diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-17 15:59:37 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-17 15:59:37 -0400 |
commit | 4e74c0d7f33a66eb524ef020ef4401fa322db34c (patch) | |
tree | d0a239d6022339b3cb5afeced2d3f859aa4d02d3 /Annex/ReplaceFile.hs | |
parent | 963f2c5726ce0fe899038733d4318a234d355268 (diff) |
test suite passes in direct mode
This fixes a bug with git annex add in direct mode. If some files already
existed in the tree pointing at the same key as a file that was just added,
and their content was not present, add neglected to copy the content to
those files.
I also changed the behavior of moveAnnex slightly: When content is moved
into the annex in direct mode, it does not overwrite any content already
present in direct mode files. That content may be modified after all.
Diffstat (limited to 'Annex/ReplaceFile.hs')
-rw-r--r-- | Annex/ReplaceFile.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Annex/ReplaceFile.hs b/Annex/ReplaceFile.hs new file mode 100644 index 000000000..f0dfa5b27 --- /dev/null +++ b/Annex/ReplaceFile.hs @@ -0,0 +1,35 @@ +{- git-annex file replacing + - + - Copyright 2013 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Annex.ReplaceFile where + +import Common.Annex +import Annex.Perms + +{- Replaces a possibly already existing file with a new version, + - atomically, by running an action. + - + - The action is passed a temp file, which it can write to, and once + - done the temp file is moved into place. + -} +replaceFile :: FilePath -> (FilePath -> Annex ()) -> Annex () +replaceFile file a = do + tmpdir <- fromRepo gitAnnexTmpDir + createAnnexDirectory tmpdir + tmpfile <- liftIO $ do + (tmpfile, h) <- openTempFileWithDefaultPermissions tmpdir $ + takeFileName file + hClose h + return tmpfile + a tmpfile + liftIO $ do + r <- tryIO $ rename tmpfile file + case r of + Left _ -> do + createDirectoryIfMissing True $ parentDir file + rename tmpfile file + _ -> noop |