From 5f55082d10f218158c2dfce6e34c758fe979c523 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 9 Nov 2017 15:14:00 -0400 Subject: [PATCH] Revert "use unix-compat 0.5 on windows" This reverts commit 3ec579f5e1b0896bca105fd4f70aed6aa419f0be. Too early for this; needs newer Win32 version. Le sigh. --- Annex/Content.hs | 2 +- Annex/Fixup.hs | 2 +- Common.hs | 2 +- Utility/DirWatcher/Win32Notify.hs | 2 +- Utility/Directory.hs | 2 +- Utility/FileMode.hs | 2 +- Utility/PosixFiles.hs | 42 +++++++++++++++++++++++++++++++ Utility/Tmp.hs | 2 +- git-annex.cabal | 7 ++---- stack-windows.yaml | 1 - 10 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 Utility/PosixFiles.hs diff --git a/Annex/Content.hs b/Annex/Content.hs index 2ba3871051..0b665d4dcc 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -50,7 +50,6 @@ module Annex.Content ( ) where import System.IO.Unsafe (unsafeInterleaveIO) -import System.PosixCompat.Files import qualified Data.Set as S import Annex.Common @@ -85,6 +84,7 @@ import Types.Key import Annex.UUID import Annex.InodeSentinal import Utility.InodeCache +import Utility.PosixFiles {- Checks if a given key's content is currently present. -} inAnnex :: Key -> Annex Bool diff --git a/Annex/Fixup.hs b/Annex/Fixup.hs index 4b5149d0ab..6a14f22bc9 100644 --- a/Annex/Fixup.hs +++ b/Annex/Fixup.hs @@ -15,11 +15,11 @@ import qualified Git.BuildVersion import Utility.Path import Utility.SafeCommand import Utility.Directory +import Utility.PosixFiles import Utility.Exception import System.IO import System.FilePath -import System.PosixCompat.Files import Data.List import Control.Monad import Control.Monad.IfElse diff --git a/Common.hs b/Common.hs index 8ff1b718ae..ba8382613b 100644 --- a/Common.hs +++ b/Common.hs @@ -18,7 +18,6 @@ import System.IO as X hiding (FilePath) import System.Posix.IO as X hiding (createPipe) #endif import System.Exit as X -import System.PosixCompat.Files as X hiding (fileSize) import Utility.Misc as X import Utility.Exception as X @@ -29,6 +28,7 @@ import Utility.Directory as X import Utility.Monad as X import Utility.Data as X import Utility.Applicative as X +import Utility.PosixFiles as X hiding (fileSize) import Utility.FileSize as X import Utility.Network as X import Utility.Split as X diff --git a/Utility/DirWatcher/Win32Notify.hs b/Utility/DirWatcher/Win32Notify.hs index a2f40128fb..3428f3db37 100644 --- a/Utility/DirWatcher/Win32Notify.hs +++ b/Utility/DirWatcher/Win32Notify.hs @@ -11,7 +11,7 @@ import Common hiding (isDirectory) import Utility.DirWatcher.Types import System.Win32.Notify -import qualified System.PosixCompat.Files as Files +import qualified Utility.PosixFiles as Files watchDir :: FilePath -> (FilePath -> Bool) -> Bool -> WatchHooks -> IO WatchManager watchDir dir ignored scanevents hooks = do diff --git a/Utility/Directory.hs b/Utility/Directory.hs index 895581dff1..c24f36da56 100644 --- a/Utility/Directory.hs +++ b/Utility/Directory.hs @@ -16,7 +16,6 @@ module Utility.Directory ( import System.IO.Error import Control.Monad import System.FilePath -import System.PosixCompat.Files import Control.Applicative import Control.Concurrent import System.IO.Unsafe (unsafeInterleaveIO) @@ -32,6 +31,7 @@ import Control.Monad.IfElse #endif import Utility.SystemDirectory +import Utility.PosixFiles import Utility.Tmp import Utility.Exception import Utility.Monad diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index 370bcf62da..d9a269448f 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -15,7 +15,7 @@ module Utility.FileMode ( import System.IO import Control.Monad import System.PosixCompat.Types -import System.PosixCompat.Files +import Utility.PosixFiles #ifndef mingw32_HOST_OS import System.Posix.Files import Control.Monad.IO.Class (liftIO) diff --git a/Utility/PosixFiles.hs b/Utility/PosixFiles.hs new file mode 100644 index 0000000000..37253da29b --- /dev/null +++ b/Utility/PosixFiles.hs @@ -0,0 +1,42 @@ +{- POSIX files (and compatablity wrappers). + - + - This is like System.PosixCompat.Files, but with a few fixes. + - + - Copyright 2014 Joey Hess + - + - License: BSD-2-clause + -} + +{-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -fno-warn-tabs #-} + +module Utility.PosixFiles ( + module X, + rename +) where + +import System.PosixCompat.Files as X hiding (rename) + +#ifndef mingw32_HOST_OS +import System.Posix.Files (rename) +#else +import qualified System.Win32.File as Win32 +import qualified System.Win32.HardLink as Win32 +#endif + +{- System.PosixCompat.Files.rename on Windows calls renameFile, + - so cannot rename directories. + - + - Instead, use Win32 moveFile, which can. It needs to be told to overwrite + - any existing file. -} +#ifdef mingw32_HOST_OS +rename :: FilePath -> FilePath -> IO () +rename src dest = Win32.moveFileEx src dest Win32.mOVEFILE_REPLACE_EXISTING +#endif + +{- System.PosixCompat.Files.createLink throws an error, but windows + - does support hard links. -} +#ifdef mingw32_HOST_OS +createLink :: FilePath -> FilePath -> IO () +createLink = Win32.createHardLink +#endif diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index 7255c141e5..ca611e0b4c 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -15,13 +15,13 @@ import Control.Monad.IfElse import System.FilePath import System.Directory import Control.Monad.IO.Class -import System.PosixCompat.Files #ifndef mingw32_HOST_OS import System.Posix.Temp (mkdtemp) #endif import Utility.Exception import Utility.FileSystemEncoding +import Utility.PosixFiles type Template = String diff --git a/git-annex.cabal b/git-annex.cabal index 3363d12a8e..f16e682cfb 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -380,11 +380,7 @@ Executable git-annex Build-Depends: network (< 2.6), network (>= 2.4) if (os(windows)) - Build-Depends: - Win32 (== 2.3.1.1), - Win32-extras, - unix-compat (>= 0.5), - setenv, + Build-Depends: Win32 (== 2.3.1.1), Win32-extras, unix-compat (>= 0.4.1.3), setenv, process (>= 1.4.2.0) else Build-Depends: unix @@ -1030,6 +1026,7 @@ Executable git-annex Utility.PartialPrelude Utility.Path Utility.Percentage + Utility.PosixFiles Utility.Process Utility.Process.Shim Utility.QuickCheck diff --git a/stack-windows.yaml b/stack-windows.yaml index fc81c3454a..bdacbec314 100644 --- a/stack-windows.yaml +++ b/stack-windows.yaml @@ -25,7 +25,6 @@ extra-deps: - bloomfilter-2.0.1.0 - torrent-10000.1.1 - yesod-default-1.2.0 -- unix-compat-0.5 explicit-setup-deps: git-annex: true resolver: lts-9.10