replace removeLink with removeFile

removeFile calls unlink so removes anything not a directory. So these
are replaceable in order to convert to OsPath.
This commit is contained in:
Joey Hess 2025-02-02 14:16:58 -04:00
parent 8af91a4c92
commit 5cc8d9d03b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 39 additions and 41 deletions

View file

@ -58,8 +58,7 @@ cleanCorruptObjects fsckresults r = do
mapM_ removeLoose (S.toList $ knownMissing fsckresults)
mapM_ removeBad =<< listLooseObjectShas r
where
removeLoose s = removeWhenExistsWith R.removeLink $
fromOsPath $ looseObjectFile r s
removeLoose s = removeWhenExistsWith removeFile $ looseObjectFile r s
removeBad s = do
void $ tryIO $ allowRead $ looseObjectFile r s
whenM (isMissing s r) $
@ -97,8 +96,8 @@ explodePacks r = go =<< listPackFiles r
createDirectoryIfMissing True (parentDir dest)
moveFile objfile dest
forM_ packs $ \packfile -> do
removeWhenExistsWith R.removeLink (fromOsPath packfile)
removeWhenExistsWith R.removeLink (fromOsPath (packIdxFile packfile))
removeWhenExistsWith removeFile packfile
removeWhenExistsWith removeFile (packIdxFile packfile)
return True
{- Try to retrieve a set of missing objects, from the remotes of a
@ -264,7 +263,7 @@ explodePackedRefsFile r = do
. fileLines'
<$> catchDefaultIO "" (safeReadFile f)
forM_ rs makeref
removeWhenExistsWith R.removeLink (fromOsPath f)
removeWhenExistsWith removeFile f
where
makeref (sha, ref) = do
let gitd = localGitDir r
@ -286,7 +285,7 @@ parsePacked l = case words l of
{- git-branch -d cannot be used to remove a branch that is directly
- pointing to a corrupt commit. -}
nukeBranchRef :: Branch -> Repo -> IO ()
nukeBranchRef b r = removeWhenExistsWith R.removeLink $ fromOsPath $
nukeBranchRef b r = removeWhenExistsWith removeFile $
localGitDir r </> toOsPath (fromRef' b)
{- Finds the most recent commit to a branch that does not need any
@ -425,7 +424,7 @@ rewriteIndex r
| otherwise = do
(bad, good, cleanup) <- partitionIndex r
unless (null bad) $ do
removeWhenExistsWith R.removeLink (fromOsPath (indexFile r))
removeWhenExistsWith removeFile (indexFile r)
UpdateIndex.streamUpdateIndex r
=<< (catMaybes <$> mapM reinject good)
void cleanup
@ -473,7 +472,7 @@ displayList items header
preRepair :: Repo -> IO ()
preRepair g = do
unlessM (validhead <$> catchDefaultIO "" (decodeBS <$> safeReadFile headfile)) $ do
removeWhenExistsWith R.removeLink (fromOsPath headfile)
removeWhenExistsWith removeFile headfile
writeFile (fromOsPath headfile) "ref: refs/heads/master"
explodePackedRefsFile g
unless (repoIsLocalBare g) $
@ -606,7 +605,7 @@ runRepair' removablebranch fsckresult forced referencerepo g = do
else successfulfinish modifiedbranches
corruptedindex = do
removeWhenExistsWith R.removeLink (fromOsPath (indexFile g))
removeWhenExistsWith removeFile (indexFile g)
-- The corrupted index can prevent fsck from finding other
-- problems, so re-run repair.
fsckresult' <- findBroken False False g