Repository navigation
fix(local-disk): remove folders a delete or move leaves empty - #35
Merged
Merged
Conversation
Deleting the last file under a folder left the folder on disk, so a later put, copy or move onto the folder's name failed with StorageKeyConflictError although no key was there. A move left the source's folder behind the same way. A delete or move now removes each folder it leaves empty, up to the root. On a write, an empty folder at the key is removed before the rename, which fixes roots that already hold such folders. If a concurrent delete removes the write's folder before the rename, the write creates it again and retries. Closes #33
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
LocalDisk.delete()unlinks a file and its sidecar but keeps the folder it was in. A laterput(),copy()ormove()onto that folder's name then fails withStorageKeyConflictError, althoughexists()andlist()show no key there.InMemoryDiskandS3Diskaccept the same steps.move()leaves the source's folder behind the same way.Issue Number: #33
What is the new behavior?
Thanks to @johnnyhuirilef for the report, the repro and both ideas for the fix. This PR combines them:
.nest-storage). It uses non-recursivermdirand stops at the first folder that still holds something or can't be removed. This keeps the tree from filling with empty folders thatlist()would still walk.rmdiron it. If the folder was empty, the rename is retried; if not, it is still aStorageKeyConflictError. This covers roots that already hold empty folders from earlier versions, a crash between unlink and rmdir, or another tool.ensureParent(), the rename fails withENOENT. The write then creates the folder again and retries, up to 3 attempts. If a file was put at that folder's name in between, the write getsStorageKeyConflictError, so the documented rule thataanda/bcan't both exist still holds.Sidecars are flat files under
.nest-storage/meta/, so they leave no folders behind.exists()andlist()are unchanged.Tests: one test in the shared disk suite runs on every disk (it failed only on
LocalDiskbefore). LocalDisk-only tests cover pruning, an empty folder left by another tool, a folder that still holds something (a conflict), and symbolic links. Two deterministic race tests stubrename.Does this PR introduce a breaking change?
Other information
uploads/). The next write that needs it creates it again.a/b/still blocksput('a')until a delete through the disk prunes it.EPERM(rename onto a folder) andEPERM/EBUSY(rmdir) are handled, but untested, since CI runs on Linux only.