Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Utils exports encodeArg; use it instead of encodeString

Ignore-this: 5f475c124a0fcf99a800373f1943ee73

darcs-hash:20120420184215-0f649-d529a5ff4a491b41bf0d05503e530b4573e050e8.gz
  • Loading branch information...
commit 96cdafcc8e217b2d0c2d633799d2aa6e6d337829 1 parent 4500c22
@jgm authored
View
5 Data/FileStore/Darcs.hs
@@ -28,8 +28,7 @@ import System.FilePath ((</>), dropFileName, addTrailingPathSeparator)
import Data.FileStore.DarcsXml (parseDarcsXML)
import Data.FileStore.Types
-import Data.FileStore.Utils (withSanityCheck, hashsMatch, runShellCommand, ensureFileExists, grepSearchRepo, withVerifyDir)
-import Codec.Binary.UTF8.String (encodeString)
+import Data.FileStore.Utils (withSanityCheck, hashsMatch, runShellCommand, ensureFileExists, grepSearchRepo, withVerifyDir, encodeArg)
import Data.ByteString.Lazy.UTF8 (toString)
import qualified Data.ByteString.Lazy as B (ByteString, writeFile, null)
@@ -77,7 +76,7 @@ darcsInit repo = do
-- | Save changes (creating the file and directory if needed), add, and commit.
darcsSave :: Contents a => FilePath -> FilePath -> Author -> Description -> a -> IO ()
darcsSave repo name author logMsg contents = do
- withSanityCheck repo ["_darcs"] name $ B.writeFile (repo </> encodeString name) $ toByteString contents
+ withSanityCheck repo ["_darcs"] name $ B.writeFile (repo </> encodeArg name) $ toByteString contents
-- Just in case it hasn't been added yet; we ignore failures since darcs will
-- fail if the file doesn't exist *and* if the file exists but has been added already.
runDarcsCommand repo "add" [name]
View
5 Data/FileStore/Git.hs
@@ -21,11 +21,10 @@ import Data.Maybe (mapMaybe)
import Data.List.Split (endByOneOf)
import System.Exit
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
-import Data.FileStore.Utils (withSanityCheck, hashsMatch, runShellCommand, escapeRegexSpecialChars, withVerifyDir)
+import Data.FileStore.Utils (withSanityCheck, hashsMatch, runShellCommand, escapeRegexSpecialChars, withVerifyDir, encodeArg)
import Data.ByteString.Lazy.UTF8 (toString)
import qualified Data.ByteString.Lazy as B
import qualified Text.ParserCombinators.Parsec as P
-import Codec.Binary.UTF8.String (encodeString)
import Control.Monad (when)
import System.FilePath ((</>))
import System.Directory (createDirectoryIfMissing, doesDirectoryExist, executable, getPermissions, setPermissions)
@@ -97,7 +96,7 @@ gitCommit repo names author logMsg = do
-- | Save changes (creating file and directory if needed), add, and commit.
gitSave :: Contents a => FilePath -> FilePath -> Author -> Description -> a -> IO ()
gitSave repo name author logMsg contents = do
- withSanityCheck repo [".git"] name $ B.writeFile (repo </> encodeString name) $ toByteString contents
+ withSanityCheck repo [".git"] name $ B.writeFile (repo </> encodeArg name) $ toByteString contents
(statusAdd, errAdd, _) <- runGitCommand repo "add" [name]
if statusAdd == ExitSuccess
then gitCommit repo [name] author logMsg
View
5 Data/FileStore/Mercurial.hs
@@ -19,12 +19,11 @@ where
import Data.FileStore.Types
import Data.Maybe (fromJust)
import System.Exit
-import Data.FileStore.Utils (withSanityCheck, hashsMatch, withVerifyDir, grepSearchRepo)
+import Data.FileStore.Utils (withSanityCheck, hashsMatch, withVerifyDir, grepSearchRepo, encodeArg)
import Data.FileStore.MercurialCommandServer
import Data.ByteString.Lazy.UTF8 (toString)
import qualified Data.ByteString.Lazy as B
import qualified Text.ParserCombinators.Parsec as P
-import Codec.Binary.UTF8.String (encodeString)
import Data.List (nub)
import Control.Monad (when, liftM, unless)
import System.FilePath ((</>), splitDirectories, takeFileName)
@@ -84,7 +83,7 @@ mercurialCommit repo names author logMsg = do
-- | Save changes (creating file and directory if needed), add, and commit.
mercurialSave :: Contents a => FilePath -> FilePath -> Author -> Description -> a -> IO ()
mercurialSave repo name author logMsg contents = do
- withSanityCheck repo [".hg"] name $ B.writeFile (repo </> encodeString name) $ toByteString contents
+ withSanityCheck repo [".hg"] name $ B.writeFile (repo </> encodeArg name) $ toByteString contents
(statusAdd, errAdd, _) <- runMercurialCommand repo "add" ["path:" ++ name]
if statusAdd == ExitSuccess
then mercurialCommit repo [name] author logMsg
View
1  Data/FileStore/Sqlite3.hs
@@ -24,7 +24,6 @@ import Data.FileStore.Utils (hashsMatch, isInsideRepo, runShellCommand)
import Data.ByteString.Lazy.UTF8 (toString)
import qualified Data.ByteString.Lazy as B
import qualified Text.ParserCombinators.Parsec as P
-import Codec.Binary.UTF8.String (encodeString)
import Data.Char (chr)
import Control.Monad (liftM, unless, when)
import System.FilePath ((</>), takeDirectory)
View
15 Data/FileStore/Utils.hs
@@ -22,7 +22,8 @@ module Data.FileStore.Utils (
, regsSearchFile
, withSanityCheck
, grepSearchRepo
- , withVerifyDir ) where
+ , withVerifyDir
+ , encodeArg ) where
import Codec.Binary.UTF8.String (encodeString)
import Control.Exception (throwIO)
@@ -42,6 +43,10 @@ import qualified Data.ByteString as S
import Data.FileStore.Types (SearchMatch(..), FileStoreError(IllegalResourceName, NotFound, UnknownError), SearchQuery(..))
+-- | Encode argument for raw command.
+encodeArg :: String -> String
+encodeArg = encodeString
+
-- | Run shell command and return error status, standard output, and error output. Assumes
-- UTF-8 locale. Note that this does not actually go through \/bin\/sh!
runShellCommand :: FilePath -- ^ Working directory
@@ -53,7 +58,7 @@ runShellCommand workingDir environment command optionList = do
tempPath <- catch getTemporaryDirectory (\_ -> return ".")
(outputPath, hOut) <- openTempFile tempPath "out"
(errorPath, hErr) <- openTempFile tempPath "err"
- hProcess <- runProcess (encodeString command) (map encodeString optionList) (Just workingDir) environment Nothing (Just hOut) (Just hErr)
+ hProcess <- runProcess (encodeArg command) (map encodeArg optionList) (Just workingDir) environment Nothing (Just hOut) (Just hErr)
status <- waitForProcess hProcess
errorOutput <- S.readFile errorPath
output <- S.readFile outputPath
@@ -174,7 +179,7 @@ regsSearchFile os repo patterns file = do res <- mapM (run file) patterns
-- | If name doesn't exist in repo or is not a file, throw 'NotFound' exception.
ensureFileExists :: FilePath -> FilePath -> IO ()
ensureFileExists repo name = do
- isFile <- doesFileExist (repo </> encodeString name)
+ isFile <- doesFileExist (repo </> encodeArg name)
unless isFile $ throwIO NotFound
-- | Check that the filename/location is within the given repo, and not inside
@@ -186,7 +191,7 @@ withSanityCheck :: FilePath
-> IO b
-> IO b
withSanityCheck repo excludes name action = do
- let filename = repo </> encodeString name
+ let filename = repo </> encodeArg name
let insideRepo = filename `isInsideDir` repo
let insideExcludes = or $ map (filename `isInsideDir`)
$ map (repo </>) excludes
@@ -222,7 +227,7 @@ grepSearchRepo indexer repo query = do
-- | we don't actually need the contents, just want to check that the directory exists and we have enough permissions
withVerifyDir :: FilePath -> IO a -> IO a
withVerifyDir d a =
- catch (liftM head (getDirectoryContents $ encodeString d) >> a) $ \e ->
+ catch (liftM head (getDirectoryContents $ encodeArg d) >> a) $ \e ->
if "No such file or directory" `isInfixOf` show e
then throwIO NotFound
else throwIO . UnknownError . show $ e
Please sign in to comment.
Something went wrong with that request. Please try again.