diff options
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r-- | Annex/Content.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs index 289a4f1b3..73cb6ab01 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -24,6 +24,8 @@ module Annex.Content ( withTmp, checkDiskSpace, moveAnnex, + linkAnnex, + LinkAnnexResult(..), sendAnnex, prepSendAnnex, removeAnnex, @@ -470,6 +472,28 @@ 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 LinkAnnexResult +linkAnnex key src = do + dest <- calcRepo (gitAnnexLocation key) + ifM (liftIO $ doesFileExist dest) + ( return LinkAnnexNoop + , modifyContent dest $ + ifM (liftIO $ createLinkOrCopy src dest) + ( return LinkAnnexOk + , return LinkAnnexFailed + ) + ) + +data LinkAnnexResult = LinkAnnexOk | LinkAnnexFailed | LinkAnnexNoop + {- 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. |