filestore 0.4.0.3 → 0.4.0.4
raw patch · 4 files changed
+26/−7 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/FileStore/Darcs.hs +11/−3
- Data/FileStore/Utils.hs +4/−3
- Tests.lhs +10/−0
- filestore.cabal +1/−1
Data/FileStore/Darcs.hs view
@@ -32,7 +32,7 @@ import Codec.Binary.UTF8.String (encodeString) import Data.ByteString.Lazy.UTF8 (toString)-import qualified Data.ByteString.Lazy as B (ByteString, writeFile)+import qualified Data.ByteString.Lazy as B (ByteString, writeFile, null) -- | Return a filestore implemented using the Darcs distributed revision control system -- (<http://darcs.net/>).@@ -170,21 +170,29 @@ -> Maybe RevisionId -- ^ @Just@ revision ID, or @Nothing@ for latest -> IO a darcsRetrieve repo name mbId = do- ensureFileExists repo name let opts = case mbId of Nothing -> ["contents", name] Just revid -> ["contents", "--match=hash " ++ revid, name] (status, err, output) <- runDarcsCommand repo "query" opts+ if B.null output+ then do+ (_, _, out) <- runDarcsCommand repo "query" (["files", "--no-directories"] ++ opts)+ if B.null out || null (filter (== name) . getNames $ output)+ then throwIO NotFound else return ()+ else return () if status == ExitSuccess then return $ fromByteString output else throwIO $ UnknownError $ "Error in darcs query contents:\n" ++ err+ +getNames :: B.ByteString -> [String]+getNames = map (drop 2) . lines . toString -- | Get a list of all known files inside and managed by a repository. darcsIndex :: FilePath ->IO [FilePath] darcsIndex repo = withVerifyDir repo $ do (status, _errOutput, output) <- runDarcsCommand repo "query" ["files","--no-directories"] if status == ExitSuccess- then return $ map (drop 2) . lines . toString $ output+ then return . getNames $ output else return [] -- return empty list if invalid path (see gitIndex) -- | Get a list of all resources inside a directory in the repository.
Data/FileStore/Utils.hs view
@@ -38,6 +38,7 @@ import System.IO (openTempFile, hClose) import System.Process (runProcess, waitForProcess) import qualified Data.ByteString.Lazy as B+import qualified Data.ByteString as S import Data.FileStore.Types (SearchMatch(..), FileStoreError(IllegalResourceName, NotFound, UnknownError), SearchQuery(..)) @@ -54,11 +55,11 @@ (errorPath, hErr) <- openTempFile tempPath "err" hProcess <- runProcess (encodeString command) (map encodeString optionList) (Just workingDir) environment Nothing (Just hOut) (Just hErr) status <- waitForProcess hProcess- errorOutput <- B.readFile errorPath- output <- B.readFile outputPath+ errorOutput <- S.readFile errorPath+ output <- S.readFile outputPath removeFile errorPath removeFile outputPath- return (status, errorOutput, output)+ return (status, B.fromChunks [errorOutput], B.fromChunks [output]) -- | Do a three way merge, using either git merge-file or RCS merge. Assumes -- that either @git@ or @merge@ is in the system path. Assumes UTF-8 locale.
Tests.lhs view
@@ -46,6 +46,7 @@ > , ("retrieve subdirectory (should raise error)", retrieveTest4) > , ("modify resource", modifyTest) > , ("delete resource", deleteTest fsName)+> , ("retrieve deleted file", retrieveTest5) > , ("rename resource", renameTest) > , ("test for matching IDs", matchTest) > , ("history and revision", historyTest)@@ -261,6 +262,15 @@ > catch (delete fs special testAuthor "description of change" >> > (assertFailure $ "did not return error from delete " ++ special)) $ > \e -> assertEqual ("error from delete " ++ special) IllegalResourceName e ++*** Retrieve earlier version of deleted file:++> retrieveTest5 fs = TestCase $ do+> hist <- history fs ["Aaack!"] (TimeRange Nothing Nothing)+> assertBool "history is nonempty" (not (null hist))+> let deletedId = revId $ last hist+> contents <- retrieve fs "Aaack!" (Just deletedId) :: IO String+> assertEqual "contents returned by retrieve" testContents contents *** Rename a resource:
filestore.cabal view
@@ -1,5 +1,5 @@ Name: filestore-Version: 0.4.0.3+Version: 0.4.0.4 Cabal-version: >= 1.2 Build-type: Custom Tested-with: GHC==6.10.1