vfs: make --vfs-download-first flag WIP FIXME

Needs
- tests
- docs
This commit is contained in:
Nick Craig-Wood 2025-03-03 16:02:17 +00:00
parent 401cf81034
commit 35bda6781f
3 changed files with 27 additions and 0 deletions

View File

@ -113,6 +113,17 @@ func (fh *RWFileHandle) openPending() (err error) {
}
fh.opened = true
fh.d.addObject(fh.file) // make sure the directory has this object in it now
// If we are downloading the file first, then do that here
if fh.d.vfs.Opt.DownloadFirst {
fs.Errorf(fh.logPrefix(), "downloading %v file completely to cache", fs.SizeSuffix(size))
err = fh.item.Ensure()
if err != nil {
fs.Errorf(fh.logPrefix(), "failed to download file to cache: %v", err)
return fmt.Errorf("failed to download file to cache: %w", err)
}
fs.Errorf(fh.logPrefix(), "downloaded %v file completely to cache", fs.SizeSuffix(size))
}
return nil
}

View File

@ -642,6 +642,16 @@ func (item *Item) store(ctx context.Context, storeFn StoreFn) (err error) {
return item._store(ctx, storeFn)
}
// Ensure item is entirely on disk
func (item *Item) Ensure() (err error) {
item.mu.Lock()
defer item.mu.Unlock()
if item.o == nil {
return nil
}
return item._ensure(0, item.info.Size)
}
// Close the cache file
func (item *Item) Close(storeFn StoreFn) (err error) {
// defer log.Trace(item.o, "Item.Close")("err=%v", &err)

View File

@ -145,6 +145,11 @@ var OptionsInfo = fs.Options{{
Default: false,
Help: "Use fast (less accurate) fingerprints for change detection",
Groups: "VFS",
}, {
Name: "vfs_download_first",
Default: false,
Help: "If set and --vfs-cache-mode full then download files completely on first access.",
Groups: "VFS",
}, {
Name: "vfs_disk_space_total_size",
Default: fs.SizeSuffix(-1),
@ -203,6 +208,7 @@ type Options struct {
ReadAhead fs.SizeSuffix `config:"vfs_read_ahead"` // bytes to read ahead in cache mode "full"
UsedIsSize bool `config:"vfs_used_is_size"` // if true, use the `rclone size` algorithm for Used size
FastFingerprint bool `config:"vfs_fast_fingerprint"` // if set use fast fingerprints
DownloadFirst bool `config:"vfs_download_first"` // if set download files to VFS cache first
DiskSpaceTotalSize fs.SizeSuffix `config:"vfs_disk_space_total_size"`
}