diff --git a/http/fs/cached/remote/remote.go b/http/fs/cached/remote/remote.go index e786edd..fcf4f6c 100644 --- a/http/fs/cached/remote/remote.go +++ b/http/fs/cached/remote/remote.go @@ -60,12 +60,12 @@ func checkDirCached(dir string) fs.FileInfo { return fi } -func touchDirCached(dir string) error { +func TouchDirCached(dir string) error { cacheFile := filepath.Join(dir, dirListCacheFile) return os.WriteFile(cacheFile, nil, 0666) } -func writeStubFile(localFile string, fi fs.FileInfo) error { +func WriteStubFile(localFile string, fi fs.FileInfo) error { if fi.IsDir() { return os.Mkdir(localFile, 0755) } @@ -188,11 +188,6 @@ func (p *remote) SyncLstat(local string, name string) (fi fs.FileInfo, err error } func (p *remote) SyncOpen(local string, name string) (f http.File, err error) { - if name == "/" { - name = "." - } else { - name = strings.TrimPrefix(name, "/") - } f, err = p.bucket.Open(name) if err != nil { log.Printf(`[ERROR] bucket.Open("%s"): %v\n`, name, err) @@ -215,12 +210,12 @@ func (p *remote) SyncOpen(local string, name string) (f http.File, err error) { base := filepath.Join(local, name) for _, fi := range fis { itemFile := base + "/" + fi.Name() - if writeStubFile(itemFile, fi) != nil { + if WriteStubFile(itemFile, fi) != nil { nError++ } } if nError == 0 { - touchDirCached(base) + TouchDirCached(base) } else { log.Printf("[WARN] writeStubFile fail (%d errors)", nError) } diff --git a/http/fsx/cached/cached.go b/http/fsx/cached/cached.go index b325030..14d673c 100644 --- a/http/fsx/cached/cached.go +++ b/http/fsx/cached/cached.go @@ -46,7 +46,7 @@ const ( confFileName = remote.SysFilePrefix + "conf" ) -type config struct { +type Config struct { Base string `json:"base"` // url of base file system CacheFile bool `json:"cacheFile"` } @@ -57,7 +57,7 @@ func New(ctx context.Context, localDir string, offline ...bool) (fs http.FileSys if err != nil { return } - var conf config + var conf Config err = json.Unmarshal(b, &conf) if err != nil { return @@ -74,4 +74,13 @@ func New(ctx context.Context, localDir string, offline ...bool) (fs http.FileSys return } +func WriteConf(localDir string, conf *Config) (err error) { + confFile := filepath.Join(localDir, confFileName) + b, err := json.MarshalIndent(conf, "", " ") + if err != nil { + return + } + return os.WriteFile(confFile, b, 0644) +} + // -----------------------------------------------------------------------------------------