From f8bb9a873416aa757da271e04c8071952a7c555c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 11 Feb 2025 13:41:26 -0400 Subject: [PATCH] replace removeLink with removeFile same reasoning as in commit 5cc8d9d03b53f2e43d51e4f612f423178519e824 --- Annex/Content/PointerFile.hs | 10 ++++------ Annex/Content/Presence.hs | 2 +- Annex/Fixup.hs | 5 ++--- Annex/Ingest.hs | 2 +- Annex/Link.hs | 6 ++---- Annex/Tmp.hs | 6 +++--- Annex/Transfer.hs | 2 +- Build/DistributionUpdate.hs | 2 +- Command/Fsck.hs | 2 +- 9 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Annex/Content/PointerFile.hs b/Annex/Content/PointerFile.hs index c37614be94..22657a11c8 100644 --- a/Annex/Content/PointerFile.hs +++ b/Annex/Content/PointerFile.hs @@ -34,10 +34,9 @@ populatePointerFile :: Restage -> Key -> OsPath -> OsPath -> Annex (Maybe InodeC populatePointerFile restage k obj f = go =<< liftIO (isPointerFile f) where go (Just k') | k == k' = do - let f' = fromOsPath f destmode <- liftIO $ catchMaybeIO $ - fileMode <$> R.getFileStatus f' - liftIO $ removeWhenExistsWith R.removeLink f' + fileMode <$> R.getFileStatus (fromOsPath f) + liftIO $ removeWhenExistsWith removeFile f (ic, populated) <- replaceWorkTreeFile f $ \tmp -> do ok <- linkOrCopy k obj tmp destmode >>= \case Just _ -> thawContent tmp >> return True @@ -55,11 +54,10 @@ populatePointerFile restage k obj f = go =<< liftIO (isPointerFile f) - Does not check if the pointer file is modified. -} depopulatePointerFile :: Key -> OsPath -> Annex () depopulatePointerFile key file = do - let file' = fromOsPath file - st <- liftIO $ catchMaybeIO $ R.getFileStatus file' + st <- liftIO $ catchMaybeIO $ R.getFileStatus (fromOsPath file) let mode = fmap fileMode st secureErase file - liftIO $ removeWhenExistsWith R.removeLink file' + liftIO $ removeWhenExistsWith removeFile file ic <- replaceWorkTreeFile file $ \tmp -> do liftIO $ writePointerFile tmp key mode #if ! defined(mingw32_HOST_OS) diff --git a/Annex/Content/Presence.hs b/Annex/Content/Presence.hs index 1ef022c1ba..376e8d1a1d 100644 --- a/Annex/Content/Presence.hs +++ b/Annex/Content/Presence.hs @@ -116,7 +116,7 @@ inAnnexSafe key = inAnnex' (fromMaybe True) (Just False) go key Nothing -> return is_locked Just lockhandle -> do dropLock lockhandle - void $ tryIO $ removeWhenExistsWith R.removeLink lockfile + void $ tryIO $ removeWhenExistsWith removeFile lockfile return is_unlocked , return is_missing ) diff --git a/Annex/Fixup.hs b/Annex/Fixup.hs index f27ab45e38..a0e5730333 100644 --- a/Annex/Fixup.hs +++ b/Annex/Fixup.hs @@ -112,9 +112,8 @@ fixupUnusualRepos r@(Repo { location = l@(Local { worktree = Just w, gitdir = d replacedotgit = whenM (doesFileExist dotgit) $ do linktarget <- relPathDirToFile w d - let dotgit' = fromOsPath dotgit - removeWhenExistsWith R.removeLink dotgit' - R.createSymbolicLink (fromOsPath linktarget) dotgit' + removeWhenExistsWith removeFile dotgit + R.createSymbolicLink (fromOsPath linktarget) (fromOsPath dotgit) -- Unsetting a config fails if it's not set, so ignore failure. unsetcoreworktree = void $ Git.Config.unset "core.worktree" r diff --git a/Annex/Ingest.hs b/Annex/Ingest.hs index 47399567fc..695a0cb063 100644 --- a/Annex/Ingest.hs +++ b/Annex/Ingest.hs @@ -120,7 +120,7 @@ lockDown' cfg file = tryNonAsync $ ifM crippledFileSystem relatedTemplate $ fromOsPath $ literalOsPath "ingest-" <> takeFileName file hClose h - removeWhenExistsWith R.removeLink (fromOsPath tmpfile) + removeWhenExistsWith removeFile tmpfile withhardlink' delta tmpfile `catchIO` const (nohardlink' delta) diff --git a/Annex/Link.hs b/Annex/Link.hs index 559add24ed..2f22143dd8 100644 --- a/Annex/Link.hs +++ b/Annex/Link.hs @@ -116,12 +116,10 @@ makeAnnexLink = makeGitLink makeGitLink :: LinkTarget -> OsPath -> Annex () makeGitLink linktarget file = ifM (coreSymlinks <$> Annex.getGitConfig) ( liftIO $ do - void $ tryIO $ R.removeLink file' - R.createSymbolicLink linktarget file' + void $ tryIO $ removeFile file + R.createSymbolicLink linktarget (fromOsPath file) , liftIO $ F.writeFile' file linktarget ) - where - file' = fromOsPath file {- Creates a link on disk, and additionally stages it in git. -} addAnnexLink :: LinkTarget -> OsPath -> Annex () diff --git a/Annex/Tmp.hs b/Annex/Tmp.hs index 6a1fd99f7e..d6b18332cb 100644 --- a/Annex/Tmp.hs +++ b/Annex/Tmp.hs @@ -61,7 +61,7 @@ cleanupOtherTmp = do tmpdir <- fromRepo gitAnnexTmpOtherDir void $ liftIO $ tryIO $ removeDirectoryRecursive tmpdir oldtmp <- fromRepo gitAnnexTmpOtherDirOld - liftIO $ mapM_ (cleanold . fromOsPath) + liftIO $ mapM_ cleanold =<< emptyWhenDoesNotExist (dirContentsRecursive oldtmp) -- remove when empty liftIO $ void $ tryIO $ removeDirectory oldtmp @@ -69,7 +69,7 @@ cleanupOtherTmp = do cleanold f = do now <- liftIO getPOSIXTime let oldenough = now - (60 * 60 * 24 * 7) - catchMaybeIO (modificationTime <$> R.getSymbolicLinkStatus f) >>= \case + catchMaybeIO (modificationTime <$> R.getSymbolicLinkStatus (fromOsPath f)) >>= \case Just mtime | realToFrac mtime <= oldenough -> - void $ tryIO $ removeWhenExistsWith R.removeLink f + void $ tryIO $ removeWhenExistsWith removeFile f _ -> return () diff --git a/Annex/Transfer.hs b/Annex/Transfer.hs index c2fbfa5786..45969003ae 100644 --- a/Annex/Transfer.hs +++ b/Annex/Transfer.hs @@ -216,7 +216,7 @@ runTransfer' ignorelock t eventualbackend afile stalldetection retrydecider tran -} maybe noop dropLock moldlockhandle dropLock lockhandle - void $ tryIO $ R.removeLink lckfile + void $ tryIO $ removeFile lckfile maybe noop (void . tryIO . removeFile) moldlckfile #endif diff --git a/Build/DistributionUpdate.hs b/Build/DistributionUpdate.hs index 80a0b2cdf3..d864c7cf09 100644 --- a/Build/DistributionUpdate.hs +++ b/Build/DistributionUpdate.hs @@ -233,7 +233,7 @@ buildrpms topdir l = do <$> liftIO (getDirectoryContents rpmrepo) forM_ tarrpmarches $ \(tararch, rpmarch) -> forM_ (filter (isstandalonetarball tararch . fst) l) $ \(tarball, v) -> do - liftIO $ mapM_ (removeWhenExistsWith (R.removeLink . toRawFilePath)) + liftIO $ mapM_ (removeWhenExistsWith removeFile) (filter ((rpmarch ++ ".rpm") `isSuffixOf`) oldrpms) void $ liftIO $ boolSystem script [ Param rpmarch diff --git a/Command/Fsck.hs b/Command/Fsck.hs index d8f18bf16b..4e66755c02 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -246,7 +246,7 @@ fixLink key file = do | want /= fromInternalGitPath have = do showNote "fixing link" createWorkTreeDirectory (parentDir file) - liftIO $ R.removeLink (fromOsPath file) + liftIO $ removeFile file addAnnexLink (fromOsPath want) file | otherwise = noop