diff --git a/backend/local/local.go b/backend/local/local.go index 25ff7fce5..115dbec0d 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -32,7 +32,6 @@ import ( // Constants const devUnset = 0xdeadbeefcafebabe // a device id meaning it is unset -const linkSuffix = ".rclonelink" // The suffix added to a translated symbolic link const useReadDir = (runtime.GOOS == "windows" || runtime.GOOS == "plan9") // these OSes read FileInfos directly // Register with Fs @@ -72,7 +71,7 @@ supported by all file systems) under the "user.*" prefix. Advanced: true, }, { Name: "links", - Help: "Translate symlinks to/from regular files with a '" + linkSuffix + "' extension.", + Help: "Translate symlinks to/from regular files with a '" + fs.LinkSuffix + "' extension.", Default: false, NoPrefix: true, ShortOpt: "l", @@ -375,8 +374,8 @@ func (f *Fs) caseInsensitive() bool { // // for regular files, localPath is returned unchanged func translateLink(remote, localPath string) (newLocalPath string, isTranslatedLink bool) { - isTranslatedLink = strings.HasSuffix(remote, linkSuffix) - newLocalPath = strings.TrimSuffix(localPath, linkSuffix) + isTranslatedLink = strings.HasSuffix(remote, fs.LinkSuffix) + newLocalPath = strings.TrimSuffix(localPath, fs.LinkSuffix) return newLocalPath, isTranslatedLink } @@ -551,7 +550,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e } else { // Check whether this link should be translated if f.opt.TranslateSymlinks && fi.Mode()&os.ModeSymlink != 0 { - newRemote += linkSuffix + newRemote += fs.LinkSuffix } fso, err := f.newObjectWithInfo(newRemote, fi) if err != nil { diff --git a/backend/local/local_internal_test.go b/backend/local/local_internal_test.go index 0b5d12480..9d329c943 100644 --- a/backend/local/local_internal_test.go +++ b/backend/local/local_internal_test.go @@ -91,7 +91,7 @@ func TestSymlink(t *testing.T) { require.NoError(t, lChtimes(symlinkPath, modTime2, modTime2)) // Object viewed as symlink - file2 := fstest.NewItem("symlink.txt"+linkSuffix, "file.txt", modTime2) + file2 := fstest.NewItem("symlink.txt"+fs.LinkSuffix, "file.txt", modTime2) // Object viewed as destination file2d := fstest.NewItem("symlink.txt", "hello", modTime1) @@ -120,7 +120,7 @@ func TestSymlink(t *testing.T) { // Create a symlink modTime3 := fstest.Time("2002-03-03T04:05:10.123123123Z") - file3 := r.WriteObjectTo(ctx, r.Flocal, "symlink2.txt"+linkSuffix, "file.txt", modTime3, false) + file3 := r.WriteObjectTo(ctx, r.Flocal, "symlink2.txt"+fs.LinkSuffix, "file.txt", modTime3, false) fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2, file3}, nil, fs.ModTimeNotSupported) if haveLChtimes { r.CheckLocalItems(t, file1, file2, file3) @@ -136,9 +136,9 @@ func TestSymlink(t *testing.T) { assert.Equal(t, "file.txt", linkText) // Check that NewObject gets the correct object - o, err := r.Flocal.NewObject(ctx, "symlink2.txt"+linkSuffix) + o, err := r.Flocal.NewObject(ctx, "symlink2.txt"+fs.LinkSuffix) require.NoError(t, err) - assert.Equal(t, "symlink2.txt"+linkSuffix, o.Remote()) + assert.Equal(t, "symlink2.txt"+fs.LinkSuffix, o.Remote()) assert.Equal(t, int64(8), o.Size()) // Check that NewObject doesn't see the non suffixed version diff --git a/fs/fs.go b/fs/fs.go index fe68517c4..83b03f474 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -16,6 +16,8 @@ const ( ModTimeNotSupported = 100 * 365 * 24 * time.Hour // MaxLevel is a sentinel representing an infinite depth for listings MaxLevel = math.MaxInt32 + // The suffix added to a translated symbolic link + LinkSuffix = ".rclonelink" ) // Globals