vfs: make -ve sized files appear as 0 size. #320

This means that Google docs will no longer appear as huge files in
`rclone mount`.  They will not be downloadable, though sometimes
trying twice will work.
This commit is contained in:
Nick Craig-Wood 2018-01-31 15:23:01 +00:00
parent 2eb5cfb7ad
commit 44276db454
3 changed files with 18 additions and 2 deletions

View File

@ -382,6 +382,14 @@ see User rate limit exceeded errors, wait at least 24 hours and retry.
You can disable server side copies with `--disable copy` to download
and upload the files if you prefer.
Google docs will appear as size -1 in `rclone ls` and as size 0 in
anything which uses the VFS layer, eg `rclone mount`, `rclone serve
XXX`. This is because rclone can't find out the size of the Google
Documents until they are downloaded. An unfortunate consequence of
this is that you can't download Google docs using `rclone mount` - you
will get a 0 sized file. If you try again the doc may gain its
correct size and be downloadable.
### Duplicated files ###
Sometimes, for no reason I've been able to track down, drive will

View File

@ -144,6 +144,14 @@ func (f *File) ModTime() (modTime time.Time) {
return f.d.modTime
}
// nonNegative returns 0 if i is -ve, i otherwise
func nonNegative(i int64) int64 {
if i >= 0 {
return i
}
return 0
}
// Size of the file
func (f *File) Size() int64 {
f.mu.Lock()
@ -153,7 +161,7 @@ func (f *File) Size() int64 {
if f.o == nil || len(f.writers) != 0 {
return atomic.LoadInt64(&f.size)
}
return f.o.Size()
return nonNegative(f.o.Size())
}
// SetModTime sets the modtime for the file

View File

@ -51,7 +51,7 @@ func newReadFileHandle(f *File, o fs.Object) (*ReadFileHandle, error) {
noSeek: f.d.vfs.Opt.NoSeek,
file: f,
hash: mhash,
size: o.Size(),
size: nonNegative(o.Size()),
}
return fh, nil
}