Fix potential crash in exporttree database due to failure to honor uniqueness constraint

I don't know the circumstances, but have a report of this:

git-annex: failed to commit changes to sqlite database: Just SQLite3 returned
ErrorConstraint while attempting to perform step.

All 3 tables in the export db have uniqueness constraints on them,
insertUnique is used for all the rest, but this use of insertMany
means it doesn't check the constraint. I guess that's what caused the
crash, but I have not been able to test it yet.

Use putMany when available, as it should be faster than mapM of insertMany.

This commit was sponsored by Brock Spratlen on Patreon.
This commit is contained in:
Joey Hess 2018-10-09 16:56:33 -04:00
parent b8ed97f5d8
commit def5d8b02c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 5 additions and 3 deletions

View file

@ -12,6 +12,8 @@ git-annex (6.20180927) UNRELEASED; urgency=medium
that called them; this was not documented behavior and is no longer done.
* export: Fix false positive in export conflict detection, that occurred
when the same tree was exported by multiple clones.
* Fix potential crash in exporttree database due to failure to honor
uniqueness constraint.
-- Joey Hess <id@joeyh.name> Thu, 27 Sep 2018 15:27:20 -0400

View file

@ -126,10 +126,10 @@ addExportedLocation h k el = queueDb h $ do
let edirs = map
(\ed -> ExportedDirectory (toSFilePath (fromExportDirectory ed)) ef)
(exportDirectories el)
#if MIN_VERSION_persistent(2,1,0)
insertMany_ edirs
#if MIN_VERSION_persistent(2,8,1)
putMany edirs
#else
void $ insertMany edirs
mapM_ insertUnique edirs
#endif
where
ik = toIKey k