summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
Diffstat (limited to 'Command')
-rw-r--r--Command/Add.hs43
-rw-r--r--Command/ReKey.hs15
2 files changed, 31 insertions, 27 deletions
diff --git a/Command/Add.hs b/Command/Add.hs
index fe1a6b13a..6a2261d1f 100644
--- a/Command/Add.hs
+++ b/Command/Add.hs
@@ -80,20 +80,21 @@ start file = ifAnnexed file addpresent add
{- The file that's being added is locked down before a key is generated,
- to prevent it from being modified in between. It's hard linked into a
- - temporary location, and its writable bits are removed. It could still be
- - written to by a process that already has it open for writing.
+ - temporary location (to prevent it being replaced with another file),
+ - and its writable bits are removed. It could still be written to by a
+ - process that already has it open for writing.
+ -
+ - On a crippled filesystem, no lock down is done; the file can be modified
+ - at any time, and the no hard link is made.
+ -
+ - On a filesystem without hard links, but not otherwise crippled,
+ - no hard link is made, but the write bit is still removed.
-
- Lockdown can fail if a file gets deleted, and Nothing will be returned.
-}
lockDown :: FilePath -> Annex (Maybe KeySource)
lockDown file = ifM (crippledFileSystem)
- ( liftIO $ catchMaybeIO $ do
- cache <- genInodeCache file
- return $ KeySource
- { keyFilename = file
- , contentLocation = file
- , inodeCache = cache
- }
+ ( liftIO $ catchMaybeIO nohardlink
, do
tmp <- fromRepo gitAnnexTmpDir
createAnnexDirectory tmp
@@ -102,14 +103,24 @@ lockDown file = ifM (crippledFileSystem)
(tmpfile, h) <- openTempFile tmp (takeFileName file)
hClose h
nukeFile tmpfile
- createLink file tmpfile
- cache <- genInodeCache tmpfile
- return $ KeySource
- { keyFilename = file
- , contentLocation = tmpfile
- , inodeCache = cache
- }
+ withhardlink tmpfile `catchIO` const nohardlink
)
+ where
+ nohardlink = do
+ cache <- genInodeCache file
+ return $ KeySource
+ { keyFilename = file
+ , contentLocation = file
+ , inodeCache = cache
+ }
+ withhardlink tmpfile = do
+ createLink file tmpfile
+ cache <- genInodeCache tmpfile
+ return $ KeySource
+ { keyFilename = file
+ , contentLocation = tmpfile
+ , inodeCache = cache
+ }
{- Ingests a locked down file into the annex.
-
diff --git a/Command/ReKey.hs b/Command/ReKey.hs
index 05fd73f1b..d7b277fa6 100644
--- a/Command/ReKey.hs
+++ b/Command/ReKey.hs
@@ -7,8 +7,6 @@
module Command.ReKey where
-import System.PosixCompat.Files
-
import Common.Annex
import Command
import qualified Annex
@@ -17,7 +15,6 @@ import Annex.Content
import qualified Command.Add
import Logs.Web
import Logs.Location
-import Config
import Utility.CopyFile
def :: [Command]
@@ -49,18 +46,14 @@ perform file oldkey newkey = do
return True
next $ cleanup file oldkey newkey
-{- Make a hard link to the old key content, to avoid wasting disk space. -}
+{- Make a hard link to the old key content (when supported),
+ - to avoid wasting disk space. -}
linkKey :: Key -> Key -> Annex Bool
linkKey oldkey newkey = getViaTmpUnchecked newkey $ \tmp -> do
src <- calcRepo $ gitAnnexLocation oldkey
- ifM (liftIO $ doesFileExist tmp)
+ liftIO $ ifM (doesFileExist tmp)
( return True
- , ifM crippledFileSystem
- ( liftIO $ copyFileExternal src tmp
- , do
- liftIO $ createLink src tmp
- return True
- )
+ , createLinkOrCopy src tmp
)
cleanup :: FilePath -> Key -> Key -> CommandCleanup