mirror of
https://github.com/rclone/rclone.git
synced 2025-08-19 09:52:05 +02:00
fs: Move link suffix to fs
This commit is contained in:
committed by
albertony
parent
3834de5ab1
commit
46de095e9c
@@ -32,7 +32,6 @@ import (
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const devUnset = 0xdeadbeefcafebabe // a device id meaning it is unset
|
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
|
const useReadDir = (runtime.GOOS == "windows" || runtime.GOOS == "plan9") // these OSes read FileInfos directly
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
@@ -72,7 +71,7 @@ supported by all file systems) under the "user.*" prefix.
|
|||||||
Advanced: true,
|
Advanced: true,
|
||||||
}, {
|
}, {
|
||||||
Name: "links",
|
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,
|
Default: false,
|
||||||
NoPrefix: true,
|
NoPrefix: true,
|
||||||
ShortOpt: "l",
|
ShortOpt: "l",
|
||||||
@@ -375,8 +374,8 @@ func (f *Fs) caseInsensitive() bool {
|
|||||||
//
|
//
|
||||||
// for regular files, localPath is returned unchanged
|
// for regular files, localPath is returned unchanged
|
||||||
func translateLink(remote, localPath string) (newLocalPath string, isTranslatedLink bool) {
|
func translateLink(remote, localPath string) (newLocalPath string, isTranslatedLink bool) {
|
||||||
isTranslatedLink = strings.HasSuffix(remote, linkSuffix)
|
isTranslatedLink = strings.HasSuffix(remote, fs.LinkSuffix)
|
||||||
newLocalPath = strings.TrimSuffix(localPath, linkSuffix)
|
newLocalPath = strings.TrimSuffix(localPath, fs.LinkSuffix)
|
||||||
return newLocalPath, isTranslatedLink
|
return newLocalPath, isTranslatedLink
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,7 +550,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
} else {
|
} else {
|
||||||
// Check whether this link should be translated
|
// Check whether this link should be translated
|
||||||
if f.opt.TranslateSymlinks && fi.Mode()&os.ModeSymlink != 0 {
|
if f.opt.TranslateSymlinks && fi.Mode()&os.ModeSymlink != 0 {
|
||||||
newRemote += linkSuffix
|
newRemote += fs.LinkSuffix
|
||||||
}
|
}
|
||||||
fso, err := f.newObjectWithInfo(newRemote, fi)
|
fso, err := f.newObjectWithInfo(newRemote, fi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -91,7 +91,7 @@ func TestSymlink(t *testing.T) {
|
|||||||
require.NoError(t, lChtimes(symlinkPath, modTime2, modTime2))
|
require.NoError(t, lChtimes(symlinkPath, modTime2, modTime2))
|
||||||
|
|
||||||
// Object viewed as symlink
|
// 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
|
// Object viewed as destination
|
||||||
file2d := fstest.NewItem("symlink.txt", "hello", modTime1)
|
file2d := fstest.NewItem("symlink.txt", "hello", modTime1)
|
||||||
@@ -120,7 +120,7 @@ func TestSymlink(t *testing.T) {
|
|||||||
|
|
||||||
// Create a symlink
|
// Create a symlink
|
||||||
modTime3 := fstest.Time("2002-03-03T04:05:10.123123123Z")
|
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)
|
fstest.CheckListingWithPrecision(t, r.Flocal, []fstest.Item{file1, file2, file3}, nil, fs.ModTimeNotSupported)
|
||||||
if haveLChtimes {
|
if haveLChtimes {
|
||||||
r.CheckLocalItems(t, file1, file2, file3)
|
r.CheckLocalItems(t, file1, file2, file3)
|
||||||
@@ -136,9 +136,9 @@ func TestSymlink(t *testing.T) {
|
|||||||
assert.Equal(t, "file.txt", linkText)
|
assert.Equal(t, "file.txt", linkText)
|
||||||
|
|
||||||
// Check that NewObject gets the correct object
|
// 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)
|
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())
|
assert.Equal(t, int64(8), o.Size())
|
||||||
|
|
||||||
// Check that NewObject doesn't see the non suffixed version
|
// Check that NewObject doesn't see the non suffixed version
|
||||||
|
2
fs/fs.go
2
fs/fs.go
@@ -16,6 +16,8 @@ const (
|
|||||||
ModTimeNotSupported = 100 * 365 * 24 * time.Hour
|
ModTimeNotSupported = 100 * 365 * 24 * time.Hour
|
||||||
// MaxLevel is a sentinel representing an infinite depth for listings
|
// MaxLevel is a sentinel representing an infinite depth for listings
|
||||||
MaxLevel = math.MaxInt32
|
MaxLevel = math.MaxInt32
|
||||||
|
// The suffix added to a translated symbolic link
|
||||||
|
LinkSuffix = ".rclonelink"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
|
Reference in New Issue
Block a user