summaryrefslogtreecommitdiff
path: root/Command/Add.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-06-10 13:10:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-06-10 13:11:33 -0400
commita5cb4a7bc5d7d603fc8f5f8b1a1595e889fb25ce (patch)
tree9b1e97311129413c5e0d33e9b52caa0ab66809dc /Command/Add.hs
parent7bf5b7b0c5ba2789ef1473329da0000af0410b61 (diff)
Supports indirect mode on encfs in paranoia mode, and other filesystems that do not support hard links, but do support symlinks and other POSIX filesystem features.
Diffstat (limited to 'Command/Add.hs')
-rw-r--r--Command/Add.hs43
1 files changed, 27 insertions, 16 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.
-