fix replaceFile makeAnnexLink race
authorJoey Hess <joeyh@joeyh.name>
Fri, 6 Nov 2015 19:08:19 +0000 (15:08 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 6 Nov 2015 19:08:19 +0000 (15:08 -0400)
commit51e60259e126a279b067f95c4849cbd32c60f961
tree263cd069dd38f77c9c62e0a51c0df92a43976faf
parent78b63888a6aa7967f3b27f8e65b47ac80668a961
fix replaceFile makeAnnexLink race

replaceFile created a temp file, which was guaranteed to not overlap with
another temp file. However, makeAnnexLink then deleted that file, in
preparation for making the symlink in its place. This caused a race, since
some other replaceFile could create a temp file, using the same name!

I was able to reproduce the race easily running git-annex add -J10 in a
directory with 100 files (all with different contents). Some files would
get ingested into the annex, but their annex links would fail to be added.

There could be other situations where this same problem could occur.
Perhaps when the assistant is adding a file, if the user manually also ran
git-annex add. Perhaps in cases not involving adding a file.

The new replaceFile makes a temprary directory, which is guaranteed to be
unique, and doesn't make a temp file in there. makeAnnexLink can thus
create the symlink without problem and the race is avoided.

Audited all calls to replaceFile to make sure that the old behavior of
providing an empty temp file was not relied on.

The general problem of asking for a temp file and deleting it as part of
the process of using it could reach beyond replaceFile. Did some quick
audits and didn't find other cases of it. Probably only symlink creation
stuff would tend to make that mistake, mostly.
Annex/ReplaceFile.hs
debian/changelog