mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
touch: fix recursive touch due to recently introduced error ErrorIsDir
This commit is contained in:
parent
a70c20fe6b
commit
9c8c0a58b5
@ -132,7 +132,7 @@ func Touch(ctx context.Context, f fs.Fs, fileName string) error {
|
|||||||
return errors.Wrap(err, "failed to touch (create)")
|
return errors.Wrap(err, "failed to touch (create)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if errors.Cause(err) == fs.ErrorNotAFile {
|
if errors.Cause(err) == fs.ErrorIsDir {
|
||||||
if recursive {
|
if recursive {
|
||||||
// Touch existing directory, recursive
|
// Touch existing directory, recursive
|
||||||
fs.Debugf(nil, "Touching files in directory recursively")
|
fs.Debugf(nil, "Touching files in directory recursively")
|
||||||
|
@ -112,3 +112,43 @@ func TestTouchCreateMultipleDirAndFile(t *testing.T) {
|
|||||||
file1 := fstest.NewItem("a/b/c.txt", "", t1)
|
file1 := fstest.NewItem("a/b/c.txt", "", t1)
|
||||||
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{"a", "a/b"}, fs.ModTimeNotSupported)
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{"a", "a/b"}, fs.ModTimeNotSupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTouchEmptyDir(t *testing.T) {
|
||||||
|
r := fstest.NewRun(t)
|
||||||
|
defer r.Finalise()
|
||||||
|
|
||||||
|
err := r.Fremote.Mkdir(context.Background(), "a")
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = Touch(context.Background(), r.Fremote, "a")
|
||||||
|
require.NoError(t, err)
|
||||||
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{}, []string{"a"}, fs.ModTimeNotSupported)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTouchDirWithFiles(t *testing.T) {
|
||||||
|
r := fstest.NewRun(t)
|
||||||
|
defer r.Finalise()
|
||||||
|
|
||||||
|
err := r.Fremote.Mkdir(context.Background(), "a")
|
||||||
|
require.NoError(t, err)
|
||||||
|
file1 := r.WriteObject(context.Background(), "a/f1", "111", t1)
|
||||||
|
file2 := r.WriteObject(context.Background(), "a/f2", "222", t1)
|
||||||
|
err = Touch(context.Background(), r.Fremote, "a")
|
||||||
|
require.NoError(t, err)
|
||||||
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2}, []string{"a"}, fs.ModTimeNotSupported)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecursiveTouchDirWithFiles(t *testing.T) {
|
||||||
|
r := fstest.NewRun(t)
|
||||||
|
defer r.Finalise()
|
||||||
|
|
||||||
|
err := r.Fremote.Mkdir(context.Background(), "a/b/c")
|
||||||
|
require.NoError(t, err)
|
||||||
|
file1 := r.WriteObject(context.Background(), "a/f1", "111", t1)
|
||||||
|
file2 := r.WriteObject(context.Background(), "a/b/f2", "222", t1)
|
||||||
|
file3 := r.WriteObject(context.Background(), "a/b/c/f3", "333", t1)
|
||||||
|
recursive = true
|
||||||
|
err = Touch(context.Background(), r.Fremote, "a")
|
||||||
|
recursive = false
|
||||||
|
require.NoError(t, err)
|
||||||
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, file3}, []string{"a", "a/b", "a/b/c"}, fs.ModTimeNotSupported)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user