diff --git a/Annex/Content.hs b/Annex/Content.hs index 5a7a89ff10..3f26c0f0a8 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -108,6 +108,7 @@ import Utility.HumanTime import Utility.TimeStamp import Utility.FileMode import qualified Utility.RawFilePath as R +import qualified Utility.FileIO as F import qualified System.FilePath.ByteString as P import System.PosixCompat.Files (isSymbolicLink, linkCount) @@ -1086,7 +1087,7 @@ writeContentRetentionTimestamp key rt t = do readContentRetentionTimestamp :: RawFilePath -> Annex (Maybe POSIXTime) readContentRetentionTimestamp rt = liftIO $ join <$> tryWhenExists - (parsePOSIXTime <$> readFile (fromRawFilePath rt)) + (parsePOSIXTime <$> F.readFile' (toOsPath rt)) {- Checks if the retention timestamp is in the future, if so returns - Nothing. diff --git a/Annex/VectorClock.hs b/Annex/VectorClock.hs index db2c63c0bd..792f6e6e82 100644 --- a/Annex/VectorClock.hs +++ b/Annex/VectorClock.hs @@ -21,6 +21,7 @@ import qualified Annex import Utility.TimeStamp import Data.ByteString.Builder +import qualified Data.ByteString as B import qualified Data.Attoparsec.ByteString.Lazy as A currentVectorClock :: Annex CandidateVectorClock @@ -76,7 +77,7 @@ formatVectorClock (VectorClock t) = show t buildVectorClock :: VectorClock -> Builder buildVectorClock = string7 . formatVectorClock -parseVectorClock :: String -> Maybe VectorClock +parseVectorClock :: B.ByteString -> Maybe VectorClock parseVectorClock t = VectorClock <$> parsePOSIXTime t vectorClockParser :: A.Parser VectorClock diff --git a/Annex/VectorClock/Utility.hs b/Annex/VectorClock/Utility.hs index 76b74d9cd5..2c9f40f16e 100644 --- a/Annex/VectorClock/Utility.hs +++ b/Annex/VectorClock/Utility.hs @@ -12,12 +12,13 @@ import Data.Time.Clock.POSIX import Types.VectorClock import Utility.Env import Utility.TimeStamp +import Utility.FileSystemEncoding startVectorClock :: IO (IO CandidateVectorClock) startVectorClock = go =<< getEnv "GIT_ANNEX_VECTOR_CLOCK" where go Nothing = timebased - go (Just s) = case parsePOSIXTime s of + go (Just s) = case parsePOSIXTime (encodeBS s) of Just t -> return (pure (CandidateVectorClock t)) Nothing -> timebased -- Avoid using fractional seconds in the CandidateVectorClock. diff --git a/Assistant/DaemonStatus.hs b/Assistant/DaemonStatus.hs index dde5010f8c..eeb40605ea 100644 --- a/Assistant/DaemonStatus.hs +++ b/Assistant/DaemonStatus.hs @@ -136,13 +136,13 @@ readDaemonStatusFile file = parse <$> newDaemonStatus <*> readFile file where parse status = foldr parseline status . lines parseline line status - | key == "lastRunning" = parseval parsePOSIXTime $ \v -> + | key == "lastRunning" = parseval (parsePOSIXTime . encodeBS) $ \v -> status { lastRunning = Just v } | key == "scanComplete" = parseval readish $ \v -> status { scanComplete = v } | key == "sanityCheckRunning" = parseval readish $ \v -> status { sanityCheckRunning = v } - | key == "lastSanityCheck" = parseval parsePOSIXTime $ \v -> + | key == "lastSanityCheck" = parseval (parsePOSIXTime . encodeBS) $ \v -> status { lastSanityCheck = Just v } | otherwise = status -- unparsable line where diff --git a/Command/Fsck.hs b/Command/Fsck.hs index 5924b4d11e..f0f833117d 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -702,7 +702,7 @@ getStartTime u = do liftIO $ catchDefaultIO Nothing $ do timestamp <- modificationTime <$> R.getFileStatus f let fromstatus = Just (realToFrac timestamp) - fromfile <- parsePOSIXTime <$> readFile (fromRawFilePath f) + fromfile <- parsePOSIXTime <$> F.readFile' (toOsPath f) return $ if matchingtimestamp fromfile fromstatus then Just timestamp else Nothing diff --git a/Git/LsFiles.hs b/Git/LsFiles.hs index 4eea39541a..08c98b7fda 100644 --- a/Git/LsFiles.hs +++ b/Git/LsFiles.hs @@ -373,4 +373,4 @@ inodeCaches locs repo = guardSafeForLsFiles repo $ do mkInodeCache <$> (readish =<< M.lookup "ino:" m) <*> (readish =<< M.lookup "size:" m) - <*> (parsePOSIXTime =<< (replace ":" "." <$> M.lookup "mtime:" m)) + <*> (parsePOSIXTime =<< (encodeBS . replace ":" "." <$> M.lookup "mtime:" m)) diff --git a/Logs/AdjustedBranchUpdate.hs b/Logs/AdjustedBranchUpdate.hs index c7f2822945..5b2ea9648a 100644 --- a/Logs/AdjustedBranchUpdate.hs +++ b/Logs/AdjustedBranchUpdate.hs @@ -80,5 +80,5 @@ parseAdjustLog l = "1" -> Just True "0" -> Just False _ -> Nothing - t <- parsePOSIXTime ts + t <- parsePOSIXTime (encodeBS ts) return (b, t) diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs index 098ecb9465..6ddd9350b2 100644 --- a/Logs/Transfer.hs +++ b/Logs/Transfer.hs @@ -320,7 +320,7 @@ readTransferInfo mpid s = TransferInfo bits = splitc ' ' firstline numbits = length bits time = if numbits > 0 - then Just <$> parsePOSIXTime =<< headMaybe bits + then Just <$> parsePOSIXTime . encodeBS =<< headMaybe bits else pure Nothing -- not failure bytes = if numbits > 1 then Just <$> readish =<< headMaybe (drop 1 bits) diff --git a/Logs/Unused.hs b/Logs/Unused.hs index 5e8416a605..fa2b2ce3cc 100644 --- a/Logs/Unused.hs +++ b/Logs/Unused.hs @@ -81,7 +81,7 @@ readUnusedLog prefix = do , return M.empty ) where - parse line = case (readish sint, deserializeKey skey, parsePOSIXTime ts) of + parse line = case (readish sint, deserializeKey skey, parsePOSIXTime (encodeBS ts)) of (Just int, Just key, mtimestamp) -> Just (key, (int, mtimestamp)) _ -> Nothing where diff --git a/Logs/Upgrade.hs b/Logs/Upgrade.hs index bdc4f40d90..bc63e0021f 100644 --- a/Logs/Upgrade.hs +++ b/Logs/Upgrade.hs @@ -39,7 +39,7 @@ readUpgradeLog = do , return [] ) where - parse line = case (readish sint, parsePOSIXTime ts) of + parse line = case (readish sint, parsePOSIXTime (encodeBS ts)) of (Just v, Just t) -> Just (RepoVersion v, t) _ -> Nothing where diff --git a/Utility/InodeCache.hs b/Utility/InodeCache.hs index 3828bc645a..6f8008dd5f 100644 --- a/Utility/InodeCache.hs +++ b/Utility/InodeCache.hs @@ -185,7 +185,7 @@ readInodeCache s = case words s of (inode:size:mtime:mtimedecimal:_) -> do i <- readish inode sz <- readish size - t <- parsePOSIXTime $ mtime ++ '.' : mtimedecimal + t <- parsePOSIXTime $ encodeBS $ mtime ++ '.' : mtimedecimal return $ InodeCache $ InodeCachePrim i sz (MTimeHighRes t) _ -> Nothing diff --git a/Utility/TimeStamp.hs b/Utility/TimeStamp.hs index 878d6f7299..1175034e91 100644 --- a/Utility/TimeStamp.hs +++ b/Utility/TimeStamp.hs @@ -19,7 +19,6 @@ import Data.Time import Data.Ratio import Control.Applicative import qualified Data.ByteString as B -import qualified Data.ByteString.Char8 as B8 import qualified Data.Attoparsec.ByteString as A import Data.Attoparsec.ByteString.Char8 (char, decimal, signed, isDigit_w8) @@ -41,9 +40,9 @@ parserPOSIXTime = mkPOSIXTime A.parseOnly (decimal <* A.endOfInput) b return (d, len) -parsePOSIXTime :: String -> Maybe POSIXTime -parsePOSIXTime s = eitherToMaybe $ - A.parseOnly (parserPOSIXTime <* A.endOfInput) (B8.pack s) +parsePOSIXTime :: B.ByteString -> Maybe POSIXTime +parsePOSIXTime b = eitherToMaybe $ + A.parseOnly (parserPOSIXTime <* A.endOfInput) b {- This implementation allows for higher precision in a POSIXTime than - supported by the system's Double, and avoids the complications of diff --git a/doc/todo/RawFilePath_conversion.mdwn b/doc/todo/RawFilePath_conversion.mdwn index 6d08e95efd..a452c41dca 100644 --- a/doc/todo/RawFilePath_conversion.mdwn +++ b/doc/todo/RawFilePath_conversion.mdwn @@ -21,6 +21,10 @@ status. readFile, writeFile, and appendFile on FilePaths. Note that the FilePath versions do newline translation on windows, which has to be handled when converting to the Utility.FileIO ones. +* System.Directory.OsPath is available with OsPath build flag, but + not yet used, and would eliminate a lot of fromRawFilePaths. + Make Utility.SystemDirectory import it when built with OsPath, + and the remaining 6 hours or work will explain itself.. [[!tag confirmed]]