-
Notifications
You must be signed in to change notification settings - Fork 537
Closed
Labels
Description
When I rename a directory with MemMapFS, the files within it don't get moved. I think the files within should also move to the new directory name (as in the behavior of mv <old_dir> <new_dir>
), but maybe I'm misunderstanding how Rename works.
I've written a unit test that shows the error:
// TestRenameDirectory creates a directory with a file, and attempts to rename
// the directory. The child file should also be within the renamed directory.
func TestRenameDirectory(t *testing.T) {
fs := NewMemMapFs()
srcDir := "/src-dir"
dstDir := "/dst-dir"
filename := "file"
fileInSrcDir := filepath.Join(srcDir, filename)
fileInDstDir := filepath.Join(dstDir, filename)
if err := fs.Mkdir(srcDir, 755); err != nil {
t.Fatalf("Mkdir failed unexpectedly: %s", err)
}
if _, err := fs.Create(fileInSrcDir); err != nil {
t.Fatalf("Create file failed unexpectedly: %s", err)
}
if err := fs.Rename(srcDir, dstDir); err != nil {
t.Fatalf("Rename failed unexpectedly: %s", err)
}
if _, err := fs.Stat(fileInSrcDir); err == nil {
t.Error("The file should not be in the old directory")
}
if _, err := fs.Stat(fileInDstDir); err != nil {
t.Errorf("The file should be in the new directory: %s", err)
}
}
--- FAIL: TestRenameDirectory (0.00s)
memmap_test.go:371: The file should not be in the old directory
memmap_test.go:375: The file should be in the new directory: open /dst-dir/file: file does not exist
I could help out fixing this, but I'm not sure how to approach it. I took a quick glance at the way the filesystem is represented within MemMapFS, and didn't completely understand it.
Thanks!
carolynvs, michaljurecko, lediraison-a and hanagantig