local: fix filtering of symlinks with -l/--links flag
Before this fix, with the -l flag, the `.rclonelink` suffix wasn't being added to the file names before filtering by name. See #6855
This commit is contained in:
parent
2b8af4d23f
commit
15a3ec8fa1
2 changed files with 55 additions and 21 deletions
|
@ -540,11 +540,6 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
||||||
}
|
}
|
||||||
mode = fi.Mode()
|
mode = fi.Mode()
|
||||||
}
|
}
|
||||||
// Don't include non directory if not included
|
|
||||||
// we leave directory filtering to the layer above
|
|
||||||
if useFilter && !fi.IsDir() && !filter.IncludeRemote(newRemote) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
// Ignore directories which are symlinks. These are junction points under windows which
|
// Ignore directories which are symlinks. These are junction points under windows which
|
||||||
// are kind of a souped up symlink. Unix doesn't have directories which are symlinks.
|
// are kind of a souped up symlink. Unix doesn't have directories which are symlinks.
|
||||||
|
@ -557,6 +552,11 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
||||||
if f.opt.TranslateSymlinks && fi.Mode()&os.ModeSymlink != 0 {
|
if f.opt.TranslateSymlinks && fi.Mode()&os.ModeSymlink != 0 {
|
||||||
newRemote += linkSuffix
|
newRemote += linkSuffix
|
||||||
}
|
}
|
||||||
|
// Don't include non directory if not included
|
||||||
|
// we leave directory filtering to the layer above
|
||||||
|
if useFilter && !filter.IncludeRemote(newRemote) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
fso, err := f.newObjectWithInfo(newRemote, fi)
|
fso, err := f.newObjectWithInfo(newRemote, fi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -397,7 +397,7 @@ func TestFilter(t *testing.T) {
|
||||||
require.Equal(t, "[included]", fmt.Sprint(entries))
|
require.Equal(t, "[included]", fmt.Sprint(entries))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterSymlink(t *testing.T) {
|
func testFilterSymlink(t *testing.T, copyLinks bool) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
r := fstest.NewRun(t)
|
r := fstest.NewRun(t)
|
||||||
defer r.Finalise()
|
defer r.Finalise()
|
||||||
|
@ -411,15 +411,23 @@ func TestFilterSymlink(t *testing.T) {
|
||||||
require.NoError(t, os.Symlink("included.dir", filepath.Join(r.LocalName, "included.dir.link")))
|
require.NoError(t, os.Symlink("included.dir", filepath.Join(r.LocalName, "included.dir.link")))
|
||||||
require.NoError(t, os.Symlink("dangling", filepath.Join(r.LocalName, "dangling.link")))
|
require.NoError(t, os.Symlink("dangling", filepath.Join(r.LocalName, "dangling.link")))
|
||||||
|
|
||||||
// Set fs into "-L" mode
|
defer func() {
|
||||||
f.opt.FollowSymlinks = true
|
// Reset -L/-l mode
|
||||||
f.opt.TranslateSymlinks = false
|
f.opt.FollowSymlinks = false
|
||||||
f.lstat = os.Stat
|
f.opt.TranslateSymlinks = false
|
||||||
|
f.lstat = os.Lstat
|
||||||
// Set fs into "-l" mode
|
}()
|
||||||
// f.opt.FollowSymlinks = false
|
if copyLinks {
|
||||||
// f.opt.TranslateSymlinks = true
|
// Set fs into "-L" mode
|
||||||
// f.lstat = os.Lstat
|
f.opt.FollowSymlinks = true
|
||||||
|
f.opt.TranslateSymlinks = false
|
||||||
|
f.lstat = os.Stat
|
||||||
|
} else {
|
||||||
|
// Set fs into "-l" mode
|
||||||
|
f.opt.FollowSymlinks = false
|
||||||
|
f.opt.TranslateSymlinks = true
|
||||||
|
f.lstat = os.Lstat
|
||||||
|
}
|
||||||
|
|
||||||
// Check set up for filtering
|
// Check set up for filtering
|
||||||
assert.True(t, f.Features().FilterAware)
|
assert.True(t, f.Features().FilterAware)
|
||||||
|
@ -431,21 +439,35 @@ func TestFilterSymlink(t *testing.T) {
|
||||||
// Add a filter
|
// Add a filter
|
||||||
ctx, fi := filter.AddConfig(ctx)
|
ctx, fi := filter.AddConfig(ctx)
|
||||||
require.NoError(t, fi.AddRule("+ included.file"))
|
require.NoError(t, fi.AddRule("+ included.file"))
|
||||||
require.NoError(t, fi.AddRule("+ included.file.link"))
|
|
||||||
require.NoError(t, fi.AddRule("+ included.dir/**"))
|
require.NoError(t, fi.AddRule("+ included.dir/**"))
|
||||||
require.NoError(t, fi.AddRule("+ included.dir.link/**"))
|
if copyLinks {
|
||||||
|
require.NoError(t, fi.AddRule("+ included.file.link"))
|
||||||
|
require.NoError(t, fi.AddRule("+ included.dir.link/**"))
|
||||||
|
} else {
|
||||||
|
require.NoError(t, fi.AddRule("+ included.file.link.rclonelink"))
|
||||||
|
require.NoError(t, fi.AddRule("+ included.dir.link.rclonelink"))
|
||||||
|
}
|
||||||
require.NoError(t, fi.AddRule("- *"))
|
require.NoError(t, fi.AddRule("- *"))
|
||||||
|
|
||||||
// Check listing without use filter flag
|
// Check listing without use filter flag
|
||||||
entries, err := f.List(ctx, "")
|
entries, err := f.List(ctx, "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Check 1 global errors one for each dangling symlink
|
if copyLinks {
|
||||||
assert.Equal(t, int64(1), accounting.Stats(ctx).GetErrors(), "global errors found")
|
// Check 1 global errors one for each dangling symlink
|
||||||
|
assert.Equal(t, int64(1), accounting.Stats(ctx).GetErrors(), "global errors found")
|
||||||
|
} else {
|
||||||
|
// Check 0 global errors as dangling symlink copied properly
|
||||||
|
assert.Equal(t, int64(0), accounting.Stats(ctx).GetErrors(), "global errors found")
|
||||||
|
}
|
||||||
accounting.Stats(ctx).ResetErrors()
|
accounting.Stats(ctx).ResetErrors()
|
||||||
|
|
||||||
sort.Sort(entries)
|
sort.Sort(entries)
|
||||||
require.Equal(t, "[included.dir included.dir.link included.file included.file.link]", fmt.Sprint(entries))
|
if copyLinks {
|
||||||
|
require.Equal(t, "[included.dir included.dir.link included.file included.file.link]", fmt.Sprint(entries))
|
||||||
|
} else {
|
||||||
|
require.Equal(t, "[dangling.link.rclonelink included.dir included.dir.link.rclonelink included.file included.file.link.rclonelink]", fmt.Sprint(entries))
|
||||||
|
}
|
||||||
|
|
||||||
// Add user filter flag
|
// Add user filter flag
|
||||||
ctx = filter.SetUseFilter(ctx, true)
|
ctx = filter.SetUseFilter(ctx, true)
|
||||||
|
@ -456,7 +478,11 @@ func TestFilterSymlink(t *testing.T) {
|
||||||
assert.Equal(t, int64(0), accounting.Stats(ctx).GetErrors(), "global errors found")
|
assert.Equal(t, int64(0), accounting.Stats(ctx).GetErrors(), "global errors found")
|
||||||
|
|
||||||
sort.Sort(entries)
|
sort.Sort(entries)
|
||||||
require.Equal(t, "[included.dir included.dir.link included.file included.file.link]", fmt.Sprint(entries))
|
if copyLinks {
|
||||||
|
require.Equal(t, "[included.dir included.dir.link included.file included.file.link]", fmt.Sprint(entries))
|
||||||
|
} else {
|
||||||
|
require.Equal(t, "[included.dir included.dir.link.rclonelink included.file included.file.link.rclonelink]", fmt.Sprint(entries))
|
||||||
|
}
|
||||||
|
|
||||||
// Check listing through a symlink still works
|
// Check listing through a symlink still works
|
||||||
entries, err = f.List(ctx, "included.dir")
|
entries, err = f.List(ctx, "included.dir")
|
||||||
|
@ -466,3 +492,11 @@ func TestFilterSymlink(t *testing.T) {
|
||||||
sort.Sort(entries)
|
sort.Sort(entries)
|
||||||
require.Equal(t, "[included.dir/included.sub.file]", fmt.Sprint(entries))
|
require.Equal(t, "[included.dir/included.sub.file]", fmt.Sprint(entries))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilterSymlinkCopyLinks(t *testing.T) {
|
||||||
|
testFilterSymlink(t, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFilterSymlinkLinks(t *testing.T) {
|
||||||
|
testFilterSymlink(t, false)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue