Skip to content

Commit

Permalink
Merge pull request #67 from xushiwei/cached
Browse files Browse the repository at this point in the history
x/http/fs/cached/remote: support cacheFile flag
  • Loading branch information
xushiwei authored Sep 8, 2023
2 parents 1cc4fe6 + 1d4bb1a commit 5c03193
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions http/fs/cached/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"time"

xfs "github.com/qiniu/x/http/fs"
"github.com/qiniu/x/http/fs/cached"
xdir "github.com/qiniu/x/http/fs/cached/dir"
)
Expand Down Expand Up @@ -177,16 +176,16 @@ func (p *remote) SyncOpen(local string, name string) (f http.File, err error) {
} else {
name = strings.TrimPrefix(name, "/")
}
o, err := p.bucket.Open(name)
f, err = p.bucket.Open(name)
if err != nil {
log.Printf(`[ERROR] bucket.Open("%s"): %v\n`, name, err)
return
}
if debugNet {
log.Println("[INFO] ==> bucket.Open", name)
}
if o.(interface{ IsDir() bool }).IsDir() {
fis, e := readdir(o)
if f.(interface{ IsDir() bool }).IsDir() {
fis, e := readdir(f)
if e != nil {
log.Printf(`[ERROR] Readdir("%s"): %v\n`, name, e)
return nil, e
Expand All @@ -209,10 +208,13 @@ func (p *remote) SyncOpen(local string, name string) (f http.File, err error) {
log.Printf("[WARN] writeStubFile fail (%d errors)", nError)
}
}()
return cached.Dir(o, fis), nil
return cached.Dir(f, fis), nil
}
localFile := filepath.Join(local, name)
return &objFile{xfs.SequenceFile(name, o), localFile, p.notify}, nil
if p.cacheFile {
localFile := filepath.Join(local, name)
f = &objFile{f, localFile, p.notify}
}
return
}

func (p *remote) Init(local string, offline bool) {
Expand Down

0 comments on commit 5c03193

Please sign in to comment.