Merge branch 'bs' into sqlite-bs
This commit is contained in:
commit
d5628a16b8
137 changed files with 827 additions and 516 deletions
|
@ -23,10 +23,6 @@ module Utility.FileSystemEncoding (
|
|||
encodeBL',
|
||||
decodeBS',
|
||||
encodeBS',
|
||||
decodeW8,
|
||||
encodeW8,
|
||||
encodeW8NUL,
|
||||
decodeW8NUL,
|
||||
truncateFilePath,
|
||||
s2w8,
|
||||
w82s,
|
||||
|
@ -47,6 +43,7 @@ import qualified Data.ByteString.Lazy as L
|
|||
import qualified Data.ByteString.UTF8 as S8
|
||||
import qualified Data.ByteString.Lazy.UTF8 as L8
|
||||
#endif
|
||||
import System.FilePath.ByteString (RawFilePath, encodeFilePath, decodeFilePath)
|
||||
|
||||
import Utility.Exception
|
||||
import Utility.Split
|
||||
|
@ -148,32 +145,38 @@ encodeBS = S8.fromString
|
|||
{- Faster version that assumes the string does not contain NUL;
|
||||
- if it does it will be truncated before the NUL. -}
|
||||
decodeBS' :: S.ByteString -> FilePath
|
||||
#ifndef mingw32_HOST_OS
|
||||
decodeBS' = encodeW8 . S.unpack
|
||||
#else
|
||||
decodeBS' = S8.toString
|
||||
#endif
|
||||
|
||||
encodeBS' :: FilePath -> S.ByteString
|
||||
#ifndef mingw32_HOST_OS
|
||||
encodeBS' = S.pack . decodeW8
|
||||
#else
|
||||
encodeBS' = S8.fromString
|
||||
#endif
|
||||
|
||||
decodeBL' :: L.ByteString -> FilePath
|
||||
#ifndef mingw32_HOST_OS
|
||||
decodeBL' = encodeW8 . L.unpack
|
||||
#else
|
||||
decodeBL' = L8.toString
|
||||
#endif
|
||||
|
||||
encodeBL' :: FilePath -> L.ByteString
|
||||
#ifndef mingw32_HOST_OS
|
||||
encodeBL' = L.pack . decodeW8
|
||||
#else
|
||||
encodeBL' = L8.fromString
|
||||
#endif
|
||||
|
||||
{- Recent versions of the unix package have this alias; defined here
|
||||
- for backwards compatibility. -}
|
||||
type RawFilePath = S.ByteString
|
||||
|
||||
{- Note that the RawFilePath is assumed to never contain NUL,
|
||||
- since filename's don't. This should only be used with actual
|
||||
- RawFilePaths not arbitrary ByteString that may contain NUL. -}
|
||||
fromRawFilePath :: RawFilePath -> FilePath
|
||||
fromRawFilePath = decodeBS'
|
||||
fromRawFilePath = decodeFilePath
|
||||
|
||||
{- Note that the FilePath is assumed to never contain NUL,
|
||||
- since filename's don't. This should only be used with actual FilePaths
|
||||
- not arbitrary String that may contain NUL. -}
|
||||
toRawFilePath :: FilePath -> RawFilePath
|
||||
toRawFilePath = encodeBS'
|
||||
toRawFilePath = encodeFilePath
|
||||
|
||||
{- Converts a [Word8] to a FilePath, encoding using the filesystem encoding.
|
||||
-
|
||||
|
|
|
@ -23,7 +23,6 @@ module Utility.InodeCache (
|
|||
readInodeCache,
|
||||
showInodeCache,
|
||||
genInodeCache,
|
||||
genInodeCache',
|
||||
toInodeCache,
|
||||
|
||||
InodeCacheKey,
|
||||
|
@ -185,12 +184,8 @@ readInodeCache s = case words s of
|
|||
return $ InodeCache $ InodeCachePrim i sz (MTimeHighRes t)
|
||||
_ -> Nothing
|
||||
|
||||
genInodeCache :: FilePath -> TSDelta -> IO (Maybe InodeCache)
|
||||
genInodeCache :: RawFilePath -> TSDelta -> IO (Maybe InodeCache)
|
||||
genInodeCache f delta = catchDefaultIO Nothing $
|
||||
toInodeCache delta f =<< getFileStatus f
|
||||
|
||||
genInodeCache' :: RawFilePath -> TSDelta -> IO (Maybe InodeCache)
|
||||
genInodeCache' f delta = catchDefaultIO Nothing $
|
||||
toInodeCache delta (fromRawFilePath f) =<< R.getFileStatus f
|
||||
|
||||
toInodeCache :: TSDelta -> FilePath -> FileStatus -> IO (Maybe InodeCache)
|
||||
|
@ -211,8 +206,8 @@ toInodeCache (TSDelta getdelta) f s
|
|||
- Its InodeCache at the time of its creation is written to the cache file,
|
||||
- so changes can later be detected. -}
|
||||
data SentinalFile = SentinalFile
|
||||
{ sentinalFile :: FilePath
|
||||
, sentinalCacheFile :: FilePath
|
||||
{ sentinalFile :: RawFilePath
|
||||
, sentinalCacheFile :: RawFilePath
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
|
@ -229,8 +224,8 @@ noTSDelta = TSDelta (pure 0)
|
|||
|
||||
writeSentinalFile :: SentinalFile -> IO ()
|
||||
writeSentinalFile s = do
|
||||
writeFile (sentinalFile s) ""
|
||||
maybe noop (writeFile (sentinalCacheFile s) . showInodeCache)
|
||||
writeFile (fromRawFilePath (sentinalFile s)) ""
|
||||
maybe noop (writeFile (fromRawFilePath (sentinalCacheFile s)) . showInodeCache)
|
||||
=<< genInodeCache (sentinalFile s) noTSDelta
|
||||
|
||||
data SentinalStatus = SentinalStatus
|
||||
|
@ -259,7 +254,7 @@ checkSentinalFile s = do
|
|||
Just new -> return $ calc old new
|
||||
where
|
||||
loadoldcache = catchDefaultIO Nothing $
|
||||
readInodeCache <$> readFile (sentinalCacheFile s)
|
||||
readInodeCache <$> readFile (fromRawFilePath (sentinalCacheFile s))
|
||||
gennewcache = genInodeCache (sentinalFile s) noTSDelta
|
||||
calc (InodeCache (InodeCachePrim oldinode oldsize oldmtime)) (InodeCache (InodeCachePrim newinode newsize newmtime)) =
|
||||
SentinalStatus (not unchanged) tsdelta
|
||||
|
@ -284,7 +279,7 @@ checkSentinalFile s = do
|
|||
dummy = SentinalStatus True noTSDelta
|
||||
|
||||
sentinalFileExists :: SentinalFile -> IO Bool
|
||||
sentinalFileExists s = allM doesFileExist [sentinalCacheFile s, sentinalFile s]
|
||||
sentinalFileExists s = allM R.doesPathExist [sentinalCacheFile s, sentinalFile s]
|
||||
|
||||
instance Arbitrary InodeCache where
|
||||
arbitrary =
|
||||
|
|
|
@ -8,13 +8,14 @@ module Utility.MD5 where
|
|||
|
||||
import Data.Bits
|
||||
import Data.Word
|
||||
import Data.Char
|
||||
|
||||
display_32bits_as_dir :: Word32 -> String
|
||||
display_32bits_as_dir :: Word32 -> [Word8]
|
||||
display_32bits_as_dir w = trim $ swap_pairs cs
|
||||
where
|
||||
-- Need 32 characters to use. To avoid inaverdently making
|
||||
-- a real word, use letters that appear less frequently.
|
||||
chars = ['0'..'9'] ++ "zqjxkmvwgpfZQJXKMVWGPF"
|
||||
chars = map (fromIntegral . ord) (['0'..'9'] ++ "zqjxkmvwgpfZQJXKMVWGPF")
|
||||
cs = map (\x -> getc $ (shiftR w (6*x)) .&. 31) [0..7]
|
||||
getc n = chars !! fromIntegral n
|
||||
swap_pairs (x1:x2:xs) = x2:x1:swap_pairs xs
|
||||
|
|
|
@ -258,7 +258,7 @@ commandMeter' progressparser oh meterupdate cmd params =
|
|||
unless (quietMode oh) $ do
|
||||
S.hPut stdout b
|
||||
hFlush stdout
|
||||
let s = encodeW8 (S.unpack b)
|
||||
let s = decodeBS b
|
||||
let (mbytes, buf') = progressparser (buf++s)
|
||||
case mbytes of
|
||||
Nothing -> feedprogress prev buf' h
|
||||
|
|
|
@ -18,14 +18,21 @@ module Utility.RawFilePath (
|
|||
RawFilePath,
|
||||
readSymbolicLink,
|
||||
getFileStatus,
|
||||
getSymbolicLinkStatus,
|
||||
doesPathExist,
|
||||
) where
|
||||
|
||||
#ifndef mingw32_HOST_OS
|
||||
import Utility.FileSystemEncoding (RawFilePath)
|
||||
import System.Posix.Files.ByteString
|
||||
|
||||
doesPathExist :: RawFilePath -> IO Bool
|
||||
doesPathExist = fileExist
|
||||
|
||||
#else
|
||||
import qualified Data.ByteString as B
|
||||
import qualified System.PosixCompat as P
|
||||
import qualified System.Directory as D
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
readSymbolicLink :: RawFilePath -> IO RawFilePath
|
||||
|
@ -33,4 +40,10 @@ readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f)
|
|||
|
||||
getFileStatus :: RawFilePath -> IO FileStatus
|
||||
getFileStatus = P.getFileStatus . fromRawFilePath
|
||||
|
||||
getSymbolicLinkStatus :: RawFilePath -> IO FileStatus
|
||||
getSymbolicLinkStatus = P.getSymbolicLinkStatus . fromRawFilePath
|
||||
|
||||
doesPathExist :: RawFilePath -> IO Bool
|
||||
doesPathExist = D.doesPathExist . fromRawFilePath
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue