more OsPath conversion
Sponsored-by: Brock Spratlen
This commit is contained in:
parent
c69e57aede
commit
474cf3bc8b
38 changed files with 342 additions and 330 deletions
|
@ -15,7 +15,6 @@ import Annex.Common
|
|||
import Git.Fsck
|
||||
import Git.Types
|
||||
import Logs.File
|
||||
import qualified Utility.RawFilePath as R
|
||||
|
||||
import qualified Data.Set as S
|
||||
|
||||
|
@ -25,7 +24,7 @@ writeFsckResults u fsckresults = do
|
|||
case serializeFsckResults fsckresults of
|
||||
Just s -> store s logfile
|
||||
Nothing -> liftIO $
|
||||
removeWhenExistsWith R.removeLink logfile
|
||||
removeWhenExistsWith removeFile logfile
|
||||
where
|
||||
store s logfile = writeLogFile logfile s
|
||||
|
||||
|
@ -46,7 +45,7 @@ readFsckResults :: UUID -> Annex FsckResults
|
|||
readFsckResults u = do
|
||||
logfile <- fromRepo $ gitAnnexFsckResultsLog u
|
||||
liftIO $ catchDefaultIO (FsckFoundMissing S.empty False) $
|
||||
deserializeFsckResults <$> readFile (fromRawFilePath logfile)
|
||||
deserializeFsckResults <$> readFile (fromOsPath logfile)
|
||||
|
||||
deserializeFsckResults :: String -> FsckResults
|
||||
deserializeFsckResults = deserialize . lines
|
||||
|
@ -58,6 +57,6 @@ deserializeFsckResults = deserialize . lines
|
|||
in if S.null s then FsckFailed else FsckFoundMissing s t
|
||||
|
||||
clearFsckResults :: UUID -> Annex ()
|
||||
clearFsckResults = liftIO . removeWhenExistsWith R.removeLink
|
||||
clearFsckResults = liftIO . removeWhenExistsWith removeFile
|
||||
<=< fromRepo . gitAnnexFsckResultsLog
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import qualified Utility.FileIO as F
|
|||
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Utility.RawFilePath as R
|
||||
|
||||
-- | Log a file whose pointer needs to be restaged in git.
|
||||
-- The content of the file may not be a pointer, if it is populated with
|
||||
|
@ -52,13 +51,13 @@ streamRestageLog finalizer processor = do
|
|||
lckf <- fromRepo gitAnnexRestageLock
|
||||
|
||||
withExclusiveLock lckf $ liftIO $
|
||||
whenM (R.doesPathExist logf) $
|
||||
ifM (R.doesPathExist oldf)
|
||||
whenM (doesPathExist logf) $
|
||||
ifM (doesPathExist oldf)
|
||||
( do
|
||||
h <- F.openFile (toOsPath oldf) AppendMode
|
||||
hPutStr h =<< readFile (fromRawFilePath logf)
|
||||
h <- F.openFile oldf AppendMode
|
||||
hPutStr h =<< readFile (fromOsPath logf)
|
||||
hClose h
|
||||
liftIO $ removeWhenExistsWith R.removeLink logf
|
||||
liftIO $ removeWhenExistsWith removeFile logf
|
||||
, moveFile logf oldf
|
||||
)
|
||||
|
||||
|
@ -67,7 +66,7 @@ streamRestageLog finalizer processor = do
|
|||
Just (f, ic) -> processor f ic
|
||||
Nothing -> noop
|
||||
|
||||
liftIO $ removeWhenExistsWith R.removeLink oldf
|
||||
liftIO $ removeWhenExistsWith removeFile oldf
|
||||
|
||||
-- | Calculate over both the current restage log, and also over the old
|
||||
-- one if it had started to be processed but did not get finished due
|
||||
|
@ -86,11 +85,12 @@ calcRestageLog start update = do
|
|||
Nothing -> v
|
||||
|
||||
formatRestageLog :: TopFilePath -> InodeCache -> S.ByteString
|
||||
formatRestageLog f ic = encodeBS (showInodeCache ic) <> ":" <> getTopFilePath f
|
||||
formatRestageLog f ic =
|
||||
encodeBS (showInodeCache ic) <> ":" <> fromOsPath (getTopFilePath f)
|
||||
|
||||
parseRestageLog :: String -> Maybe (TopFilePath, InodeCache)
|
||||
parseRestageLog l =
|
||||
let (ics, f) = separate (== ':') l
|
||||
in do
|
||||
ic <- readInodeCache ics
|
||||
return (asTopFilePath (toRawFilePath f), ic)
|
||||
return (asTopFilePath (toOsPath f), ic)
|
||||
|
|
|
@ -21,7 +21,7 @@ smudgeLog k f = do
|
|||
logf <- fromRepo gitAnnexSmudgeLog
|
||||
lckf <- fromRepo gitAnnexSmudgeLock
|
||||
appendLogFile logf lckf $ L.fromStrict $
|
||||
serializeKey' k <> " " <> getTopFilePath f
|
||||
serializeKey' k <> " " <> fromOsPath (getTopFilePath f)
|
||||
|
||||
-- | Streams all smudged files, and then empties the log at the end.
|
||||
--
|
||||
|
@ -43,4 +43,4 @@ streamSmudged a = do
|
|||
let (ks, f) = separate (== ' ') l
|
||||
in do
|
||||
k <- deserializeKey ks
|
||||
return (k, asTopFilePath (toRawFilePath f))
|
||||
return (k, asTopFilePath (toOsPath f))
|
||||
|
|
|
@ -21,8 +21,8 @@ import Utility.PID
|
|||
import Annex.LockPool
|
||||
import Utility.TimeStamp
|
||||
import Logs.File
|
||||
import qualified Utility.RawFilePath as R
|
||||
import qualified Utility.FileIO as F
|
||||
import qualified Utility.OsString as OS
|
||||
#ifndef mingw32_HOST_OS
|
||||
import Annex.Perms
|
||||
#endif
|
||||
|
@ -30,9 +30,6 @@ import Annex.Perms
|
|||
import Data.Time.Clock
|
||||
import Data.Time.Clock.POSIX
|
||||
import Control.Concurrent.STM
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.ByteString.Char8 as B8
|
||||
import qualified System.FilePath.ByteString as P
|
||||
|
||||
describeTransfer :: Git.Quote.QuotePath -> Transfer -> TransferInfo -> String
|
||||
describeTransfer qp t info = unwords
|
||||
|
@ -62,20 +59,21 @@ percentComplete t info =
|
|||
- appropriate permissions, which should be run after locking the transfer
|
||||
- lock file, but before using the callback, and a TVar that can be used to
|
||||
- read the number of bytes processed so far. -}
|
||||
mkProgressUpdater :: Transfer -> TransferInfo -> RawFilePath -> Annex (MeterUpdate, Annex (), TVar (Maybe BytesProcessed))
|
||||
mkProgressUpdater :: Transfer -> TransferInfo -> OsPath -> Annex (MeterUpdate, Annex (), TVar (Maybe BytesProcessed))
|
||||
mkProgressUpdater t info tfile = do
|
||||
let createtfile = void $ tryNonAsync $ writeTransferInfoFile info tfile
|
||||
let createtfile = void $ tryNonAsync $
|
||||
writeTransferInfoFile info tfile
|
||||
tvar <- liftIO $ newTVarIO Nothing
|
||||
loggedtvar <- liftIO $ newTVarIO 0
|
||||
return (liftIO . updater (fromRawFilePath tfile) tvar loggedtvar, createtfile, tvar)
|
||||
return (liftIO . updater tvar loggedtvar, createtfile, tvar)
|
||||
where
|
||||
updater tfile' tvar loggedtvar new = do
|
||||
updater tvar loggedtvar new = do
|
||||
old <- atomically $ swapTVar tvar (Just new)
|
||||
let oldbytes = maybe 0 fromBytesProcessed old
|
||||
let newbytes = fromBytesProcessed new
|
||||
when (newbytes - oldbytes >= mindelta) $ do
|
||||
let info' = info { bytesComplete = Just newbytes }
|
||||
_ <- tryIO $ updateTransferInfoFile info' tfile'
|
||||
_ <- tryIO $ updateTransferInfoFile info' tfile
|
||||
atomically $ writeTVar loggedtvar newbytes
|
||||
|
||||
{- The minimum change in bytesComplete that is worth
|
||||
|
@ -109,9 +107,9 @@ checkTransfer :: Transfer -> Annex (Maybe TransferInfo)
|
|||
checkTransfer t = debugLocks $ do
|
||||
(tfile, lck, moldlck) <- fromRepo $ transferFileAndLockFile t
|
||||
let deletestale = do
|
||||
void $ tryIO $ R.removeLink tfile
|
||||
void $ tryIO $ R.removeLink lck
|
||||
maybe noop (void . tryIO . R.removeLink) moldlck
|
||||
void $ tryIO $ removeFile tfile
|
||||
void $ tryIO $ removeFile lck
|
||||
maybe noop (void . tryIO . removeFile) moldlck
|
||||
#ifndef mingw32_HOST_OS
|
||||
v <- getLockStatus lck
|
||||
v' <- case (moldlck, v) of
|
||||
|
@ -198,7 +196,7 @@ clearFailedTransfers u = do
|
|||
removeFailedTransfer :: Transfer -> Annex ()
|
||||
removeFailedTransfer t = do
|
||||
f <- fromRepo $ failedTransferFile t
|
||||
liftIO $ void $ tryIO $ R.removeLink f
|
||||
liftIO $ void $ tryIO $ removeFile f
|
||||
|
||||
recordFailedTransfer :: Transfer -> TransferInfo -> Annex ()
|
||||
recordFailedTransfer t info = do
|
||||
|
@ -225,46 +223,47 @@ recordFailedTransfer t info = do
|
|||
- At some point in the future, when old git-annex processes are no longer
|
||||
- a concern, this complication can be removed.
|
||||
-}
|
||||
transferFileAndLockFile :: Transfer -> Git.Repo -> (RawFilePath, RawFilePath, Maybe RawFilePath)
|
||||
transferFileAndLockFile :: Transfer -> Git.Repo -> (OsPath, OsPath, Maybe OsPath)
|
||||
transferFileAndLockFile (Transfer direction u kd) r =
|
||||
case direction of
|
||||
Upload -> (transferfile, uuidlockfile, Nothing)
|
||||
Download -> (transferfile, nouuidlockfile, Just uuidlockfile)
|
||||
where
|
||||
td = transferDir direction r
|
||||
fu = B8.filter (/= '/') (fromUUID u)
|
||||
fu = OS.filter (/= unsafeFromChar '/') (fromUUID u)
|
||||
kf = keyFile (mkKey (const kd))
|
||||
lckkf = "lck." <> kf
|
||||
transferfile = td P.</> fu P.</> kf
|
||||
uuidlockfile = td P.</> fu P.</> lckkf
|
||||
nouuidlockfile = td P.</> "lck" P.</> lckkf
|
||||
lckkf = literalOsPath "lck." <> kf
|
||||
transferfile = td </> fu </> kf
|
||||
uuidlockfile = td </> fu </> lckkf
|
||||
nouuidlockfile = td </> literalOsPath "lck" </> lckkf
|
||||
|
||||
{- The transfer information file to use to record a failed Transfer -}
|
||||
failedTransferFile :: Transfer -> Git.Repo -> RawFilePath
|
||||
failedTransferFile :: Transfer -> Git.Repo -> OsPath
|
||||
failedTransferFile (Transfer direction u kd) r =
|
||||
failedTransferDir u direction r
|
||||
P.</> keyFile (mkKey (const kd))
|
||||
</> keyFile (mkKey (const kd))
|
||||
|
||||
{- Parses a transfer information filename to a Transfer. -}
|
||||
parseTransferFile :: RawFilePath -> Maybe Transfer
|
||||
parseTransferFile :: OsPath -> Maybe Transfer
|
||||
parseTransferFile file
|
||||
| "lck." `B.isPrefixOf` P.takeFileName file = Nothing
|
||||
| literalOsPath "lck." `OS.isPrefixOf` takeFileName file = Nothing
|
||||
| otherwise = case drop (length bits - 3) bits of
|
||||
[direction, u, key] -> Transfer
|
||||
<$> parseDirection direction
|
||||
<$> parseDirection (fromOsPath direction)
|
||||
<*> pure (toUUID u)
|
||||
<*> fmap (fromKey id) (fileKey key)
|
||||
_ -> Nothing
|
||||
where
|
||||
bits = P.splitDirectories file
|
||||
bits = splitDirectories file
|
||||
|
||||
writeTransferInfoFile :: TransferInfo -> RawFilePath -> Annex ()
|
||||
writeTransferInfoFile :: TransferInfo -> OsPath -> Annex ()
|
||||
writeTransferInfoFile info tfile = writeLogFile tfile $ writeTransferInfo info
|
||||
|
||||
-- The file keeps whatever permissions it has, so should be used only
|
||||
-- after it's been created with the right perms by writeTransferInfoFile.
|
||||
updateTransferInfoFile :: TransferInfo -> FilePath -> IO ()
|
||||
updateTransferInfoFile info tfile = writeFile tfile $ writeTransferInfo info
|
||||
updateTransferInfoFile :: TransferInfo -> OsPath -> IO ()
|
||||
updateTransferInfoFile info tfile =
|
||||
writeFile (fromOsPath tfile) $ writeTransferInfo info
|
||||
|
||||
{- File format is a header line containing the startedTime and any
|
||||
- bytesComplete value. Followed by a newline and the associatedFile.
|
||||
|
@ -283,12 +282,12 @@ writeTransferInfo info = unlines
|
|||
#endif
|
||||
-- comes last; arbitrary content
|
||||
, let AssociatedFile afile = associatedFile info
|
||||
in maybe "" fromRawFilePath afile
|
||||
in maybe "" fromOsPath afile
|
||||
]
|
||||
|
||||
readTransferInfoFile :: Maybe PID -> RawFilePath -> IO (Maybe TransferInfo)
|
||||
readTransferInfoFile :: Maybe PID -> OsPath -> IO (Maybe TransferInfo)
|
||||
readTransferInfoFile mpid tfile = catchDefaultIO Nothing $
|
||||
readTransferInfo mpid . decodeBS <$> F.readFile' (toOsPath tfile)
|
||||
readTransferInfo mpid . decodeBS <$> F.readFile' tfile
|
||||
|
||||
readTransferInfo :: Maybe PID -> String -> Maybe TransferInfo
|
||||
readTransferInfo mpid s = TransferInfo
|
||||
|
@ -301,9 +300,13 @@ readTransferInfo mpid s = TransferInfo
|
|||
<*> pure Nothing
|
||||
<*> pure Nothing
|
||||
<*> bytes
|
||||
<*> pure (AssociatedFile (if null filename then Nothing else Just (toRawFilePath filename)))
|
||||
<*> pure af
|
||||
<*> pure False
|
||||
where
|
||||
af = AssociatedFile $
|
||||
if null filename
|
||||
then Nothing
|
||||
else Just (toOsPath filename)
|
||||
#ifdef mingw32_HOST_OS
|
||||
(firstliner, otherlines) = separate (== '\n') s
|
||||
(secondliner, rest) = separate (== '\n') otherlines
|
||||
|
@ -326,16 +329,18 @@ readTransferInfo mpid s = TransferInfo
|
|||
else pure Nothing -- not failure
|
||||
|
||||
{- The directory holding transfer information files for a given Direction. -}
|
||||
transferDir :: Direction -> Git.Repo -> RawFilePath
|
||||
transferDir direction r = gitAnnexTransferDir r P.</> formatDirection direction
|
||||
transferDir :: Direction -> Git.Repo -> OsPath
|
||||
transferDir direction r =
|
||||
gitAnnexTransferDir r
|
||||
</> toOsPath (formatDirection direction)
|
||||
|
||||
{- The directory holding failed transfer information files for a given
|
||||
- Direction and UUID -}
|
||||
failedTransferDir :: UUID -> Direction -> Git.Repo -> RawFilePath
|
||||
failedTransferDir :: UUID -> Direction -> Git.Repo -> OsPath
|
||||
failedTransferDir u direction r = gitAnnexTransferDir r
|
||||
P.</> "failed"
|
||||
P.</> formatDirection direction
|
||||
P.</> B8.filter (/= '/') (fromUUID u)
|
||||
</> literalOsPath "failed"
|
||||
</> toOsPath (formatDirection direction)
|
||||
</> OS.filter (/= unsafeFromChar '/') (fromUUID u)
|
||||
|
||||
prop_read_write_transferinfo :: TransferInfo -> Bool
|
||||
prop_read_write_transferinfo info
|
||||
|
|
|
@ -32,8 +32,8 @@ import qualified Data.ByteString.Lazy as L
|
|||
import qualified Data.Attoparsec.ByteString.Lazy as A
|
||||
import qualified Data.Attoparsec.ByteString.Char8 as A8
|
||||
|
||||
transitionsLog :: RawFilePath
|
||||
transitionsLog = "transitions.log"
|
||||
transitionsLog :: OsPath
|
||||
transitionsLog = literalOsPath "transitions.log"
|
||||
|
||||
data Transition
|
||||
= ForgetGitHistory
|
||||
|
@ -102,7 +102,7 @@ knownTransitionList = nub . rights . map transition . S.elems
|
|||
|
||||
{- Typically ran with Annex.Branch.change, but we can't import Annex.Branch
|
||||
- here since it depends on this module. -}
|
||||
recordTransitions :: (RawFilePath -> (L.ByteString -> Builder) -> Annex ()) -> Transitions -> Annex ()
|
||||
recordTransitions :: (OsPath -> (L.ByteString -> Builder) -> Annex ()) -> Transitions -> Annex ()
|
||||
recordTransitions changer t = changer transitionsLog $
|
||||
buildTransitions . S.union t . parseTransitionsStrictly "local"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue