2020-04-16 12:33:46 +00:00
|
|
|
package vfstest
|
2016-07-17 22:03:23 +00:00
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2016-07-17 22:03:23 +00:00
|
|
|
"testing"
|
2017-03-23 19:41:21 +00:00
|
|
|
"time"
|
2016-07-17 22:03:23 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2016-07-17 22:03:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirLs checks out listing
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirLs(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.checkDir(t, "")
|
|
|
|
|
|
|
|
run.mkdir(t, "a directory")
|
|
|
|
run.createFile(t, "a file", "hello")
|
|
|
|
|
|
|
|
run.checkDir(t, "a directory/|a file 5")
|
|
|
|
|
|
|
|
run.rmdir(t, "a directory")
|
|
|
|
run.rm(t, "a file")
|
|
|
|
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirCreateAndRemoveDir tests creating and removing a directory
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirCreateAndRemoveDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir/subdir")
|
|
|
|
run.checkDir(t, "dir/|dir/subdir/")
|
|
|
|
|
|
|
|
// Check we can't delete a directory with stuff in
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Remove(run.path("dir"))
|
2016-07-17 22:03:23 +00:00
|
|
|
assert.Error(t, err, "file exists")
|
|
|
|
|
|
|
|
// Now delete subdir then dir - should produce no errors
|
|
|
|
run.rmdir(t, "dir/subdir")
|
|
|
|
run.checkDir(t, "dir/")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirCreateAndRemoveFile tests creating and removing a file
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirCreateAndRemoveFile(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "dir/file", "potato")
|
|
|
|
run.checkDir(t, "dir/|dir/file 6")
|
|
|
|
|
|
|
|
// Check we can't delete a directory with stuff in
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Remove(run.path("dir"))
|
2016-07-17 22:03:23 +00:00
|
|
|
assert.Error(t, err, "file exists")
|
|
|
|
|
|
|
|
// Now delete file
|
|
|
|
run.rm(t, "dir/file")
|
|
|
|
|
|
|
|
run.checkDir(t, "dir/")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirRenameFile tests renaming a file
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirRenameFile(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "file", "potato")
|
|
|
|
run.checkDir(t, "dir/|file 6")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Rename(run.path("file"), run.path("file2"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
2017-02-06 21:17:45 +00:00
|
|
|
run.checkDir(t, "dir/|file2 6")
|
2016-07-17 22:03:23 +00:00
|
|
|
|
2017-11-19 19:58:09 +00:00
|
|
|
data := run.readFile(t, "file2")
|
|
|
|
assert.Equal(t, "potato", data)
|
2017-02-06 21:17:45 +00:00
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err = run.os.Rename(run.path("file2"), run.path("dir/file3"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/file3 6")
|
|
|
|
|
2017-11-19 19:58:09 +00:00
|
|
|
data = run.readFile(t, "dir/file3")
|
2017-02-06 21:17:45 +00:00
|
|
|
require.NoError(t, err)
|
2017-11-19 19:58:09 +00:00
|
|
|
assert.Equal(t, "potato", data)
|
2017-02-06 21:17:45 +00:00
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.rm(t, "dir/file3")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirRenameEmptyDir tests renaming and empty directory
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirRenameEmptyDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir1")
|
|
|
|
run.checkDir(t, "dir/|dir1/")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Rename(run.path("dir1"), run.path("dir/dir2"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir2/")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err = run.os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir3/")
|
|
|
|
|
|
|
|
run.rmdir(t, "dir/dir3")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirRenameFullDir tests renaming a full directory
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestDirRenameFullDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir1")
|
|
|
|
run.createFile(t, "dir1/potato.txt", "maris piper")
|
|
|
|
run.checkDir(t, "dir/|dir1/|dir1/potato.txt 11")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Rename(run.path("dir1"), run.path("dir/dir2"))
|
2017-02-06 21:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir2/|dir/dir2/potato.txt 11")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err = run.os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
|
2017-02-06 21:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir3/|dir/dir3/potato.txt 11")
|
|
|
|
|
|
|
|
run.rm(t, "dir/dir3/potato.txt")
|
|
|
|
run.rmdir(t, "dir/dir3")
|
2016-07-17 22:03:23 +00:00
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
2017-03-23 19:41:21 +00:00
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirModTime tests mod times
|
2017-03-23 19:41:21 +00:00
|
|
|
func TestDirModTime(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
run.mkdir(t, "dir")
|
2018-08-04 10:16:43 +00:00
|
|
|
mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
|
2020-04-16 12:33:46 +00:00
|
|
|
err := run.os.Chtimes(run.path("dir"), mtime, mtime)
|
2017-03-23 19:41:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
info, err := run.os.Stat(run.path("dir"))
|
2017-03-23 19:41:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// avoid errors because of timezone differences
|
|
|
|
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
|
|
|
|
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
}
|
2017-05-04 20:49:06 +00:00
|
|
|
|
Spelling fixes
Fix spelling of: above, already, anonymous, associated,
authentication, bandwidth, because, between, blocks, calculate,
candidates, cautious, changelog, cleaner, clipboard, command,
completely, concurrently, considered, constructs, corrupt, current,
daemon, dependencies, deprecated, directory, dispatcher, download,
eligible, ellipsis, encrypter, endpoint, entrieslist, essentially,
existing writers, existing, expires, filesystem, flushing, frequently,
hierarchy, however, implementation, implements, inaccurate,
individually, insensitive, longer, maximum, metadata, modified,
multipart, namedirfirst, nextcloud, obscured, opened, optional,
owncloud, pacific, passphrase, password, permanently, persimmon,
positive, potato, protocol, quota, receiving, recommends, referring,
requires, revisited, satisfied, satisfies, satisfy, semver,
serialized, session, storage, strategies, stringlist, successful,
supported, surprise, temporarily, temporary, transactions, unneeded,
update, uploads, wrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-09 00:17:24 +00:00
|
|
|
// TestDirCacheFlush tests flushing the dir cache
|
2017-05-04 20:49:06 +00:00
|
|
|
func TestDirCacheFlush(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
run.checkDir(t, "")
|
|
|
|
|
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "otherdir")
|
|
|
|
run.createFile(t, "dir/file", "1")
|
|
|
|
run.createFile(t, "otherdir/file", "1")
|
|
|
|
|
|
|
|
dm := newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1")
|
|
|
|
localDm := make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
2019-06-17 08:34:30 +00:00
|
|
|
err := run.fremote.Mkdir(context.Background(), "dir/subdir")
|
2017-05-04 20:49:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-10-28 19:01:34 +00:00
|
|
|
root, err := run.vfs.Root()
|
2017-05-07 12:04:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-05-04 20:49:06 +00:00
|
|
|
// expect newly created "subdir" on remote to not show up
|
2018-03-08 20:03:34 +00:00
|
|
|
root.ForgetPath("otherdir", fs.EntryDirectory)
|
2017-05-04 20:49:06 +00:00
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
2018-03-08 20:03:34 +00:00
|
|
|
root.ForgetPath("dir", fs.EntryDirectory)
|
2017-05-04 20:49:06 +00:00
|
|
|
dm = newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1|dir/subdir/")
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
run.rm(t, "otherdir/file")
|
|
|
|
run.rmdir(t, "otherdir")
|
|
|
|
run.rm(t, "dir/file")
|
|
|
|
run.rmdir(t, "dir/subdir")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestDirCacheFlushOnDirRename tests flushing the dir cache on rename
|
2017-05-04 20:49:06 +00:00
|
|
|
func TestDirCacheFlushOnDirRename(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "dir/file", "1")
|
|
|
|
|
|
|
|
dm := newDirMap("dir/|dir/file 1")
|
|
|
|
localDm := make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
// expect remotely created directory to not show up
|
2019-06-17 08:34:30 +00:00
|
|
|
err := run.fremote.Mkdir(context.Background(), "dir/subdir")
|
2017-05-04 20:49:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
2020-04-16 12:33:46 +00:00
|
|
|
err = run.os.Rename(run.path("dir"), run.path("rid"))
|
2017-05-04 20:49:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
dm = newDirMap("rid/|rid/subdir/|rid/file 1")
|
|
|
|
localDm = make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
run.rm(t, "rid/file")
|
|
|
|
run.rmdir(t, "rid/subdir")
|
|
|
|
run.rmdir(t, "rid")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|