mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-03-20 15:14:54 +09:00
96 lines
3.2 KiB
Haskell
96 lines
3.2 KiB
Haskell
{- This file is part of Vervis.
|
|
-
|
|
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
|
-
|
|
- ♡ Copying is an act of love. Please copy, reuse and share.
|
|
-
|
|
- The author(s) have dedicated all copyright and related and neighboring
|
|
- rights to this software to the public domain worldwide. This software is
|
|
- distributed without any warranty.
|
|
-
|
|
- You should have received a copy of the CC0 Public Domain Dedication along
|
|
- with this software. If not, see
|
|
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
-}
|
|
|
|
module Darcs.Local.Inventory.Read
|
|
( readLatestInventory
|
|
, readCompressedInventory
|
|
)
|
|
where
|
|
|
|
import Prelude
|
|
|
|
import Codec.Compression.Zlib.Internal
|
|
import Control.Applicative (many, optional, liftA2)
|
|
import Control.Arrow (second)
|
|
import Control.Monad (replicateM_)
|
|
import Crypto.Hash
|
|
import Data.Attoparsec.ByteString
|
|
import Data.ByteArray (convert)
|
|
import Data.ByteString (ByteString)
|
|
import Data.Time.Calendar (fromGregorianValid)
|
|
import Data.Time.Clock (UTCTime (..), secondsToDiffTime)
|
|
import Data.Word (Word8)
|
|
import System.FilePath ((</>))
|
|
|
|
import qualified Data.ByteString as B
|
|
import qualified Data.ByteString.Char8 as BC
|
|
import qualified Data.ByteString.Base16 as B16
|
|
import qualified Data.ByteString.Lex.Integral as BX
|
|
|
|
import Control.Applicative.Local
|
|
import Darcs.Local.Hash.Codec
|
|
import Darcs.Local.Hash.Types
|
|
import Darcs.Local.Inventory.Parser
|
|
import Darcs.Local.Inventory.Types
|
|
import Data.Attoparsec.ByteString.Local
|
|
import Data.ByteString.Local (stripPrefix)
|
|
import Data.Text.UTF8.Local (decodeStrict)
|
|
|
|
darcsDir :: FilePath
|
|
darcsDir = "_darcs"
|
|
|
|
inventoryDir :: FilePath
|
|
inventoryDir = "inventories"
|
|
|
|
inventoryFile :: FilePath
|
|
inventoryFile = "hashed_inventory"
|
|
|
|
readLatestInventory :: FilePath -> Parser a -> IO (Either String a)
|
|
readLatestInventory repo =
|
|
parseFileIncremental $ repo </> darcsDir </> inventoryFile
|
|
|
|
readCompressedInventory
|
|
:: FilePath -> InventoryHash -> Parser a -> IO (Either String a)
|
|
readCompressedInventory repo ih =
|
|
let invFile = BC.unpack $ encodeInventoryHash ih
|
|
invPath = repo </> darcsDir </> inventoryDir </> invFile
|
|
defParams = defaultDecompressParams
|
|
bufSize = min (decompressBufferSize defParams) (ihSize ih)
|
|
params = defParams { decompressBufferSize = bufSize }
|
|
in parseCompressedFileIncremental gzipFormat params invPath
|
|
|
|
{-
|
|
readLatestInventorySize :: FilePath -> IO (Either String Int)
|
|
|
|
readLatestInventoryAll :: FilePath -> IO (Either String LatestInventory)
|
|
|
|
readLatestInventoryPage
|
|
:: Int -> Int -> FilePath -> IO (Either String LatestInventory)
|
|
|
|
readInventorySize :: FilePath -> IO (Either String Int)
|
|
readInventorySize repoPath = do
|
|
let invPath = repoPath </> darcsDir </> inventoryFile
|
|
parseFileIncremental invPath $ patchInfosCountP <* endOfInput
|
|
|
|
readPatchInfoAll :: FilePath -> IO (Either String PatchSeq)
|
|
readPatchInfoAll repoPath = do
|
|
let invPath = repoPath </> darcsDir </> inventoryFile
|
|
parseFileIncremental invPath $ patchInfosAllP <* endOfInput
|
|
|
|
readPatchInfoPage :: Int -> Int -> FilePath -> IO (Either String PatchSeq)
|
|
readPatchInfoPage off lim repoPath = do
|
|
let invPath = repoPath </> darcsDir </> inventoryFile
|
|
parseFileIncremental invPath $ patchInfosOffsetLimitP off lim
|
|
-}
|