clean empty object directories after deleting content lock file

When dropping content, this was already done after deleting the content
file, but the lock file prevents deleting the directories. So, try the
deletion again.

This does mean there's a small added overhead of a failed rmdir().

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2022-01-13 14:19:36 -04:00
parent e28d1d0325
commit 86e5ffe34a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -236,8 +236,9 @@ lockContentUsing locker sharedlock key fallback a = do
#endif #endif
cleanuplockfile lockfile = modifyContent lockfile $ cleanuplockfile lockfile = modifyContent lockfile $
void $ liftIO $ tryIO $ void $ liftIO $ tryIO $ do
removeWhenExistsWith R.removeLink lockfile removeWhenExistsWith R.removeLink lockfile
cleanObjectDirs lockfile
{- Runs an action, passing it the temp file to get, {- Runs an action, passing it the temp file to get,
- and if the action succeeds, verifies the file matches - and if the action succeeds, verifies the file matches
@ -574,12 +575,15 @@ cleanObjectLoc key cleaner = do
file <- calcRepo (gitAnnexLocation key) file <- calcRepo (gitAnnexLocation key)
void $ tryIO $ thawContentDir file void $ tryIO $ thawContentDir file
cleaner cleaner
liftIO $ removeparents file (3 :: Int) liftIO $ cleanObjectDirs file
cleanObjectDirs :: RawFilePath -> IO ()
cleanObjectDirs = go (3 :: Int)
where where
removeparents _ 0 = noop go 0 _ = noop
removeparents file n = do go n file = do
let dir = parentDir file let dir = parentDir file
maybe noop (const $ removeparents dir (n-1)) maybe noop (const $ go (n-1) dir)
<=< catchMaybeIO $ removeDirectory (fromRawFilePath dir) <=< catchMaybeIO $ removeDirectory (fromRawFilePath dir)
{- Removes a key's file from .git/annex/objects/ -} {- Removes a key's file from .git/annex/objects/ -}