aboutsummaryrefslogtreecommitdiff
path: root/Annex/View
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2014-12-30 17:48:04 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2014-12-30 17:48:04 -0400
commit9c2f520e57a61667bd887275e645baf8ee0f4f6f (patch)
tree42444a66f2a116da7b96825dda43beaa31cda961 /Annex/View
parentdd38607b51535f02fe058107b606dd744a463837 (diff)
Windows: Fix handling of views of filenames containing '%'
Diffstat (limited to 'Annex/View')
-rw-r--r--Annex/View/ViewedFile.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/Annex/View/ViewedFile.hs b/Annex/View/ViewedFile.hs
index 827ab09dc..0b963fcd5 100644
--- a/Annex/View/ViewedFile.hs
+++ b/Annex/View/ViewedFile.hs
@@ -5,6 +5,8 @@
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE CPP #-}
+
module Annex.View.ViewedFile (
ViewedFile,
MkViewedFile,
@@ -43,10 +45,18 @@ viewedFileFromReference f = concat
{- To avoid collisions with filenames or directories that contain
- '%', and to allow the original directories to be extracted
- - from the ViewedFile, '%' is escaped to '\%' (and '\' to '\\').
+ - from the ViewedFile, '%' is escaped. )
-}
escape :: String -> String
- escape = replace "%" "\\%" . replace "\\" "\\\\"
+ escape = replace "%" (escchar:'%':[]) . replace [escchar] [escchar, escchar]
+
+escchar :: Char
+#ifndef mingw32_HOST_OS
+escchar = '\\'
+#else
+-- \ is path separator on Windows, so instead use !
+escchar = '!'
+#endif
{- For use when operating already within a view, so whatever filepath
- is present in the work tree is already a ViewedFile. -}
@@ -61,7 +71,7 @@ dirFromViewedFile = joinPath . drop 1 . sep [] ""
sep l _ [] = reverse l
sep l curr (c:cs)
| c == '%' = sep (reverse curr:l) "" cs
- | c == '\\' = case cs of
+ | c == escchar = case cs of
(c':cs') -> sep l (c':curr) cs'
[] -> sep l curr cs
| otherwise = sep l (c:curr) cs