We should put this retry logic into LockFile too, because DirCache uses that.

We could either keep this code here, or better, convert the class to use LockFile rather than its own custom logic.  The LockFile stuff is more robust anyway.