summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Content.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 289a4f1b3..74fae381b 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -24,6 +24,7 @@ module Annex.Content (
withTmp,
checkDiskSpace,
moveAnnex,
+ linkAnnex,
sendAnnex,
prepSendAnnex,
removeAnnex,
@@ -470,6 +471,23 @@ moveAnnex key src = withObjectLoc key storeobject storedirect
alreadyhave = liftIO $ removeFile src
+{- Hard links a file into .git/annex/objects/, falling back to a copy
+ - if necessary.
+ -
+ - Does not lock down the hard linked object, so that the user can modify
+ - the source file. So, adding an object to the annex this way can
+ - prevent losing the content if the source file is deleted, but does not
+ - guard against modifications.
+ -}
+linkAnnex :: Key -> FilePath -> Annex Bool
+linkAnnex key src = do
+ dest <- calcRepo (gitAnnexLocation key)
+ ifM (liftIO $ doesFileExist dest)
+ ( return True
+ , modifyContent dest $
+ liftIO $ createLinkOrCopy src dest
+ )
+
{- Runs an action to transfer an object's content.
-
- In direct mode, it's possible for the file to change as it's being sent.