aboutsummaryrefslogtreecommitdiff
path: root/Command/Unannex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-04-15 14:23:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-04-15 14:23:08 -0400
commite110fd9b8b87fcb6da2ecdac0a93a1f71f80552f (patch)
treea227f6797f15bfa3ad3310ff5a447b7cf9b81584 /Command/Unannex.hs
parent1fc480e5664930992fbd697c27cc365191d873d3 (diff)
found a way to make uninit always fast
To do so, I slightly changed the behavior of unannex. Now in fast mode, it only makes a hard link when the annexed file's link count is 1. This avoids unannexing 2 files with the same content in fast mode from hard linking them together. (One will end up hard linked to the annex, which the docs warn about.) With that change, uninit can simply always run unannex in fast mode. Since .git/annex/objects is being blown away anyway, there's no worry in this case about a hard link pointing into it causing an annexed object to be modified.
Diffstat (limited to 'Command/Unannex.hs')
-rw-r--r--Command/Unannex.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/Command/Unannex.hs b/Command/Unannex.hs
index 3da7c2a41..ca9788ddb 100644
--- a/Command/Unannex.hs
+++ b/Command/Unannex.hs
@@ -75,7 +75,16 @@ cleanupIndirect :: FilePath -> Key -> CommandCleanup
cleanupIndirect file key = do
src <- calcRepo $ gitAnnexLocation key
ifM (Annex.getState Annex.fast)
- ( hardlinkfrom src
+ ( do
+ -- Only make a hard link if the annexed file does not
+ -- already have other hard links pointing at it.
+ -- This avoids unannexing (and uninit) ending up
+ -- hard linking files together, which would be
+ -- surprising.
+ s <- liftIO $ getFileStatus src
+ if linkCount s > 1
+ then copyfrom src
+ else hardlinkfrom src
, copyfrom src
)
where