From df4e6079f11b4623f57dd2ee199a0a91b1537d45 Mon Sep 17 00:00:00 2001 From: Riccardo Iaconelli Date: Mon, 25 Jan 2021 22:25:40 +0100 Subject: [PATCH] local: new flag --local-zero-size-links to fix sync on some virtual filesystems Assume the Stat size of links is zero (and read them instead) On some virtual filesystems (such ash LucidLink), reading a link size via a Stat call always returns 0. However, on unix it reads as the length of the text in the link. This may cause errors like this when syncing: Failed to copy: corrupted on transfer: sizes differ 0 vs 13 Setting this flag causes rclone to read the link and use that as the size of the link instead of 0 which in most cases fixes the problem. Fixes #4950 Signed-off-by: Riccardo Iaconelli --- backend/local/local.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/local/local.go b/backend/local/local.go index 9b3aa7b76..3daeb4f0a 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -70,6 +70,20 @@ points, as you explicitly acknowledge that they should be skipped.`, Default: false, NoPrefix: true, Advanced: true, + }, { + Name: "zero_size_links", + Help: `Assume the Stat size of links is zero (and read them instead) + +On some virtual filesystems (such ash LucidLink), reading a link size via a Stat call always returns 0. +However, on unix it reads as the length of the text in the link. This may cause errors like this when +syncing: + + Failed to copy: corrupted on transfer: sizes differ 0 vs 13 + +Setting this flag causes rclone to read the link and use that as the size of the link +instead of 0 which in most cases fixes the problem.`, + Default: false, + Advanced: true, }, { Name: "no_unicode_normalization", Help: `Don't apply unicode normalization to paths and filenames (Deprecated) @@ -170,6 +184,7 @@ type Options struct { FollowSymlinks bool `config:"copy_links"` TranslateSymlinks bool `config:"links"` SkipSymlinks bool `config:"skip_links"` + ZeroSizeLinks bool `config:"zero_size_links"` NoUTFNorm bool `config:"no_unicode_normalization"` NoCheckUpdated bool `config:"no_check_updated"` NoUNC bool `config:"nounc"` @@ -1232,7 +1247,8 @@ func (o *Object) setMetadata(info os.FileInfo) { o.mode = info.Mode() o.fs.objectMetaMu.Unlock() // On Windows links read as 0 size so set the correct size here - if runtime.GOOS == "windows" && o.translatedLink { + // Optionally, users can turn this feature on with the zero_size_links flag + if (runtime.GOOS == "windows" || o.fs.opt.ZeroSizeLinks) && o.translatedLink { linkdst, err := os.Readlink(o.path) if err != nil { fs.Errorf(o, "Failed to read link size: %v", err)