summaryrefslogtreecommitdiff
path: root/Utility/MoveFile.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2023-08-14 12:06:32 -0400
committerJoey Hess <joeyh@joeyh.name>2023-08-14 12:12:52 -0400
commitedf83982be214f3c839fab9b659f645de53a9100 (patch)
treebef06cb750379c6d7942fc13b13fcb328201354c /Utility/MoveFile.hs
parentf0cd3a2a3758ddcd2f0900c16bdc1fb80bbd6e92 (diff)
downloadgit-repair-edf83982be214f3c839fab9b659f645de53a9100.tar.gz
merge from git-annex
Support building with unix-compat 0.7
Diffstat (limited to 'Utility/MoveFile.hs')
-rw-r--r--Utility/MoveFile.hs25
1 files changed, 15 insertions, 10 deletions
diff --git a/Utility/MoveFile.hs b/Utility/MoveFile.hs
index 3ea17e8..6481b29 100644
--- a/Utility/MoveFile.hs
+++ b/Utility/MoveFile.hs
@@ -14,12 +14,11 @@ module Utility.MoveFile (
) where
import Control.Monad
-import System.FilePath
-import System.PosixCompat.Files hiding (removeLink)
import System.IO.Error
import Prelude
#ifndef mingw32_HOST_OS
+import System.PosixCompat.Files (isDirectory)
import Control.Monad.IfElse
import Utility.SafeCommand
#endif
@@ -28,17 +27,19 @@ import Utility.SystemDirectory
import Utility.Tmp
import Utility.Exception
import Utility.Monad
+import Utility.FileSystemEncoding
+import qualified Utility.RawFilePath as R
{- Moves one filename to another.
- First tries a rename, but falls back to moving across devices if needed. -}
-moveFile :: FilePath -> FilePath -> IO ()
-moveFile src dest = tryIO (rename src dest) >>= onrename
+moveFile :: RawFilePath -> RawFilePath -> IO ()
+moveFile src dest = tryIO (R.rename src dest) >>= onrename
where
onrename (Right _) = noop
onrename (Left e)
| isPermissionError e = rethrow
| isDoesNotExistError e = rethrow
- | otherwise = viaTmp mv dest ()
+ | otherwise = viaTmp mv (fromRawFilePath dest) ()
where
rethrow = throwM e
@@ -46,16 +47,20 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
-- copyFile is likely not as optimised as
-- the mv command, so we'll use the command.
--
- -- But, while Windows has a "mv", it does not seem very
- -- reliable, so use copyFile there.
+ -- But, while Windows has a "mv", it does not
+ -- seem very reliable, so use copyFile there.
#ifndef mingw32_HOST_OS
-- If dest is a directory, mv would move the file
-- into it, which is not desired.
whenM (isdir dest) rethrow
- ok <- boolSystem "mv" [Param "-f", Param src, Param tmp]
+ ok <- boolSystem "mv"
+ [ Param "-f"
+ , Param (fromRawFilePath src)
+ , Param tmp
+ ]
let e' = e
#else
- r <- tryIO $ copyFile src tmp
+ r <- tryIO $ copyFile (fromRawFilePath src) tmp
let (ok, e') = case r of
Left err -> (False, err)
Right _ -> (True, e)
@@ -67,7 +72,7 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
#ifndef mingw32_HOST_OS
isdir f = do
- r <- tryIO $ getFileStatus f
+ r <- tryIO $ R.getSymbolicLinkStatus f
case r of
(Left _) -> return False
(Right s) -> return $ isDirectory s