Repository navigation
fix(local-fs): Remove empty directories after deleting objects - #755
Conversation
Changelog PreviewThis PR lands in these workspaces:
📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes
🤖 This preview updates automatically when you update the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #755 +/- ##
==========================================
+ Coverage 91.86% 91.88% +0.01%
==========================================
Files 119 119
Lines 22978 23059 +81
==========================================
+ Hits 21109 21188 +79
- Misses 1869 1871 +2
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fc6d205. Configure here.
97bcaee to
c19dfc4
Compare
Dropping an unpublished draft removed its empty directories synchronously, usually on an async worker. Inside a Tokio runtime, the removal now runs on the blocking thread pool. Without a runtime, it still runs in place.

The filesystem backend stores each object key segment as one directory level. When an object was deleted, its directories stayed on disk. Self-hosted and local deployments therefore collected a growing number of empty directories, which can slow down the filesystem.
Deleting an object now also removes its directories while they are empty, up to the storage root. Cleanup stops at the first directory that still holds other objects. A failed cleanup never fails the delete.
This cleanup does not take any lock. Object locks are per object, but directories are shared by many objects, so locking every directory level would be expensive. Instead, this relies on the fact that directory removal is atomic and only succeeds on empty directories, so it can never remove stored objects. The only race is a writer that has just created a directory but has not yet placed its file in it. Writers now handle this: if the directory is gone when they create their draft or publish a resumable upload, they create it again and retry, up to three attempts. The delete releases the object lock before it starts the cleanup.
Fixes FS-158
Changelog Entry