]> dgit.raspbian.org Git - git-annex.git/commitdiff
prevent removeKey from annexobjects=yes remote when the key is in the exported tree
authorJoey Hess <joeyh@joeyh.name>
Fri, 2 Aug 2024 20:45:52 +0000 (16:45 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 2 Aug 2024 20:45:52 +0000 (16:45 -0400)
Removing the key from the annexobjects location when it's in the
exported tree would leave it in the exported tree, and so succeeding
would update the location log incorrectly. But this also can't remove it
from the exported tree, because that would cause import tree to see a
file got deleted. So, refuse to remove in this situation.

It would be possible to remove from the annexobjects location and then
fail. Then if a key somehow got stored in both the annexobjects location
and the exported tree location(s), the duplicate would be resolved. Not
doing this because first, I don't know how that situation could happen,
and second, it seems wrong for a failed remove to have a side-effect
like that.

Remote/Helper/ExportImport.hs

index 6840055f6f338f255321b895fc6d49a7fbe8fe84..73137c728aeae4806ed394024539f63e74c399e1 100644 (file)
@@ -175,7 +175,7 @@ adjustExportImport' isexport isimport annexobjects r rs gc = do
                                then giveup "dropping content from this remote is not supported"
                                else if isexport
                                        then if annexobjects
-                                               then removeannexobject k
+                                               then removeannexobject dbv k
                                                else giveup "dropping content from an export is not supported; use `git annex export` to export a tree that lacks the files you want to remove"
                                        else if isimport
                                                then giveup "dropping content from this remote is not supported because it is configured with importtree=yes"
@@ -427,8 +427,15 @@ adjustExportImport' isexport isimport annexobjects r rs gc = do
                                        removeExport (exportActions r) k loc
                                        giveup err
 
-       removeannexobject k = 
-               removeExport (exportActions r) k (annexobjectlocation k)
+       removeannexobject dbv k = 
+               getanyexportlocs dbv k >>= \case
+                       [] -> ifM (isexportinconflict dbv)
+                               ( do
+                                       warnExportImportConflict r
+                                       giveup "Cannot remove content from the remote until the conflict has been resolved."
+                               , removeExport (exportActions r) k (annexobjectlocation k)
+                               )
+                       _ -> giveup "This key is part of the exported tree, so can only be removed by exporting a tree that does not include it."
 
        retrieveannexobject k dest p =
                retrieveExport (exportActions r) k (annexobjectlocation k) dest p