diff options
author | Joey Hess <joeyh@joeyh.name> | 2018-03-07 14:13:02 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2018-03-07 14:23:52 -0400 |
commit | 599258b9442b776dc4079d3e42f4794fa8345c80 (patch) | |
tree | 185957a33baee91c7073c5c3db82d1383004b0b7 /Annex/Content.hs | |
parent | 0b98b883e40d1019ff9cdcd6c9ff58079ffe68b6 (diff) |
make sure that lockContentShared is always paired with an inAnnex check
lockContentShared had a screwy caveat that it didn't verify that the content
was present when locking it, but in the most common case, eg indirect mode,
it failed to lock when the content is not present.
That led to a few callers forgetting to check inAnnex when using it,
but the potential data loss was unlikely to be noticed because it only
affected direct mode I think.
Fix data loss bug when the local repository uses direct mode, and a
locally modified file is dropped from a remote repsitory. The bug
caused the modified file to be counted as a copy of the original file.
(This is not a severe bug because in such a situation, dropping
from the remote and then modifying the file is allowed and has the same
end result.)
And, in content locking over tor, when the remote repository is
in direct mode, it neglected to check that the content was actually
present when locking it. This could cause git annex drop to remove
the only copy of a file when it thought the tor remote had a copy.
So, make lockContentShared do its own inAnnex check. This could perhaps
be optimised for direct mode, to avoid the check then, since locking
the content necessarily verifies it exists there, but I have not bothered
with that.
This commit was sponsored by Jeff Goeke-Smith on Patreon.
Diffstat (limited to 'Annex/Content.hs')
-rw-r--r-- | Annex/Content.hs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs index 768b2a9dc..6542804f7 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -196,19 +196,19 @@ contentLockFile key = Just <$> calcRepo (gitAnnexContentLock key) {- Prevents the content from being removed while the action is running. - Uses a shared lock. - - - Does not actually check if the content is present. Use inAnnex for that. - - However, since the contentLockFile is the content file in indirect mode, - - if the content is not present, locking it will fail. - - - - If locking fails, throws an exception rather than running the action. + - If locking fails, or the content is not present, throws an exception + - rather than running the action. - - Note that, in direct mode, nothing prevents the user from directly - editing or removing the content, even while it's locked by this. -} lockContentShared :: Key -> (VerifiedCopy -> Annex a) -> Annex a -lockContentShared key a = lockContentUsing lock key $ do - u <- getUUID - withVerifiedCopy LockedCopy u (return True) a +lockContentShared key a = lockContentUsing lock key $ ifM (inAnnex key) + ( do + u <- getUUID + withVerifiedCopy LockedCopy u (return True) a + , giveup $ "failed to lock content: not present" + ) where #ifndef mingw32_HOST_OS lock contentfile Nothing = tryLockShared Nothing contentfile |