more OsPath conversion
Sponsored-by: k0ld
This commit is contained in:
parent
474cf3bc8b
commit
71195cce13
33 changed files with 198 additions and 194 deletions
|
@ -34,6 +34,7 @@ import Backend (isStableKey)
|
|||
import Annex.SpecialRemote.Config
|
||||
import Annex.Verify
|
||||
import qualified Utility.RawFilePath as R
|
||||
import qualified Utility.FileIO as F
|
||||
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
|
@ -120,7 +121,7 @@ storeChunks
|
|||
-> ChunkConfig
|
||||
-> EncKey
|
||||
-> Key
|
||||
-> FilePath
|
||||
-> OsPath
|
||||
-> MeterUpdate
|
||||
-> Maybe (Cipher, EncKey)
|
||||
-> encc
|
||||
|
@ -135,7 +136,7 @@ storeChunks u chunkconfig encryptor k f p enc encc storer checker =
|
|||
-- possible without this check.
|
||||
(UnpaddedChunks chunksize) -> ifM (isStableKey k)
|
||||
( do
|
||||
h <- liftIO $ openBinaryFile f ReadMode
|
||||
h <- liftIO $ F.openBinaryFile f ReadMode
|
||||
go chunksize h
|
||||
liftIO $ hClose h
|
||||
, storechunk k (FileContent f) p
|
||||
|
@ -257,7 +258,7 @@ retrieveChunks
|
|||
-> ChunkConfig
|
||||
-> EncKey
|
||||
-> Key
|
||||
-> FilePath
|
||||
-> OsPath
|
||||
-> MeterUpdate
|
||||
-> Maybe (Cipher, EncKey)
|
||||
-> encc
|
||||
|
@ -276,7 +277,7 @@ retrieveChunks retriever u vc chunkconfig encryptor basek dest basep enc encc
|
|||
where
|
||||
go pe cks = do
|
||||
let ls = map chunkKeyList cks
|
||||
currsize <- liftIO $ catchMaybeIO $ getFileSize (toRawFilePath dest)
|
||||
currsize <- liftIO $ catchMaybeIO $ getFileSize dest
|
||||
let ls' = maybe ls (setupResume ls) currsize
|
||||
if any null ls'
|
||||
-- dest is already complete
|
||||
|
@ -339,7 +340,7 @@ retrieveChunks retriever u vc chunkconfig encryptor basek dest basep enc encc
|
|||
-- passing the whole file content to the
|
||||
-- incremental verifier though.
|
||||
Nothing -> do
|
||||
retriever (encryptor basek) basep (toRawFilePath dest) iv $
|
||||
retriever (encryptor basek) basep dest iv $
|
||||
retrieved iv Nothing basep
|
||||
return $ case iv of
|
||||
Nothing -> Right iv
|
||||
|
@ -347,13 +348,13 @@ retrieveChunks retriever u vc chunkconfig encryptor basek dest basep enc encc
|
|||
|
||||
opennew = do
|
||||
iv <- startVerifyKeyContentIncrementally vc basek
|
||||
h <- liftIO $ openBinaryFile dest WriteMode
|
||||
h <- liftIO $ F.openBinaryFile dest WriteMode
|
||||
return (h, iv)
|
||||
|
||||
-- Open the file and seek to the start point in order to resume.
|
||||
openresume startpoint = do
|
||||
-- ReadWriteMode allows seeking; AppendMode does not.
|
||||
h <- liftIO $ openBinaryFile dest ReadWriteMode
|
||||
h <- liftIO $ F.openBinaryFile dest ReadWriteMode
|
||||
liftIO $ hSeek h AbsoluteSeek startpoint
|
||||
-- No incremental verification when resuming, since that
|
||||
-- would need to read up to the startpoint.
|
||||
|
@ -398,7 +399,7 @@ retrieveChunks retriever u vc chunkconfig encryptor basek dest basep enc encc
|
|||
-}
|
||||
writeRetrievedContent
|
||||
:: LensEncParams encc
|
||||
=> FilePath
|
||||
=> OsPath
|
||||
-> Maybe (Cipher, EncKey)
|
||||
-> encc
|
||||
-> Maybe Handle
|
||||
|
@ -409,7 +410,7 @@ writeRetrievedContent
|
|||
writeRetrievedContent dest enc encc mh mp content miv = case (enc, mh, content) of
|
||||
(Nothing, Nothing, FileContent f)
|
||||
| f == dest -> noop
|
||||
| otherwise -> liftIO $ moveFile (toRawFilePath f) (toRawFilePath dest)
|
||||
| otherwise -> liftIO $ moveFile f dest
|
||||
(Just (cipher, _), _, ByteContent b) -> do
|
||||
cmd <- gpgCmd <$> Annex.getGitConfig
|
||||
decrypt cmd encc cipher (feedBytes b) $
|
||||
|
@ -419,10 +420,10 @@ writeRetrievedContent dest enc encc mh mp content miv = case (enc, mh, content)
|
|||
withBytes content $ \b ->
|
||||
decrypt cmd encc cipher (feedBytes b) $
|
||||
readBytes write
|
||||
liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
|
||||
liftIO $ removeWhenExistsWith R.removeLink (fromOsPath f)
|
||||
(Nothing, _, FileContent f) -> do
|
||||
withBytes content write
|
||||
liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
|
||||
liftIO $ removeWhenExistsWith R.removeLink (fromOsPath f)
|
||||
(Nothing, _, ByteContent b) -> write b
|
||||
where
|
||||
write b = case mh of
|
||||
|
@ -437,7 +438,7 @@ writeRetrievedContent dest enc encc mh mp content miv = case (enc, mh, content)
|
|||
Nothing -> S.hPut h
|
||||
in meteredWrite p writer b
|
||||
Nothing -> L.hPut h b
|
||||
opendest = openBinaryFile dest WriteMode
|
||||
opendest = F.openBinaryFile dest WriteMode
|
||||
|
||||
{- Can resume when the chunk's offset is at or before the end of
|
||||
- the dest file. -}
|
||||
|
@ -583,4 +584,4 @@ ensureChunksAreLogged _ _ (ChunkKeys _) = return ()
|
|||
|
||||
withBytes :: ContentSource -> (L.ByteString -> Annex a) -> Annex a
|
||||
withBytes (ByteContent b) a = a b
|
||||
withBytes (FileContent f) a = a =<< liftIO (L.readFile f)
|
||||
withBytes (FileContent f) a = a =<< liftIO (L.readFile (fromOsPath f))
|
||||
|
|
|
@ -72,7 +72,7 @@ storeChunks key tmp dest storer recorder finalizer = do
|
|||
when (null stored) $
|
||||
giveup "no chunks were stored"
|
||||
where
|
||||
basef = tmp ++ fromRawFilePath (keyFile key)
|
||||
basef = tmp ++ fromOsPath (keyFile key)
|
||||
tmpdests = map (basef ++ ) chunkStream
|
||||
|
||||
{- Given a list of destinations to use, chunks the data according to the
|
||||
|
|
|
@ -23,15 +23,14 @@ import Data.Time.Clock.POSIX
|
|||
import System.PosixCompat.Files (modificationTime)
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Set as S
|
||||
import qualified System.FilePath.ByteString as P
|
||||
|
||||
repoCheap :: Git.Repo -> Bool
|
||||
repoCheap = not . Git.repoIsUrl
|
||||
|
||||
localpathCalc :: Git.Repo -> Maybe FilePath
|
||||
localpathCalc :: Git.Repo -> Maybe OsPath
|
||||
localpathCalc r
|
||||
| not (Git.repoIsLocal r) && not (Git.repoIsLocalUnknown r) = Nothing
|
||||
| otherwise = Just $ fromRawFilePath $ Git.repoPath r
|
||||
| otherwise = Just $ Git.repoPath r
|
||||
|
||||
{- Checks relatively inexpensively if a repository is available for use. -}
|
||||
repoAvail :: Git.Repo -> Annex Availability
|
||||
|
@ -63,8 +62,11 @@ guardUsable r fallback a
|
|||
gitRepoInfo :: Remote -> Annex [(String, String)]
|
||||
gitRepoInfo r = do
|
||||
d <- fromRepo Git.localGitDir
|
||||
mtimes <- liftIO $ mapM (\p -> modificationTime <$> R.getFileStatus p)
|
||||
=<< emptyWhenDoesNotExist (dirContentsRecursive (d P.</> "refs" P.</> "remotes" P.</> encodeBS (Remote.name r)))
|
||||
let refsdir = d </> literalOsPath "refs"
|
||||
</> literalOsPath "remotes"
|
||||
</> toOsPath (Remote.name r)
|
||||
mtimes <- liftIO $ mapM (\p -> modificationTime <$> R.getFileStatus (fromOsPath p))
|
||||
=<< emptyWhenDoesNotExist (dirContentsRecursive refsdir)
|
||||
let lastsynctime = case mtimes of
|
||||
[] -> "never"
|
||||
_ -> show $ posixSecondsToUTCTime $ realToFrac $ maximum mtimes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue