Fix race in cleanup of othertmp directory that could result in a failure attempting to access it.

Need to create the directory after the lock is held, not before.

The other racing process would need to shut down at just the wrong time,
running cleanupOtherTmp.

This commit was sponsored by Boyd Stephen Smith Jr. on Patreon.
This commit is contained in:
Joey Hess 2019-02-02 13:56:31 -04:00
parent aff2fd33b3
commit a64fca92f6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 5 additions and 2 deletions

View file

@ -27,8 +27,9 @@ withOtherTmp a = do
addCleanup OtherTmpCleanup cleanupOtherTmp
tmpdir <- fromRepo gitAnnexTmpOtherDir
tmplck <- fromRepo gitAnnexTmpOtherLock
void $ createAnnexDirectory tmpdir
withSharedLock (const tmplck) (a tmpdir)
withSharedLock (const tmplck) $ do
void $ createAnnexDirectory tmpdir
a tmpdir
-- | Cleans up any tmp files that were left by a previous
-- git-annex process that got interrupted or failed to clean up after