more OsPath conversion (542/749)

Sponsored-by: Luke T. Shumaker
This commit is contained in:
Joey Hess 2025-02-06 11:38:14 -04:00
parent 0d2b805806
commit 0811531b59
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 127 additions and 116 deletions

View file

@ -39,12 +39,12 @@ seeker fast = AnnexedFileSeeker
, usesLocationLog = False
}
start :: Bool -> SeekInput -> RawFilePath -> Key -> CommandStart
start :: Bool -> SeekInput -> OsPath -> Key -> CommandStart
start fast si file key =
starting "unannex" (mkActionItem (key, file)) si $
perform fast file key
perform :: Bool -> RawFilePath -> Key -> CommandPerform
perform :: Bool -> OsPath -> Key -> CommandPerform
perform fast file key = do
Annex.Queue.addCommand [] "rm"
[ Param "--cached"
@ -52,7 +52,7 @@ perform fast file key = do
, Param "--quiet"
, Param "--"
]
[fromRawFilePath file]
[fromOsPath file]
isAnnexLink file >>= \case
-- If the file is locked, it needs to be replaced with
-- the content from the annex. Note that it's possible
@ -73,9 +73,9 @@ perform fast file key = do
maybe noop Database.Keys.removeInodeCache
=<< withTSDelta (liftIO . genInodeCache file)
cleanup :: Bool -> RawFilePath -> Key -> CommandCleanup
cleanup :: Bool -> OsPath -> Key -> CommandCleanup
cleanup fast file key = do
liftIO $ removeFile (fromRawFilePath file)
liftIO $ removeFile file
src <- calcRepo (gitAnnexLocation key)
ifM (pure fast <||> Annex.getRead Annex.fast)
( do
@ -83,7 +83,7 @@ cleanup fast file key = do
-- already have other hard links pointing at it. This
-- avoids unannexing (and uninit) ending up hard
-- linking files together, which would be surprising.
s <- liftIO $ R.getFileStatus src
s <- liftIO $ R.getFileStatus (fromOsPath src)
if linkCount s > 1
then copyfrom src
else hardlinkfrom src
@ -91,13 +91,14 @@ cleanup fast file key = do
)
where
copyfrom src =
thawContent file `after` liftIO
(copyFileExternal CopyAllMetaData
(fromRawFilePath src)
(fromRawFilePath file))
thawContent file `after`
liftIO (copyFileExternal CopyAllMetaData src file)
hardlinkfrom src =
-- creating a hard link could fall; fall back to copying
ifM (liftIO $ catchBoolIO $ R.createLink src file >> return True)
ifM (liftIO $ tryhardlink src file)
( return True
, copyfrom src
)
tryhardlink src dest = catchBoolIO $ do
R.createLink (fromOsPath src) (fromOsPath dest)
return True

View file

