summaryrefslogtreecommitdiff
path: root/Annex/Link.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-04-02 13:13:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-04-02 15:02:00 -0400
commit56835693f551bdd07f6a840cce2d760098eebd82 (patch)
tree576a80009ea1cb6fe05f9a196f8421583457fcdf /Annex/Link.hs
parent8ba1f8f3327288bba9e27081d1aa651adbaa1e3e (diff)
Update working tree files fully atomically
This avoids commit churn by the assistant when eg, replacing a file with a symlink. But, just as importantly, it prevents the working tree being left with a deleted file if git-annex, or perhaps the whole system, crashes at the wrong time. (It also probably avoids confusing displays in file managers.)
Diffstat (limited to 'Annex/Link.hs')
-rw-r--r--Annex/Link.hs4
1 files changed, 3 insertions, 1 deletions
diff --git a/Annex/Link.hs b/Annex/Link.hs
index 650fc19a1..931836d31 100644
--- a/Annex/Link.hs
+++ b/Annex/Link.hs
@@ -60,7 +60,9 @@ getAnnexLinkTarget file = do
-}
makeAnnexLink :: LinkTarget -> FilePath -> Annex ()
makeAnnexLink linktarget file = ifM (coreSymlinks <$> Annex.getGitConfig)
- ( liftIO $ createSymbolicLink linktarget file
+ ( liftIO $ do
+ void $ tryIO $ removeFile file
+ createSymbolicLink linktarget file
, liftIO $ writeFile file linktarget
)