vfs: fix --vfs-cache-mode minimal,writes ignoring cached files

Before this change, with --vfs-cache-mode minimal,writes if files were
opened they would always be read from the remote, regardless of
whether they were in the cache or not.

This change checks to see if the file is in the cache when opening a
file with --vfs-cache-mode >= minimal and if so then it uses it from
the cache.

This makes --vfs-cache-mode writes in particular much more
efficient. No longer is a file uploaded (with write mode) then
immediately downloaded (with read only mode).

Fixes #3330
s3-about
Nick Craig-Wood 2019-08-03 14:50:48 +01:00
parent 67fae720d7
commit 077b45322d
2 changed files with 14 additions and 3 deletions

View File

@ -263,6 +263,19 @@ func (c *cache) cacheDir(name string) {
}
}
// exists checks to see if the file exists in the cache or not
func (c *cache) exists(name string) bool {
osPath := c.toOSPath(name)
fi, err := os.Stat(osPath)
if err != nil {
return false
}
if fi.IsDir() {
return false
}
return true
}
// _close marks name as closed - must be called with the lock held
func (c *cache) _close(isFile bool, name string) {
for {

View File

@ -546,11 +546,9 @@ func (f *File) Open(flags int) (fd Handle, err error) {
write = true
}
// FIXME discover if file is in cache or not?
// Open the correct sort of handle
CacheMode := f.d.vfs.Opt.CacheMode
if CacheMode >= CacheModeMinimal && f.d.vfs.cache.opens(f.Path()) > 0 {
if CacheMode >= CacheModeMinimal && (f.d.vfs.cache.opens(f.Path()) > 0 || f.d.vfs.cache.exists(f.Path())) {
fd, err = f.openRW(flags)
} else if read && write {
if CacheMode >= CacheModeMinimal {