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
|
||||
|
|
|
@ -25,6 +25,8 @@ git-annex (7.20190826) UNRELEASED; urgency=medium
|
|||
in working tree.
|
||||
* Avoid making a commit when upgrading from direct mode to v7.
|
||||
* init: Catch more exceptions when testing locking.
|
||||
* init: Fix a reversion that broke initialization on systems that
|
||||
need to use pid locking.
|
||||
|
||||
-- Joey Hess <id@joeyh.name> Sat, 24 Aug 2019 12:54:35 -0400
|
||||
|
||||
|
|
|
@ -42,7 +42,5 @@ running createProcess with this:
|
|||
|
||||
CreateProcess {cmdspec = RawCommand "git" ["update-index","--index-info"], cwd = Nothing, env = Just [("GIT_INDEX_FILE","/tmp/\56514\56481/.git/annex/index")], std_in = Inherit, std_out = Inherit, std_err = Inherit, close_fds = False, create_group = False, delegate_ctlc = False, detach_console = False, create_new_console = False, new_session = False, child_group = Nothing, child_user = Nothing, use_process_jobs = False}
|
||||
|
||||
This bug needs to be forwarded to http://hackage.haskell.org/process,
|
||||
after checking what environment value it actually passes to the child
|
||||
process in this case.
|
||||
This bug needs to be forwarded to process.
|
||||
"""]]
|
||||
|
|
|
@ -62,3 +62,5 @@ type nfs (rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp
|
|||
```
|
||||
|
||||
[[!meta author=yoh]]
|
||||
|
||||
> [[fixed|done]] --[[Joey]]
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[[!comment format=mdwn
|
||||
username="joey"
|
||||
subject="""comment 4"""
|
||||
date="2019-09-10T16:28:12Z"
|
||||
content="""
|
||||
Thanks for the bisection. It's not the init code that's
|
||||
trying and failing to set a lock, but the misctmp cleanup code. Which is
|
||||
ironically now used in setting up the temp directory that init uses to
|
||||
probe for locking problems. Chicken and egg problem.
|
||||
|
||||
Committed a fix.
|
||||
"""]]
|
Loading…
Reference in a new issue