etcd: Use source filepath base in CopyFs destination path

This patch corrects the destination path in CopyFs to use the source's
base filepath, instead of the entire source path. Now copying /foo/bar
to /baz results in /baz/bar instead of /baz/foo/bar. This commit also adds
a test to verify this behaviour.
This commit is contained in:
Jonathan Gold
2018-12-08 17:43:05 -05:00
parent 70ac38e66c
commit 086a89fad6
2 changed files with 58 additions and 4 deletions

View File

@@ -227,3 +227,59 @@ func TestFs3(t *testing.T) {
}
t.Logf("tree2: \n%s", tree2)
}
func TestFs4(t *testing.T) {
etcdClient := &etcd.ClientEtcd{
Seeds: []string{"localhost:2379"}, // endpoints
}
if err := etcdClient.Connect(); err != nil {
t.Logf("client connection error: %+v", err)
return
}
defer etcdClient.Destroy()
etcdFs := &etcdfs.Fs{
Client: etcdClient.GetClient(),
Metadata: superblock,
DataPrefix: etcdfs.DefaultDataPrefix,
}
etcdFs.Mkdir("/tmp", umask)
etcdFs.Mkdir("/tmp/foo", umask)
etcdFs.Mkdir("/tmp/foo/bar", umask)
tree, err := util.FsTree(etcdFs, "/")
if err != nil {
t.Errorf("tree error: %+v", err)
return
}
t.Logf("tree: \n%s", tree)
var memFs = afero.NewMemMapFs()
if err := util.CopyFs(etcdFs, memFs, "/tmp/foo/bar", "/", false); err != nil {
t.Errorf("CopyFs error: %+v", err)
return
}
if err := util.CopyFs(etcdFs, memFs, "/tmp/foo/bar", "/baz/", false); err != nil {
t.Errorf("CopyFs error: %+v", err)
return
}
tree2, err := util.FsTree(memFs, "/")
if err != nil {
t.Errorf("tree2 error: %+v", err)
return
}
t.Logf("tree2: \n%s", tree2)
if _, err := memFs.Stat("/bar"); err != nil {
t.Errorf("Stat error: %+v", err)
return
}
if _, err := memFs.Stat("/baz/bar"); err != nil {
t.Errorf("Stat error: %+v", err)
return
}
}