Skip to content

Commit

Permalink
vfs: add vfs-read-chunk-size-list parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
B4dM4n committed Mar 31, 2019
1 parent 9c8d218 commit e8357a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vfs/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (fh *ReadFileHandle) openPending() (err error) {
return nil
}
o := fh.file.getObject()
r, err := chunkedreader.New(o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit)).Open()
r, err := chunkedreader.NewWithChunkSizeIterator(o, fh.file.d.vfs.chunkSizeFunc()).Open()
if err != nil {
return err
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (fh *ReadFileHandle) seek(offset int64, reopen bool) (err error) {
}
// re-open with a seek
o := fh.file.getObject()
r = chunkedreader.New(o, int64(fh.file.d.vfs.Opt.ChunkSize), int64(fh.file.d.vfs.Opt.ChunkSizeLimit))
r = chunkedreader.NewWithChunkSizeIterator(o, fh.file.d.vfs.chunkSizeFunc())
_, err := r.Seek(offset, 0)
if err != nil {
fs.Debugf(fh.remote, "ReadFileHandle.Read seek failed: %v", err)
Expand Down
13 changes: 13 additions & 0 deletions vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"sync/atomic"
"time"

"github.com/ncw/rclone/fs/chunkedreader"

"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/log"
)
Expand Down Expand Up @@ -178,6 +180,8 @@ type VFS struct {
usageTime time.Time
usage *fs.Usage
pollChan chan time.Duration

chunkSizeFunc func() chunkedreader.ChunkSizeIterator
}

// Options is options for creating the vfs
Expand All @@ -195,6 +199,7 @@ type Options struct {
FilePerms os.FileMode
ChunkSize fs.SizeSuffix // if > 0 read files in chunks
ChunkSizeLimit fs.SizeSuffix // if > ChunkSize double the chunk size after each chunk until reached
ChunkSizeList chunkedreader.MultiplierList
CacheMode CacheMode
CacheMaxAge time.Duration
CacheMaxSize fs.SizeSuffix
Expand Down Expand Up @@ -223,6 +228,14 @@ func New(f fs.Fs, opt *Options) *VFS {
// Make sure directories are returned as directories
vfs.Opt.DirPerms |= os.ModeDir

if vfs.Opt.ChunkSizeList.Empty() {
vfs.chunkSizeFunc = func() chunkedreader.ChunkSizeIterator {
return chunkedreader.IteratorFromMinMax(int64(vfs.Opt.ChunkSize), int64(vfs.Opt.ChunkSizeLimit))
}
} else {
vfs.chunkSizeFunc = vfs.Opt.ChunkSizeList.Iter
}

// Create root directory
vfs.root = newDir(vfs, f, nil, fsDir)

Expand Down
1 change: 1 addition & 0 deletions vfs/vfsflags/vfsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.FVarP(flagSet, &Opt.ChunkSizeLimit, "vfs-read-chunk-size-limit", "", "If greater than --vfs-read-chunk-size, double the chunk size after each chunk read, until the limit is reached. 'off' is unlimited.")
flags.FVarP(flagSet, DirPerms, "dir-perms", "", "Directory permissions")
flags.FVarP(flagSet, FilePerms, "file-perms", "", "File permissions")
flags.FVarP(flagSet, &Opt.ChunkSizeList, "vfs-read-chunk-size-list", "", "Comma separated list of chunk sizes to use in order. Overides vfs-read-chunk-size and vfs-read-chunk-size-limit when set.")
platformFlags(flagSet)
}

0 comments on commit e8357a6

Please sign in to comment.