Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote.SyncOpen bugfix; cached.WriteConf #77

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions http/fs/cached/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions http/fsx/cached/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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
Expand All @@ -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)
}

// -----------------------------------------------------------------------------------------