-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MemMapFS doesn't properly rename directories #141
Comments
I also noticed this recently while unit testing something that moves directories with MemMapFS; it would work if I tested with the OS default filesystem, but not with MemMapFS. |
Confirm
output:
|
Prior to this change renaming an in-memory directory would leave the contents of the directory behind at their old paths. Now directory entries are updated to use the new directory name. Fixes spf13#141
Prior to this change renaming an in-memory directory would leave the contents of the directory behind at their old paths. Now directory entries are updated to use the new directory name. Fixes spf13#141
Hello, Just wanted to chime in and say that I'm having the same trouble with this. I'm unit testing with MemMapFs and finding that fs.Rename doesn't seem to be doing anything. I might be doing something wrong, but the code seems to work fine when we're using an OS filesystem. (here's my code, if it helps at all)
|
Please fix this issue. This sorta defeat the whole point of using afero, which allows me to use memfs for testing. |
Please check my PR with fix. I can't use the library with this bug. |
Actually this merged PR will not work. You need to update underlying fs := NewMemMapFs()
err := fs.MkdirAll("src/originDir", 0o777)
if err != nil {
t.Fatalf("MkDirAll failed: %s", err)
}
f, err := fs.Create("src/originDir/originFile.txt")
if err != nil {
t.Fatalf("Create failed: %s", err)
}
if err = f.Close(); err != nil {
t.Fatalf("Close failed: %s", err)
}
err = fs.Rename("src/originDir", "src/updatedDir")
if err != nil {
t.Fatalf("Rename failed: %s", err)
}
err = fs.Rename("src/updatedDir/originFile.txt", "src/updatedDir/updatedFile.txt")
if err != nil {
t.Fatalf("Rename failed: %s", err)
} @bep please have a look to my PR which I did almost a year ago. |
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:
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!
The text was updated successfully, but these errors were encountered: