aboutsummaryrefslogtreecommitdiff
path: root/Annex/Content.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-11 10:42:18 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-11 10:42:18 -0400
commitd769454704555d7e969754de22e32fd7ed738aaa (patch)
treedddb324eee4df842b731e43047dc70b6190ba4e5 /Annex/Content.hs
parent9e0360d0343575a03dce9f90e7d72c0c56deed1a (diff)
wip
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r--Annex/Content.hs37
1 files changed, 20 insertions, 17 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 10a59ae95..912831db5 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -41,6 +41,7 @@ module Annex.Content (
dirKeys,
withObjectLoc,
staleKeysPrune,
+ isUnmodified,
) where
import System.IO.Unsafe (unsafeInterleaveIO)
@@ -634,10 +635,21 @@ removeAnnex (ContentRemovalLock key) = withObjectLoc key remove removedirect
remove file = cleanObjectLoc key $ do
secureErase file
liftIO $ nukeFile file
- mapM_ (void . tryIO . resetPointerFile key)
+ mapM_ (void . tryIO . resetpointer)
=<< Database.Keys.getAssociatedFiles key
Database.Keys.removeInodeCaches key
Direct.removeInodeCache key
+ resetpointer file = ifM (isUnmodified key file)
+ ( do
+ secureErase file
+ liftIO $ nukeFile file
+ liftIO $ writeFile file (formatPointer key)
+ -- Can't delete the pointer file.
+ -- If it was a hard link to the annex object,
+ -- that object might have been frozen as part of the
+ -- removal process, so thaw it.
+ , void $ tryIO $ thawContent file
+ )
removedirect fs = do
cache <- Direct.recordedInodeCache key
Direct.removeInodeCache key
@@ -647,25 +659,16 @@ removeAnnex (ContentRemovalLock key) = withObjectLoc key remove removedirect
secureErase f
replaceFile f $ makeAnnexLink l
-{- To safely reset a pointer file, it has to be the unmodified content of
- - the key. The expensive way to tell is to do a verification of its content.
+{- Check if a file contains the unmodified content of the key.
+ -
+ - The expensive way to tell is to do a verification of its content.
- The cheaper way is to see if the InodeCache for the key matches the
- file. -}
-resetPointerFile :: Key -> FilePath -> Annex ()
-resetPointerFile key f = go =<< geti
+isUnmodified :: Key -> FilePath -> Annex Bool
+isUnmodified key f = go =<< geti
where
- go Nothing = noop
- go (Just fc) = ifM (cheapcheck fc <||> expensivecheck fc)
- ( do
- secureErase f
- liftIO $ nukeFile f
- liftIO $ writeFile f (formatPointer key)
- -- Can't delete the pointer file.
- -- If it was a hard link to the annex object,
- -- that object might have been frozen as part of the
- -- removal process, so thaw it.
- , thawContent f
- )
+ go Nothing = return False
+ go (Just fc) = cheapcheck fc <||> expensivecheck fc
cheapcheck fc = anyM (compareInodeCaches fc)
=<< Database.Keys.getInodeCaches key
expensivecheck fc = ifM (verifyKeyContent AlwaysVerify Types.Remote.UnVerified key f)