import Annex.InodeSentinal
import Utility.InodeCache
import Utility.FileMode
+import qualified Utility.RawFilePath as R
import qualified Data.Set as S
import qualified Data.Map as M
import qualified Data.ByteString.Lazy as L
-import qualified Utility.RawFilePath as R
{- Merges from a branch into the current branch (which may not exist yet),
- with automatic merge conflict resolution.
-- files, so delete here.
unless inoverlay $
unless (islocked LsFiles.valUs) $
- liftIO $ removeWhenExistsWith removeLink file
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath file)
| otherwise -> do
-- Only resolve using symlink when both
-- were locked, otherwise use unlocked
<$> mapM Database.Keys.getInodeCaches resolvedks
forM_ (M.toList unstagedmap) $ \(i, f) ->
whenM (matchesresolved is i f) $
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
where
fs = S.fromList resolvedfs
ks = S.fromList resolvedks
stagedfs <- lines <$> hGetContents jlogh
mapM_ (removeFile . (dir </>)) stagedfs
hClose jlogh
- removeWhenExistsWith removeLink jlogf
+ removeWhenExistsWith (R.removeLink) (toRawFilePath jlogf)
openjlog tmpdir = liftIO $ openTempFile tmpdir "jlog"
{- This is run after the refs have been merged into the index,
import Utility.CopyFile
import qualified Utility.RawFilePath as R
-import System.PosixCompat.Files
import qualified System.FilePath.ByteString as P
{- Runs the secure erase command if set, otherwise does nothing.
=<< liftIO (R.getFileStatus src)
checkedCopyFile' :: Key -> RawFilePath -> RawFilePath -> Maybe FileMode -> FileStatus -> Annex Bool
-checkedCopyFile' key src dest destmode s = catchBoolIO $
- ifM (checkDiskSpace' (fromIntegral $ fileSize s) (Just $ P.takeDirectory dest) key 0 True)
+checkedCopyFile' key src dest destmode s = catchBoolIO $ do
+ sz <- liftIO $ getFileSize' src s
+ ifM (checkDiskSpace' sz (Just $ P.takeDirectory dest) key 0 True)
( liftIO $
copyFileExternal CopyAllMetaData (fromRawFilePath src) (fromRawFilePath dest)
<&&> preserveGitMode dest destmode
module Annex.Content.PointerFile where
-#if ! defined(mingw32_HOST_OS)
-import System.Posix.Files
-#else
-import System.PosixCompat.Files
-#endif
-
import Annex.Common
import Annex.Perms
import Annex.Link
import Annex.InodeSentinal
import Annex.Content.LowLevel
import Utility.InodeCache
+import qualified Utility.RawFilePath as R
#if ! defined(mingw32_HOST_OS)
import Utility.Touch
+import System.Posix.Files (modificationTimeHiRes)
#endif
-import qualified Utility.RawFilePath as R
{- Populates a pointer file with the content of a key.
-
import Annex.InodeSentinal
import Annex.AdjustedBranch
import Annex.FileMatcher
+import qualified Utility.RawFilePath as R
import Control.Exception (IOException)
-import qualified Utility.RawFilePath as R
data LockedDown = LockedDown
{ lockDownConfig :: LockDownConfig
(tmpfile, h) <- openTempFile (fromRawFilePath tmpdir) $
relatedTemplate $ "ingest-" ++ takeFileName file
hClose h
- removeWhenExistsWith removeLink tmpfile
+ removeWhenExistsWith R.removeLink (toRawFilePath tmpfile)
withhardlink' delta tmpfile
`catchIO` const (nohardlink' delta)
import Upgrade
import Annex.Tmp
import Utility.UserInfo
-#ifndef mingw32_HOST_OS
import qualified Utility.RawFilePath as R
+#ifndef mingw32_HOST_OS
import Utility.ThreadScheduler
import Annex.Perms
import Utility.FileMode
where
probe f = catchDefaultIO (True, []) $ do
let f2 = f ++ "2"
- removeWhenExistsWith removeLink f2
+ removeWhenExistsWith R.removeLink (toRawFilePath f2)
createSymbolicLink f f2
- removeWhenExistsWith removeLink f2
+ removeWhenExistsWith R.removeLink (toRawFilePath f2)
preventWrite (toRawFilePath f)
-- Should be unable to write to the file, unless
-- running as root, but some crippled
}
void $ liftIO $ catchMaybeIO $ withCreateProcess p $ \_ _ _ pid ->
forceSuccessProcess p pid
- liftIO $ removeWhenExistsWith removeLink socketfile
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath socketfile)
{- This needs to be as short as possible, due to limitations on the length
- of the path to a socket file. At the same time, it needs to be unique
import Annex.LockFile
import Annex.Perms
import Types.CleanupActions
+import qualified Utility.RawFilePath as R
import Data.Time.Clock.POSIX
let oldenough = now - (60 * 60 * 24 * 7)
catchMaybeIO (modificationTime <$> getSymbolicLinkStatus f) >>= \case
Just mtime | realToFrac mtime <= oldenough ->
- void $ tryIO $ removeWhenExistsWith removeLink f
+ void $ tryIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
_ -> return ()
#endif
import qualified Utility.Lsof as Lsof
import Utility.ThreadScheduler
+import qualified Utility.RawFilePath as R
import Control.Concurrent.Async
waitforit "to check stale git lock file"
l' <- getsizes
if l' == l
- then liftIO $ mapM_ (removeWhenExistsWith removeLink . fst) l
+ then liftIO $ mapM_ (removeWhenExistsWith R.removeLink . toRawFilePath . fst) l
else go l'
, do
waitforit "for git lock file writer"
import qualified Utility.Url as Url
import qualified Annex.Url as Url hiding (download)
import Utility.Tuple
+import qualified Utility.RawFilePath as R
import Data.Either
import qualified Data.Map as M
error $ "did not find " ++ dir ++ " in " ++ distributionfile
makeorigsymlink olddir = do
let origdir = fromRawFilePath (parentDir (toRawFilePath olddir)) </> installBase
- removeWhenExistsWith removeLink origdir
+ removeWhenExistsWith R.removeLink (toRawFilePath origdir)
createSymbolicLink newdir origdir
{- Finds where the old version was installed. -}
deleteFromManifest :: FilePath -> IO ()
deleteFromManifest dir = do
fs <- map (dir </>) . lines <$> catchDefaultIO "" (readFile manifest)
- mapM_ (removeWhenExistsWith removeLink) fs
- removeWhenExistsWith removeLink manifest
+ mapM_ (removeWhenExistsWith R.removeLink . toRawFilePath) fs
+ removeWhenExistsWith R.removeLink (toRawFilePath manifest)
removeEmptyRecursive dir
where
manifest = dir </> "git-annex.MANIFEST"
import Utility.ThreadScheduler
import Utility.DiskFree
import Git.Types (fromConfigKey)
+import qualified Utility.RawFilePath as R
import Data.Time.Clock
import System.Random (getStdRandom, random, randomR)
n <- liftIO (getStdRandom random :: IO Int)
liftIO $ writeFile f $ show n ++ "\n"
runFuzzAction (FuzzDelete (FuzzFile f)) = liftIO $
- removeWhenExistsWith removeLink f
+ removeWhenExistsWith R.removeLink (toRawFilePath f)
runFuzzAction (FuzzMove (FuzzFile src) (FuzzFile dest)) = liftIO $
rename src dest
runFuzzAction (FuzzDeleteDir (FuzzDir d)) = liftIO $
import Utility.Tmp
import Utility.Tmp.Dir
import Utility.Process.Transcript
+import qualified Utility.RawFilePath as R
import Data.Char
import qualified Data.ByteString.Lazy.UTF8 as B8
KeyContainer s -> liftIO $ genkey (Param s)
KeyFile f -> do
createAnnexDirectory (toRawFilePath (takeDirectory f))
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
liftIO $ protectedOutput $ genkey (File f)
case (ok, parseFingerprint s) of
(False, _) -> giveup $ "uftp_keymgt failed: " ++ s
case deserializeKey (takeFileName f) of
Nothing -> do
warning $ "Received a file " ++ f ++ " that is not a git-annex key. Deleting this file."
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
Just k -> void $
getViaTmpFromDisk RetrievalVerifiableKeysSecure AlwaysVerify k (AssociatedFile Nothing) $ \dest -> unVerified $
liftIO $ catchBoolIO $ do
import Utility.Tmp.Dir
import Utility.FileMode
import Utility.ThreadScheduler
+import qualified Utility.RawFilePath as R
import qualified Utility.MagicWormhole as Wormhole
import Control.Concurrent.Async
Wormhole.sendFile sendf observer wormholeparams
`concurrently`
Wormhole.receiveFile recvf producer wormholeparams
- liftIO $ removeWhenExistsWith removeLink sendf
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath sendf)
if sendres /= True
then return SendFailed
else if recvres /= True
import Types.NumCopies
import Remote
import Git.Types (fromConfigKey, fromConfigValue)
+import qualified Utility.RawFilePath as R
cmd :: Command
cmd = command "vicfg" SectionSetup "edit configuration in git-annex branch"
unlessM (liftIO $ boolSystem "sh" [Param "-c", Param $ unwords [vi, shellEscape f]]) $
giveup $ vi ++ " exited nonzero; aborting"
r <- parseCfg (defCfg curcfg) <$> liftIO (readFileStrict f)
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
case r of
Left s -> do
liftIO $ writeFile f s
import System.FilePath as X
import System.IO as X hiding (FilePath)
import System.Exit as X
-import System.PosixCompat.Files as X hiding (fileSize)
+import System.PosixCompat.Files as X hiding (fileSize, removeLink)
import Utility.Misc as X
import Utility.Exception as X
import Types.ProposedAccepted
import Remote.Helper.Encryptable (remoteCipher, remoteCipher', embedCreds, EncryptionIsSetup, extractCipher)
import Utility.Env (getEnv)
+import Utility.Base64
+import qualified Utility.RawFilePath as R
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.ByteString.Char8 as S
import qualified Data.Map as M
import qualified System.FilePath.ByteString as P
-import Utility.Base64
{- A CredPair can be stored in a file, or in the environment, or
- in a remote's configuration. -}
removeCreds :: FilePath -> Annex ()
removeCreds file = do
- d <- fromRawFilePath <$> fromRepo gitAnnexCredsDir
- let f = d </> file
- liftIO $ removeWhenExistsWith removeLink f
+ d <- fromRepo gitAnnexCredsDir
+ liftIO $ removeWhenExistsWith R.removeLink (d P.</> toRawFilePath file)
includeCredsInfo :: ParsedRemoteConfig -> CredPairStorage -> [(String, String)] -> Annex [(String, String)]
includeCredsInfo pc@(ParsedRemoteConfig cm _) storage info = do
- Licensed under the GNU AGPL version 3 or higher.
-}
+{-# LANGUAGE OverloadedStrings #-}
+
module Git.Repair (
runRepair,
runRepairOf,
explodePackedRefsFile :: Repo -> IO ()
explodePackedRefsFile r = do
let f = packedRefsFile r
+ let f' = toRawFilePath f
whenM (doesFileExist f) $ do
rs <- mapMaybe parsePacked . lines
- <$> catchDefaultIO "" (safeReadFile f)
+ <$> catchDefaultIO "" (safeReadFile f')
forM_ rs makeref
- removeWhenExistsWith removeLink f
+ removeWhenExistsWith R.removeLink f'
where
makeref (sha, ref) = do
let gitd = localGitDir r
preRepair :: Repo -> IO ()
preRepair g = do
unlessM (validhead <$> catchDefaultIO "" (safeReadFile headfile)) $ do
- removeWhenExistsWith removeLink headfile
- writeFile headfile "ref: refs/heads/master"
+ removeWhenExistsWith R.removeLink headfile
+ writeFile (fromRawFilePath headfile) "ref: refs/heads/master"
explodePackedRefsFile g
unless (repoIsLocalBare g) $
void $ tryIO $ allowWrite $ indexFile g
where
- headfile = fromRawFilePath (localGitDir g) </> "HEAD"
+ headfile = localGitDir g P.</> "HEAD"
validhead s = "ref: refs/" `isPrefixOf` s
|| isJust (extractSha (encodeBS' s))
successfulRepair :: (Bool, [Branch]) -> Bool
successfulRepair = fst
-safeReadFile :: FilePath -> IO String
+safeReadFile :: RawFilePath -> IO String
safeReadFile f = do
- allowRead (toRawFilePath f)
- readFileStrict f
+ allowRead f
+ readFileStrict (fromRawFilePath f)
import Utility.FileMode
import Types.UUID
import Annex.ChangedRefs
+import qualified Utility.RawFilePath as R
import Control.Monad.Free
import Control.Monad.IO.Class
-- the callback.
serveUnixSocket :: FilePath -> (Handle -> IO ()) -> IO ()
serveUnixSocket unixsocket serveconn = do
- removeWhenExistsWith removeLink unixsocket
+ removeWhenExistsWith R.removeLink (toRawFilePath unixsocket)
soc <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
S.bind soc (S.SockAddrUnix unixsocket)
-- Allow everyone to read and write to the socket,
removeExportM :: RawFilePath -> Key -> ExportLocation -> Annex ()
removeExportM d _k loc = liftIO $ do
- removeWhenExistsWith removeLink src
+ removeWhenExistsWith R.removeLink src
removeExportLocation d loc
where
- src = fromRawFilePath $ exportPath d loc
+ src = exportPath d loc
checkPresentExportM :: RawFilePath -> Key -> ExportLocation -> Annex Bool
checkPresentExportM d _k loc =
import Annex.Tmp
import Utility.Metered
import Utility.Directory.Create
+import qualified Utility.RawFilePath as R
withCheckedFiles :: (FilePath -> IO Bool) -> FilePath -> (FilePath -> Key -> [FilePath]) -> Key -> ([FilePath] -> IO Bool) -> IO Bool
withCheckedFiles _ [] _locations _ _ = return False
retrieve :: (RawFilePath -> Key -> [RawFilePath]) -> RawFilePath -> Retriever
retrieve locations d basek p c = withOtherTmp $ \tmpdir -> do
showLongNote "This remote uses the deprecated chunksize setting. So this will be quite slow."
- let tmp = fromRawFilePath $
- tmpdir P.</> keyFile basek <> ".directorylegacy.tmp"
+ let tmp = tmpdir P.</> keyFile basek <> ".directorylegacy.tmp"
+ let tmp' = fromRawFilePath tmp
let go = \k sink -> do
liftIO $ void $ withStoredFiles (fromRawFilePath d) (legacyLocations locations) k $ \fs -> do
forM_ fs $
- S.appendFile tmp <=< S.readFile
+ S.appendFile tmp' <=< S.readFile
return True
- b <- liftIO $ L.readFile tmp
- liftIO $ removeWhenExistsWith removeLink tmp
+ b <- liftIO $ L.readFile tmp'
+ liftIO $ removeWhenExistsWith R.removeLink tmp
sink b
byteRetriever go basek p c
import qualified Git
import qualified Git.Construct
import Git.Types
+import qualified Utility.RawFilePath as R
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
withBytes content $ \b ->
decrypt cmd c cipher (feedBytes b) $
readBytes write
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
(Nothing, _, FileContent f) -> do
withBytes content write
- liftIO $ removeWhenExistsWith removeLink f
+ liftIO $ removeWhenExistsWith R.removeLink (toRawFilePath f)
(Nothing, _, ByteContent b) -> write b
where
write b = case mh of
test_ignore_deleted_files = intmpclonerepo $ do
git_annex "get" [annexedfile] @? "get failed"
git_annex_expectoutput "find" [] [annexedfile]
- removeWhenExistsWith removeLink annexedfile
+ removeWhenExistsWith R.removeLink (toRawFilePath annexedfile)
-- A file that has been deleted, but the deletion not staged,
-- is a special case; make sure git-annex skips these.
git_annex_expectoutput "find" [] []
@? "unlock conflictor failed"
writecontent conflictor "newconflictor"
indir r1 $
- removeWhenExistsWith removeLink conflictor
+ removeWhenExistsWith R.removeLink (toRawFilePath conflictor)
let l = if inr1 then [r1, r2, r1] else [r2, r1, r2]
forM_ l $ \r -> indir r $
git_annex "sync" [] @? "sync failed"
git_annex "merge" ["foo/" ++ origbranch] @? "git annex merge failed"
annexed_present_imported "import"
- removeWhenExistsWith removeLink "import"
+ removeWhenExistsWith R.removeLink (toRawFilePath "import")
writecontent "import" (content "newimport1")
git_annex "add" ["import"] @? "add of import failed"
commitchanges
-- verify that export refuses to overwrite modified file
writedir "import" (content "newimport2")
- removeWhenExistsWith removeLink "import"
+ removeWhenExistsWith R.removeLink (toRawFilePath "import")
writecontent "import" (content "newimport3")
git_annex "add" ["import"] @? "add of import failed"
commitchanges
-- resolving import conflict
git_annex "import" [origbranch, "--from", "foo"] @? "import from dir failed"
not <$> boolSystem "git" [Param "merge", Param "foo/master", Param "-mmerge"] @? "git merge of conflict failed to exit nonzero"
- removeWhenExistsWith removeLink "import"
+ removeWhenExistsWith R.removeLink (toRawFilePath "import")
writecontent "import" (content "newimport3")
git_annex "add" ["import"] @? "add of import failed"
commitchanges
import Utility.InodeCache
import Utility.DottedVersion
import Annex.AdjustedBranch
+import qualified Utility.RawFilePath as R
import qualified Data.ByteString as S
)
writepointer f k = liftIO $ do
- removeWhenExistsWith removeLink f
+ removeWhenExistsWith R.removeLink (toRawFilePath f)
S.writeFile f (formatPointer k)
{- Remove all direct mode bookkeeping files. -}
import Control.Monad
import System.FilePath
-import System.PosixCompat.Files
+import System.PosixCompat.Files hiding (removeLink)
import Control.Applicative
import System.IO.Unsafe (unsafeInterleaveIO)
import Data.Maybe
import System.IO
import Control.Monad
import System.PosixCompat.Types
-import System.PosixCompat.Files
+import System.PosixCompat.Files hiding (removeLink)
import Control.Monad.IO.Class
import Foreign (complement)
import Control.Monad.Catch
getFileSize',
) where
-import System.PosixCompat.Files
+import System.PosixCompat.Files hiding (removeLink)
import qualified Utility.RawFilePath as R
#ifdef mingw32_HOST_OS
import Control.Exception (bracket)
import Control.Monad
import System.FilePath
-import System.PosixCompat.Files
+import System.PosixCompat.Files hiding (removeLink)
import System.IO.Error
import Prelude
import System.FilePath
import System.Directory
import Control.Monad.IO.Class
-import System.PosixCompat.Files
+import System.PosixCompat.Files hiding (removeLink)
import Utility.Exception
import Utility.FileSystemEncoding