init: Fix a reversion that broke initialization on systems that need to use pid locking
This brings back .git/annex/misctmp, but only for init. If an init is interrupted while probing using that temp directory, the files it left will get deleted 1 week later by a subsequent git-annex run.
This commit is contained in:
parent
07de0e7e9d
commit
94c75d2bd9
7 changed files with 42 additions and 13 deletions
|
@ -166,7 +166,7 @@ isInitialized = maybe Annex.Branch.hasSibling (const $ return True) =<< getVersi
|
|||
{- A crippled filesystem is one that does not allow making symlinks,
|
||||
- or removing write access from files. -}
|
||||
probeCrippledFileSystem :: Annex Bool
|
||||
probeCrippledFileSystem = withOtherTmp $ \tmp -> do
|
||||
probeCrippledFileSystem = withEventuallyCleanedOtherTmp $ \tmp -> do
|
||||
(r, warnings) <- liftIO $ probeCrippledFileSystem' tmp
|
||||
mapM_ warning warnings
|
||||
return r
|
||||
|
@ -229,7 +229,7 @@ probeLockSupport = do
|
|||
#ifdef mingw32_HOST_OS
|
||||
return True
|
||||
#else
|
||||
withOtherTmp $ \tmp -> do
|
||||
withEventuallyCleanedOtherTmp $ \tmp -> do
|
||||
let f = tmp </> "lockprobe"
|
||||
mode <- annexFileMode
|
||||
liftIO $ do
|
||||
|
@ -247,7 +247,7 @@ probeFifoSupport = do
|
|||
#ifdef mingw32_HOST_OS
|
||||
return False
|
||||
#else
|
||||
withOtherTmp $ \tmp -> do
|
||||
withEventuallyCleanedOtherTmp $ \tmp -> do
|
||||
let f = tmp </> "gaprobe"
|
||||
let f2 = tmp </> "gaprobe2"
|
||||
liftIO $ do
|
||||
|
|
|
@ -266,7 +266,8 @@ gitAnnexTmpOtherDir r = addTrailingPathSeparator $ gitAnnexDir r </> "othertmp"
|
|||
gitAnnexTmpOtherLock :: Git.Repo -> FilePath
|
||||
gitAnnexTmpOtherLock r = gitAnnexDir r </> "othertmp.lck"
|
||||
|
||||
{- Tmp directory used by old versions of git-annex. -}
|
||||
{- .git/annex/misctmp/ was used by old versions of git-annex and is still
|
||||
- used during initialization -}
|
||||
gitAnnexTmpOtherDirOld :: Git.Repo -> FilePath
|
||||
gitAnnexTmpOtherDirOld r = addTrailingPathSeparator $ gitAnnexDir r </> "misctmp"
|
||||
|
||||
|
|
26
Annex/Tmp.hs
26
Annex/Tmp.hs
|
@ -7,9 +7,8 @@
|
|||
|
||||
module Annex.Tmp where
|
||||
|
||||
import Common
|
||||
import Annex
|
||||
import Annex.Locations
|
||||
import Annex.Common
|
||||
import qualified Annex
|
||||
import Annex.LockFile
|
||||
import Annex.Perms
|
||||
import Types.CleanupActions
|
||||
|
@ -24,13 +23,30 @@ import Data.Time.Clock.POSIX
|
|||
-- any time.
|
||||
withOtherTmp :: (FilePath -> Annex a) -> Annex a
|
||||
withOtherTmp a = do
|
||||
addCleanup OtherTmpCleanup cleanupOtherTmp
|
||||
Annex.addCleanup OtherTmpCleanup cleanupOtherTmp
|
||||
tmpdir <- fromRepo gitAnnexTmpOtherDir
|
||||
tmplck <- fromRepo gitAnnexTmpOtherLock
|
||||
withSharedLock (const tmplck) $ do
|
||||
void $ createAnnexDirectory tmpdir
|
||||
a tmpdir
|
||||
|
||||
-- | This uses an alternate temp directory. The action should normally
|
||||
-- clean up whatever files it writes there, but if it leaves files
|
||||
-- there (perhaps due to being interrupted), the files will be eventually
|
||||
-- cleaned up by another git-annex process (after they're a week old).
|
||||
--
|
||||
-- Unlike withOtherTmp, this does not rely on locking working.
|
||||
-- Its main use is in situations where the state of lockfile is not
|
||||
-- determined yet, eg during initialization.
|
||||
withEventuallyCleanedOtherTmp :: (FilePath -> Annex a) -> Annex a
|
||||
withEventuallyCleanedOtherTmp = bracket setup cleanup
|
||||
where
|
||||
setup = do
|
||||
tmpdir <- fromRepo gitAnnexTmpOtherDirOld
|
||||
void $ createAnnexDirectory tmpdir
|
||||
return tmpdir
|
||||
cleanup = liftIO . void . tryIO . removeDirectory
|
||||
|
||||
-- | Cleans up any tmp files that were left by a previous
|
||||
-- git-annex process that got interrupted or failed to clean up after
|
||||
-- itself for some other reason.
|
||||
|
@ -42,8 +58,6 @@ cleanupOtherTmp = do
|
|||
void $ tryIO $ tryExclusiveLock (const tmplck) $ do
|
||||
tmpdir <- fromRepo gitAnnexTmpOtherDir
|
||||
void $ liftIO $ tryIO $ removeDirectoryRecursive tmpdir
|
||||
-- This is only to clean up cruft left by old versions of
|
||||
-- git-annex; it can be removed eventually.
|
||||
oldtmp <- fromRepo gitAnnexTmpOtherDirOld
|
||||
liftIO $ mapM_ cleanold =<< dirContentsRecursive oldtmp
|
||||
liftIO $ void $ tryIO $ removeDirectory oldtmp -- when empty
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue