From 91e6625eb56671472abd9532a5635f541d025a60 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 22 Oct 2010 14:57:02 -0400 Subject: add shellEscape ugly, but sometimes necessary There is a haskell shell-escape module, but it is not packaged in Debian --- Utility.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Utility.hs') diff --git a/Utility.hs b/Utility.hs index 09b973002..8bffde057 100644 --- a/Utility.hs +++ b/Utility.hs @@ -7,7 +7,8 @@ module Utility ( parentDir, relPathCwdToDir, relPathDirToDir, - boolSystem + boolSystem, + shellEscape ) where import System.IO @@ -108,3 +109,9 @@ boolSystem command params = do ExitFailure e -> if Just e == cast sigINT then error $ command ++ "interrupted" else return False + +{- Escapes a filename to be safely able to be exposed to the shell. -} +shellEscape f = "'" ++ quote ++ "'" + where + -- replace ' with '"'"' + quote = join "'\"'\"'" $ split "'" f -- cgit v1.2.3