Skip to content

Commit

Permalink
pwd cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Apr 9, 2023
1 parent e2e7f43 commit 98921b8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 33 deletions.
4 changes: 2 additions & 2 deletions frontend/build/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<!-- Vue.js release version -->
<script src="/plug/vue.global.prod.js?3.2.47"></script>
<!-- application bundle: leaflet, sha256 -->
<script src="/relm/app.bundle.js?0.9.3"></script>
<script src="/relm/app.bundle.js?0.10.0"></script>
<!-- page bundle -->
<script src="/relm/main.bundle.js?0.9.3"></script>
<script src="/relm/main.bundle.js?0.10.0"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/build/stat.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
<!-- Vue.js release version -->
<script src="/plug/vue.global.prod.js?3.2.47"></script>
<!-- page bundle -->
<script src="/relm/stat.bundle.js?0.9.3"></script>
<script src="/relm/stat.bundle.js?0.10.0"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/devmode/devmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included only for developer mode linkage

const buildvers = "0.10.0";
const builddate = "2023.04.03";
const builddate = "2023.04.10";
console.info("version: %s, builton: %s", buildvers, builddate);
console.info("starts in developer mode");

Expand Down
2 changes: 1 addition & 1 deletion frontend/devmode/relmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is included for release mode linkage

const buildvers = "0.10.0";
const builddate = "2023.03.14";
const builddate = "2023.04.10";
const devmode = false;

const traceajax = () => undefined;
Expand Down
35 changes: 29 additions & 6 deletions ftpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io/fs"
"net/url"
"path"
"strings"
"sync"
"time"

"github.com/jlaffaye/ftp"
Expand All @@ -18,6 +18,29 @@ var (
ErrFtpNegPos = errors.New("negative position at FTP seeker")
)

var (
pwdmap map[string]string
pwdmux sync.RWMutex
)

func PwdCache(ftpaddr string, conn *ftp.ServerConn) (pwd string) {
var ok bool
pwdmux.RLock()
pwd, ok = pwdmap[ftpaddr]
pwdmux.RUnlock()
if ok {
return
}
var err error
if pwd, err = conn.CurrentDir(); err == nil {
pwdmux.Lock()
pwdmap[ftpaddr] = pwd
pwdmux.Unlock()
return
}
return
}

// FtpFileInfo encapsulates ftp.Entry structure and provides fs.FileInfo implementation.
type FtpFileInfo struct {
*ftp.Entry
Expand Down Expand Up @@ -78,14 +101,14 @@ func (ff *FtpFile) Open(ftppath string) (err error) {
if u, err = url.Parse(ftppath); err != nil {
return
}
if strings.HasPrefix(u.Path, "/") {
ff.path = u.Path[1:]
} else {
ff.path = u.Path
}
if ff.conn, err = ftp.Dial(u.Host, ftp.DialWithTimeout(cfg.DialTimeout)); err != nil {
return
}
ff.path = path.Join(PwdCache((&url.URL{
Scheme: u.Scheme,
User: u.User,
Host: u.Host,
}).String(), ff.conn), u.Path)
var pass, _ = u.User.Password()
if err = ff.conn.Login(u.User.Username(), pass); err != nil {
return
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/schwarzlichtbezirk/wpk v1.4.2
github.com/spate/glimage v0.0.0-20200505055513-fbdcc60a65e5
golang.org/x/crypto v0.7.0
golang.org/x/image v0.6.0
golang.org/x/crypto v0.8.0
golang.org/x/image v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/text v0.9.0
gopkg.in/ini.v1 v1.67.0
Expand All @@ -45,7 +45,7 @@ require (
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
xorm.io/builder v0.3.12 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWP
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4=
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -485,8 +485,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -547,7 +547,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
22 changes: 10 additions & 12 deletions opendisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ func StatFile(syspath string) (fi fs.FileInfo, err error) {
if err = conn.Login(u.User.Username(), pass); err != nil {
return
}
var path string
if strings.HasPrefix(u.Path, "/") {
path = u.Path[1:]
} else {
path = u.Path
}
var path = path.Join(PwdCache((&url.URL{
Scheme: u.Scheme,
User: u.User,
Host: u.Host,
}).String(), conn), u.Path)
var ent *ftp.Entry
if ent, err = conn.GetEntry(path); err != nil {
return
Expand Down Expand Up @@ -224,12 +223,11 @@ func ReadDir(dir string) (ret []fs.FileInfo, err error) {
if err = conn.Login(u.User.Username(), pass); err != nil {
return
}
var path string
if strings.HasPrefix(u.Path, "/") {
path = u.Path[1:]
} else {
path = u.Path
}
var path = path.Join(PwdCache((&url.URL{
Scheme: u.Scheme,
User: u.User,
Host: u.Host,
}).String(), conn), u.Path)
var entries []*ftp.Entry
if entries, err = conn.List(path); err != nil {
return
Expand Down

0 comments on commit 98921b8

Please sign in to comment.