@ -18,7 +18,6 @@ import qualified Annex
import qualified Git.LsFiles as LsFiles
import qualified Git.Command as Git
import qualified Git.Branch
import qualified Utility.RawFilePath as R
cmd :: Command
cmd = notBareRepo $ withAnnexOptions [jsonOptions] $
@ -30,7 +29,7 @@ seek :: CmdParams -> CommandSeek
seek ps = do
-- Safety first; avoid any undo that would touch files that are not
-- in the index.
(fs, cleanup) <- inRepo $ LsFiles.notInRepo [] False (map toRawFilePath ps)
(fs, cleanup) <- inRepo $ LsFiles.notInRepo [] False (map toOsPath ps)
unless (null fs) $ do
qp <- coreQuotePath <$> Annex.getGitConfig
giveup $ decodeBS $ quote qp $
@ -48,19 +47,20 @@ seek ps = do
start :: FilePath -> CommandStart
start p = starting "undo" ai si $
perform p
perform p'
where
ai = ActionItemOther (Just (QuotedPath (toRawFilePath p)))
p' = toOsPath p
ai = ActionItemOther (Just (QuotedPath p'))
si = SeekInput [p]
perform :: FilePath -> CommandPerform
perform :: OsPath -> CommandPerform
perform p = do
g <- gitRepo
-- Get the reversed diff that needs to be applied to undo.
(diff, cleanup) <- inRepo $
diffLog [Param "-R", Param "--", Param p]
top <- inRepo $ toTopFilePath $ toRawFilePath p
diffLog [Param "-R", Param "--", Param (fromOsPath p)]
top <- inRepo $ toTopFilePath p
let diff' = filter (`isDiffOf` top) diff
liftIO $ streamUpdateIndex g (map stageDiffTreeItem diff')
@ -73,10 +73,10 @@ perform p = do
forM_ removals $ \di -> do
f <- mkrel di
liftIO $ removeWhenExistsWith R.removeLink f
liftIO $ removeWhenExistsWith removeFile f
forM_ adds $ \di -> do
f <- fromRawFilePath <$> mkrel di
f <- fromOsPath <$> mkrel di
inRepo $ Git.run [Param "checkout", Param "--", File f]
next $ liftIO cleanup

View file

@ -73,7 +73,7 @@ checkCanUninit recordok =
when (b == Just Annex.Branch.name) $ giveup $
"cannot uninit when the " ++ Git.fromRef Annex.Branch.name ++ " branch is checked out"
top <- fromRepo Git.repoPath
currdir <- liftIO R.getCurrentDirectory
currdir <- liftIO getCurrentDirectory
whenM ((/=) <$> liftIO (absPath top) <*> liftIO (absPath currdir)) $
giveup "can only run uninit from the top of the git repository"
@ -87,14 +87,14 @@ checkCanUninit recordok =
{- git annex symlinks that are not checked into git could be left by an
- interrupted add. -}
startCheckIncomplete :: Annex () -> RawFilePath -> Key -> CommandStart
startCheckIncomplete :: Annex () -> OsPath -> Key -> CommandStart
startCheckIncomplete recordnotok file key =
starting "uninit check" (mkActionItem (file, key)) (SeekInput []) $ do
recordnotok
giveup $ unlines err
where
err =
[ fromRawFilePath file ++ " points to annexed content, but is not checked into git."
[ fromOsPath file ++ " points to annexed content, but is not checked into git."
, "Perhaps this was left behind by an interrupted git annex add?"
, "Not continuing with uninit; either delete or git annex add the file and retry."
]
@ -109,11 +109,11 @@ removeAnnexDir recordok = do
prepareRemoveAnnexDir annexdir
if null leftovers
then do
liftIO $ removeDirectoryRecursive (fromRawFilePath annexdir)
liftIO $ removeDirectoryRecursive annexdir
next recordok
else giveup $ unlines
[ "Not fully uninitialized"
, "Some annexed data is still left in " ++ fromRawFilePath annexobjectdir
, "Some annexed data is still left in " ++ fromOsPath annexobjectdir
, "This may include deleted files, or old versions of modified files."
, ""
, "If you don't care about preserving the data, just delete the"
@ -134,12 +134,12 @@ removeAnnexDir recordok = do
-
- Also closes sqlite databases that might be in the directory,
- to avoid later failure to write any cached changes to them. -}
prepareRemoveAnnexDir :: RawFilePath -> Annex ()
prepareRemoveAnnexDir :: OsPath -> Annex ()
prepareRemoveAnnexDir annexdir = do
Database.Keys.closeDb
liftIO $ prepareRemoveAnnexDir' annexdir
prepareRemoveAnnexDir' :: RawFilePath -> IO ()
prepareRemoveAnnexDir' :: OsPath -> IO ()
prepareRemoveAnnexDir' annexdir =
emptyWhenDoesNotExist (dirTreeRecursiveSkipping (const False) annexdir)
>>= mapM_ (void . tryIO . allowWrite)
@ -159,7 +159,7 @@ removeUnannexed = go []
, go (k:c) ks
)
enoughlinks f = catchBoolIO $ do
s <- R.getFileStatus f
s <- R.getFileStatus (fromOsPath f)
return $ linkCount s > 1
completeUnitialize :: CommandStart

View file

@ -40,7 +40,7 @@ seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
, usesLocationLog = False
}
start :: SeekInput -> RawFilePath -> Key -> CommandStart
start :: SeekInput -> OsPath -> Key -> CommandStart
start si file key = ifM (isJust <$> isAnnexLink file)
( starting "unlock" ai si $ perform file key
, stop
@ -48,9 +48,9 @@ start si file key = ifM (isJust <$> isAnnexLink file)
where
ai = mkActionItem (key, AssociatedFile (Just file))
perform :: RawFilePath -> Key -> CommandPerform
perform :: OsPath -> Key -> CommandPerform
perform dest key = do
destmode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus dest
destmode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus (fromOsPath dest)
destic <- replaceWorkTreeFile dest $ \tmp -> do
ifM (inAnnex key)
( do
@ -64,7 +64,7 @@ perform dest key = do
withTSDelta (liftIO . genInodeCache tmp)
next $ cleanup dest destic key destmode
cleanup :: RawFilePath -> Maybe InodeCache -> Key -> Maybe FileMode -> CommandCleanup
cleanup :: OsPath -> Maybe InodeCache -> Key -> Maybe FileMode -> CommandCleanup
cleanup dest destic key destmode = do
stagePointerFile dest destmode =<< hashPointerFile key
maybe noop (restagePointerFile (Restage True) dest) destic

View file

@ -119,7 +119,7 @@ check fileprefix msg a c = do
maybeAddJSONField
((if null fileprefix then "unused" else fileprefix) ++ "-list")
(M.fromList $ map (\(n, k) -> (T.pack (show n), serializeKey k)) unusedlist)
updateUnusedLog (toRawFilePath fileprefix) (M.fromList unusedlist)
updateUnusedLog (toOsPath fileprefix) (M.fromList unusedlist)
return $ c + length l
number :: Int -> [a] -> [(Int, a)]
@ -194,7 +194,7 @@ excludeReferenced refspec ks = runbloomfilter withKeysReferencedM ks
{- Given an initial value, accumulates the value over each key
- referenced by files in the working tree. -}
withKeysReferenced :: v -> (Key -> RawFilePath -> v -> Annex v) -> Annex v
withKeysReferenced :: v -> (Key -> OsPath -> v -> Annex v) -> Annex v
withKeysReferenced initial = withKeysReferenced' Nothing initial
{- Runs an action on each referenced key in the working tree. -}
@ -204,10 +204,10 @@ withKeysReferencedM a = withKeysReferenced' Nothing () calla
calla k _ _ = a k
{- Folds an action over keys and files referenced in a particular directory. -}
withKeysFilesReferencedIn :: FilePath -> v -> (Key -> RawFilePath -> v -> Annex v) -> Annex v
withKeysFilesReferencedIn :: OsPath -> v -> (Key -> OsPath -> v -> Annex v) -> Annex v
withKeysFilesReferencedIn = withKeysReferenced' . Just
withKeysReferenced' :: Maybe FilePath -> v -> (Key -> RawFilePath -> v -> Annex v) -> Annex v
withKeysReferenced' :: Maybe OsPath -> v -> (Key -> OsPath -> v -> Annex v) -> Annex v
withKeysReferenced' mdir initial a = do
(files, clean) <- getfiles
r <- go initial files
@ -221,7 +221,7 @@ withKeysReferenced' mdir initial a = do
top <- fromRepo Git.repoPath
inRepo $ LsFiles.allFiles [] [top]
)
Just dir -> inRepo $ LsFiles.inRepo [] [toRawFilePath dir]
Just dir -> inRepo $ LsFiles.inRepo [] [dir]
go v [] = return v
go v (f:fs) = do
mk <- lookupKey f
@ -308,9 +308,9 @@ data UnusedMaps = UnusedMaps
withUnusedMaps :: (UnusedMaps -> Int -> CommandStart) -> CmdParams -> CommandSeek
withUnusedMaps a params = do
unused <- readUnusedMap ""
unusedbad <- readUnusedMap "bad"
unusedtmp <- readUnusedMap "tmp"
unused <- readUnusedMap (literalOsPath "")
unusedbad <- readUnusedMap (literalOsPath "bad")
unusedtmp <- readUnusedMap (literalOsPath "tmp")
let m = unused `M.union` unusedbad `M.union` unusedtmp
let unusedmaps = UnusedMaps unused unusedbad unusedtmp
commandActions $ map (a unusedmaps) $ concatMap (unusedSpec m) params

View file

@ -34,7 +34,6 @@ import Types.NumCopies
import Remote
import Git.Types (fromConfigKey, fromConfigValue)
import Utility.DataUnits
import qualified Utility.RawFilePath as R
import qualified Utility.FileIO as F
cmd :: Command
@ -47,30 +46,35 @@ seek = withNothing (commandAction start)
start :: CommandStart
start = do
f <- fromRepo gitAnnexTmpCfgFile
let f' = fromRawFilePath f
createAnnexDirectory $ parentDir f
cfg <- getCfg
descs <- uuidDescriptions
liftIO $ writeFile f' $ genCfg cfg descs
vicfg cfg f'
liftIO $ writeFile (fromOsPath f) $ genCfg cfg descs
vicfg cfg f
stop
vicfg :: Cfg -> FilePath -> Annex ()
vicfg :: Cfg -> OsPath -> Annex ()
vicfg curcfg f = do
vi <- liftIO $ catchDefaultIO "vi" $ getEnv "EDITOR"
-- Allow EDITOR to be processed by the shell, so it can contain options.
unlessM (liftIO $ boolSystem "sh" [Param "-c", Param $ unwords [vi, shellEscape f]]) $
unlessM (liftIO $ boolSystem "sh" (shparams vi)) $
giveup $ vi ++ " exited nonzero; aborting"
r <- liftIO $ parseCfg (defCfg curcfg)
. map decodeBS
. fileLines'
<$> F.readFile' (toOsPath (toRawFilePath f))
liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
<$> F.readFile' f
liftIO $ removeWhenExistsWith removeFile f
case r of
Left s -> do
liftIO $ writeFile f s
liftIO $ writeFile (fromOsPath f) s
vicfg curcfg f
Right newcfg -> setCfg curcfg newcfg
where
-- Allow EDITOR to be processed by the shell,
-- so it can contain options.
shparams editor =
[ Param "-c"
, Param $ unwords [editor, shellEscape (fromOsPath f)]
]
data Cfg = Cfg
{ cfgTrustMap :: M.Map UUID (Down TrustLevel)

View file

@ -24,8 +24,6 @@ import Logs.View
import Types.AdjustedBranch
import Annex.AdjustedBranch.Name
import qualified System.FilePath.ByteString as P
cmd :: Command
cmd = notBareRepo $
command "view" SectionMetaData "enter a view branch"
@ -120,13 +118,12 @@ checkoutViewBranch view madj mkbranch = do
forM_ l (removeemptydir top)
liftIO $ void cleanup
unlessM (liftIO $ doesDirectoryExist here) $ do
showLongNote $ UnquotedString $ cwdmissing (fromRawFilePath top)
showLongNote $ UnquotedString $ cwdmissing (fromOsPath top)
return ok
where
removeemptydir top d = do
p <- inRepo $ toTopFilePath d
liftIO $ tryIO $ removeDirectory $
fromRawFilePath $ (top P.</> getTopFilePath p)
liftIO $ tryIO $ removeDirectory $ top </> getTopFilePath p
cwdmissing top = unlines
[ "This view does not include the subdirectory you are currently in."
, "Perhaps you should: cd " ++ top

View file

@ -124,7 +124,7 @@ findHistorical key = do
display key (descBranchFilePath (BranchFilePath r tf))
return True
searchLog :: Key -> [CommandParam] -> (S.ByteString -> [RawFilePath] -> Annex Bool) -> Annex Bool
searchLog :: Key -> [CommandParam] -> (S.ByteString -> [OsPath] -> Annex Bool) -> Annex Bool
searchLog key ps a = do
(output, cleanup) <- Annex.inRepo $ Git.Command.pipeNullSplit ps'
found <- case output of
@ -154,7 +154,7 @@ searchLog key ps a = do
-- so a regexp is used. Since annex pointer files
-- may contain a newline followed by perhaps something
-- else, that is also matched.
, Param ("-G" ++ escapeRegexp (fromRawFilePath (keyFile key)) ++ "($|\n)")
, Param ("-G" ++ escapeRegexp (fromOsPath (keyFile key)) ++ "($|\n)")
-- Skip commits where the file was deleted,
-- only find those where it was added or modified.
, Param "--diff-filter=ACMRTUX"