summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-04-30 14:03:24 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-04-30 14:04:36 -0400
commite0544f17c1ac482445ff1ae18a413be7cad68f2c (patch)
tree22c5fc754474185a76c202f1252c4f8306565c3a
parent42ae5fec8ebbb5921f91d2052bc18d595ead2cfa (diff)
import: Before removing a duplicate file in --deduplicate or --clean-duplicates mode, verify that enough copies of its content still exist.
-rw-r--r--Command/Import.hs24
-rw-r--r--debian/changelog3
-rw-r--r--doc/bugs/clean-duplicates_causes_data_loss.mdwn3
3 files changed, 28 insertions, 2 deletions
diff --git a/Command/Import.hs b/Command/Import.hs
index 261bd7b8e..58e4db38a 100644
--- a/Command/Import.hs
+++ b/Command/Import.hs
@@ -17,6 +17,9 @@ import Remote
import Types.KeySource
import Types.Key
import Annex.CheckIgnore
+import Annex.NumCopies
+import Types.TrustLevel
+import Logs.Trust
cmd :: [Command]
cmd = [withOptions opts $ notBareRepo $ command "import" paramPaths seek
@@ -76,8 +79,14 @@ start mode (srcfile, destfile) =
where
deletedup k = do
showNote $ "duplicate of " ++ key2file k
- liftIO $ removeFile srcfile
- next $ return True
+ ifM (verifiedExisting k destfile)
+ ( do
+ liftIO $ removeFile srcfile
+ next $ return True
+ , do
+ warning "could not verify that the content is still present in the annex; not removing from the import location"
+ stop
+ )
importfile = do
ignored <- not <$> Annex.getState Annex.force <&&> checkIgnored destfile
if ignored
@@ -120,3 +129,14 @@ start mode (srcfile, destfile) =
CleanDuplicates -> checkdup (Just deletedup) Nothing
SkipDuplicates -> checkdup Nothing (Just importfile)
_ -> return (Just importfile)
+
+verifiedExisting :: Key -> FilePath -> Annex Bool
+verifiedExisting key destfile = do
+ -- Look up the numcopies setting for the file that it would be
+ -- imported to, if it were imported.
+ need <- getFileNumCopies destfile
+
+ (remotes, trusteduuids) <- knownCopies key
+ untrusteduuids <- trustGet UnTrusted
+ let tocheck = Remote.remotesWithoutUUID remotes (trusteduuids++untrusteduuids)
+ verifyEnoughCopies [] key need trusteduuids [] tocheck
diff --git a/debian/changelog b/debian/changelog
index 2db52813e..ec53afd4f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,9 @@ git-annex (5.20150421) UNRELEASED; urgency=medium
* Improve integration with KDE's file manager to work with dolphin
version 14.12.3 while still being compatable with 4.14.2.
Thanks, silvio.
+ * import: Before removing a duplicate file in --deduplicate or
+ --clean-duplicates mode, verify that enough copies of its content still
+ exist.
-- Joey Hess <id@joeyh.name> Tue, 21 Apr 2015 15:54:10 -0400
diff --git a/doc/bugs/clean-duplicates_causes_data_loss.mdwn b/doc/bugs/clean-duplicates_causes_data_loss.mdwn
index df1f7e131..c5d545420 100644
--- a/doc/bugs/clean-duplicates_causes_data_loss.mdwn
+++ b/doc/bugs/clean-duplicates_causes_data_loss.mdwn
@@ -25,3 +25,6 @@ g-a import --clean-duplicates ~/tmp/importme (containing a, b and c) into 'impor
### Please provide any additional information below.
I can provide the script if it is wanted (coded in Perl, couple of non-core dependencies).
+
+> Decided to go ahead and make it check remotes like drop does, so [[done]]
+> --[[Joey]]