Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

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

Nick Craig-Wood44276db45444
diff --git a/docs/content/drive.md b/docs/content/drive.md
index 37887f5c2..508bea8ed 100644
--- a/docs/content/drive.md
+++ b/docs/content/drive.md
@@ -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
diff --git a/vfs/file.go b/vfs/file.go
index bcb1676a5..c7fe43d1c 100644
--- a/vfs/file.go
+++ b/vfs/file.go
@@ -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
diff --git a/vfs/read.go b/vfs/read.go
index a51eea52e..e3d830a9b 100644
--- a/vfs/read.go
+++ b/vfs/read.go
@@ -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
}