fix hardcoding of number of hash directories

It can be changed to 1 via a tuning, rather than the 2 this assumed. So
it would have tried to rmdir .git/annex/objects in that case, which
would not hurt anything, but is not what it is supposed to do.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2022-05-16 15:08:42 -04:00
parent 5a98f2d509
commit 6b5029db29
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -89,6 +89,7 @@ import Annex.UUID
import Annex.InodeSentinal import Annex.InodeSentinal
import Annex.ReplaceFile import Annex.ReplaceFile
import Annex.AdjustedBranch (adjustedBranchRefresh) import Annex.AdjustedBranch (adjustedBranchRefresh)
import Annex.DirHashes
import Messages.Progress import Messages.Progress
import Types.Remote (RetrievalSecurityPolicy(..), VerifyConfigA(..)) import Types.Remote (RetrievalSecurityPolicy(..), VerifyConfigA(..))
import Types.NumCopies import Types.NumCopies
@ -262,7 +263,7 @@ lockContentUsing contentlocker key fallback a = withContentLockFile key $ \mlock
cleanuplockfile lockfile = void $ tryNonAsync $ do cleanuplockfile lockfile = void $ tryNonAsync $ do
thawContentDir lockfile thawContentDir lockfile
liftIO $ removeWhenExistsWith R.removeLink lockfile liftIO $ removeWhenExistsWith R.removeLink lockfile
liftIO $ cleanObjectDirs 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
@ -607,15 +608,17 @@ cleanObjectLoc key cleaner = do
void $ tryIO $ thawContent file void $ tryIO $ thawContent file
cleaner cleaner
liftIO $ cleanObjectDirs file cleanObjectDirs file
cleanObjectDirs :: RawFilePath -> IO () cleanObjectDirs :: RawFilePath -> Annex ()
cleanObjectDirs = go (3 :: Int) cleanObjectDirs f = do
HashLevels n <- objectHashLevels <$> Annex.getGitConfig
liftIO $ go f (succ n)
where where
go 0 _ = noop go _ 0 = noop
go n file = do go file n = do
let dir = parentDir file let dir = parentDir file
maybe noop (const $ go (n-1) dir) maybe noop (const $ go dir (n-1))
<=< 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/ -}