Support filenames that start with a dash; when such a file is passed to a utility it will be escaped to avoid it being interpreted as an option.
This commit is contained in:
parent
e61b47bc8a
commit
836e71297b
9 changed files with 29 additions and 10 deletions
|
@ -20,6 +20,7 @@ import qualified Annex
|
||||||
import Locations
|
import Locations
|
||||||
import Content
|
import Content
|
||||||
import Types
|
import Types
|
||||||
|
import Utility
|
||||||
|
|
||||||
backend :: Backend Annex
|
backend :: Backend Annex
|
||||||
backend = Backend.File.backend {
|
backend = Backend.File.backend {
|
||||||
|
@ -31,7 +32,7 @@ backend = Backend.File.backend {
|
||||||
sha1 :: FilePath -> Annex String
|
sha1 :: FilePath -> Annex String
|
||||||
sha1 file = do
|
sha1 file = do
|
||||||
showNote "checksum..."
|
showNote "checksum..."
|
||||||
liftIO $ pOpen ReadFromPipe "sha1sum" [file] $ \h -> do
|
liftIO $ pOpen ReadFromPipe "sha1sum" [utilityEscape file] $ \h -> do
|
||||||
line <- hGetLine h
|
line <- hGetLine h
|
||||||
let bits = split " " line
|
let bits = split " " line
|
||||||
if null bits
|
if null bits
|
||||||
|
|
|
@ -51,6 +51,6 @@ downloadUrl :: Key -> FilePath -> Annex Bool
|
||||||
downloadUrl key file = do
|
downloadUrl key file = do
|
||||||
showNote "downloading"
|
showNote "downloading"
|
||||||
showProgress -- make way for curl progress bar
|
showProgress -- make way for curl progress bar
|
||||||
liftIO $ boolSystem "curl" ["-#", "-o", file, url]
|
liftIO $ boolSystem "curl" ["-#", "-o", utilityEscape file, url]
|
||||||
where
|
where
|
||||||
url = join ":" $ drop 1 $ split ":" $ show key
|
url = join ":" $ drop 1 $ split ":" $ show key
|
||||||
|
|
|
@ -35,7 +35,8 @@ perform file = do
|
||||||
-- rather than simply calling moveToObjectDir
|
-- rather than simply calling moveToObjectDir
|
||||||
ok <- getViaTmp key $ \dest -> do
|
ok <- getViaTmp key $ \dest -> do
|
||||||
if dest /= file
|
if dest /= file
|
||||||
then liftIO $ boolSystem "mv" [file, dest]
|
then liftIO $
|
||||||
|
boolSystem "mv" [utilityEscape file, utilityEscape dest]
|
||||||
else return True
|
else return True
|
||||||
if ok
|
if ok
|
||||||
then return $ Just $ cleanup
|
then return $ Just $ cleanup
|
||||||
|
|
10
CopyFile.hs
10
CopyFile.hs
|
@ -23,9 +23,11 @@ copyFile src dest = do
|
||||||
boolSystem "cp" opts
|
boolSystem "cp" opts
|
||||||
where
|
where
|
||||||
opts = if SysConfig.cp_reflink_auto
|
opts = if SysConfig.cp_reflink_auto
|
||||||
then ["--reflink=auto", src, dest]
|
then ["--reflink=auto", src', dest']
|
||||||
else if SysConfig.cp_a
|
else if SysConfig.cp_a
|
||||||
then ["-a", src, dest]
|
then ["-a", src', dest']
|
||||||
else if SysConfig.cp_p
|
else if SysConfig.cp_p
|
||||||
then ["-p", src, dest]
|
then ["-p", src', dest']
|
||||||
else [src, dest]
|
else [src', dest']
|
||||||
|
src' = utilityEscape src
|
||||||
|
dest' = utilityEscape dest
|
||||||
|
|
|
@ -282,7 +282,7 @@ rsyncParams r sending key file = do
|
||||||
-- inplace makes rsync resume partial files
|
-- inplace makes rsync resume partial files
|
||||||
options = ["-p", "--progress", "--inplace"]
|
options = ["-p", "--progress", "--inplace"]
|
||||||
-- the rsync shell parameter controls where rsync
|
-- the rsync shell parameter controls where rsync
|
||||||
-- does, so the source/dest parameter can be a dummy value,
|
-- goes, so the source/dest parameter can be a dummy value,
|
||||||
-- that just enables remote rsync mode.
|
-- that just enables remote rsync mode.
|
||||||
dummy = ":"
|
dummy = ":"
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,12 @@ rsyncShell command = ["-e", unwords $ map escape command]
|
||||||
|
|
||||||
{- Runs rsync in server mode to send a file, and exits. -}
|
{- Runs rsync in server mode to send a file, and exits. -}
|
||||||
rsyncServerSend :: FilePath -> IO ()
|
rsyncServerSend :: FilePath -> IO ()
|
||||||
rsyncServerSend file = rsyncExec $ rsyncServerParams ++ ["--sender", file]
|
rsyncServerSend file = rsyncExec $
|
||||||
|
rsyncServerParams ++ ["--sender", utilityEscape file]
|
||||||
|
|
||||||
{- Runs rsync in server mode to receive a file. -}
|
{- Runs rsync in server mode to receive a file. -}
|
||||||
rsyncServerReceive :: FilePath -> IO Bool
|
rsyncServerReceive :: FilePath -> IO Bool
|
||||||
rsyncServerReceive file = rsync $ rsyncServerParams ++ [file]
|
rsyncServerReceive file = rsync $ rsyncServerParams ++ [utilityEscape file]
|
||||||
|
|
||||||
rsyncServerParams :: [String]
|
rsyncServerParams :: [String]
|
||||||
rsyncServerParams =
|
rsyncServerParams =
|
||||||
|
|
|
@ -15,6 +15,7 @@ module Utility (
|
||||||
boolSystem,
|
boolSystem,
|
||||||
shellEscape,
|
shellEscape,
|
||||||
shellUnEscape,
|
shellUnEscape,
|
||||||
|
utilityEscape,
|
||||||
unsetFileMode,
|
unsetFileMode,
|
||||||
readMaybe,
|
readMaybe,
|
||||||
safeWriteFile,
|
safeWriteFile,
|
||||||
|
@ -179,6 +180,13 @@ shellUnEscape s = word:(shellUnEscape rest)
|
||||||
| c == q = findword w cs
|
| c == q = findword w cs
|
||||||
| otherwise = inquote q (w++[c]) cs
|
| otherwise = inquote q (w++[c]) cs
|
||||||
|
|
||||||
|
{- Ensures that a filename is safe to pass to a utility program. In particular
|
||||||
|
- since utilities tend to interpret things starting with a dash as
|
||||||
|
- an option, relative filenames starting with a dash are escaped. -}
|
||||||
|
utilityEscape :: FilePath -> FilePath
|
||||||
|
utilityEscape ('-':s) = "./-" ++ s
|
||||||
|
utilityEscape s = s
|
||||||
|
|
||||||
{- For quickcheck. -}
|
{- For quickcheck. -}
|
||||||
prop_idempotent_shellEscape :: String -> Bool
|
prop_idempotent_shellEscape :: String -> Bool
|
||||||
prop_idempotent_shellEscape s = [s] == (shellUnEscape $ shellEscape s)
|
prop_idempotent_shellEscape s = [s] == (shellUnEscape $ shellEscape s)
|
||||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -5,6 +5,9 @@ git-annex (0.22) UNRELEASED; urgency=low
|
||||||
for his help eliminating the infestation... for now.)
|
for his help eliminating the infestation... for now.)
|
||||||
* Make test suite not rely on a working cp -pr.
|
* Make test suite not rely on a working cp -pr.
|
||||||
(The Unix wars are still ON!)
|
(The Unix wars are still ON!)
|
||||||
|
* Support filenames that start with a dash; when such a file is passed
|
||||||
|
to a utility it will be escaped to avoid it being interpreted as an
|
||||||
|
option.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sun, 13 Feb 2011 00:48:02 -0400
|
-- Joey Hess <joeyh@debian.org> Sun, 13 Feb 2011 00:48:02 -0400
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,6 @@ add -wut-a-directory-name-/file1 (checksum...) sha1sum: invalid option -- 'u'
|
||||||
|
|
||||||
git-annex: <file descriptor: 15>: hGetLine: end of file
|
git-annex: <file descriptor: 15>: hGetLine: end of file
|
||||||
"""]]
|
"""]]
|
||||||
|
|
||||||
|
> This is fixed in git, at least I think I've found all cases where
|
||||||
|
> filenames are passed to programs and escaped them. --[[Joey]] [[done]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue