Fix space leak in fsck and drop commands.

The space leak was somehow caused by this line:

	absfiles <- mapM absPath files

I confess, I don't quite understand why this caused bad buffering,
but apparently the whole pipeline from git-ls-files backed up at that
point.

Happily, rewriting the code to only get the cwd once and use a pure
function to calculate absfiles clears it up, and should be a little more
efficient in syscalls too.
This commit is contained in:
Joey Hess 2011-03-22 20:31:22 -04:00
parent 5d75919561
commit c1dc407941
4 changed files with 12 additions and 5 deletions

View file

@ -132,8 +132,7 @@ withAttrFilesInGit :: String -> CommandSeekAttrFiles
withAttrFilesInGit attr a params = do withAttrFilesInGit attr a params = do
repo <- Annex.gitRepo repo <- Annex.gitRepo
files <- liftIO $ runPreserveOrder (Git.inRepo repo) params files <- liftIO $ runPreserveOrder (Git.inRepo repo) params
files' <- filterFiles files liftM (map a) $ liftIO $ Git.checkAttr repo attr files
liftM (map a) $ liftIO $ Git.checkAttr repo attr files'
withBackendFilesInGit :: CommandSeekBackendFiles withBackendFilesInGit :: CommandSeekBackendFiles
withBackendFilesInGit a params = do withBackendFilesInGit a params = do
repo <- Annex.gitRepo repo <- Annex.gitRepo

View file

@ -449,9 +449,9 @@ checkAttr repo attr files = do
-- top of the repo). But we're passed files relative to the current -- top of the repo). But we're passed files relative to the current
-- directory. Convert to absolute, and then convert the filenames -- directory. Convert to absolute, and then convert the filenames
-- in its output back to relative. -- in its output back to relative.
absfiles <- mapM absPath files
(_, s) <- pipeBoth "git" (toCommand params) $ join "\0" absfiles
cwd <- getCurrentDirectory cwd <- getCurrentDirectory
let absfiles = map (absPathFrom cwd) files
(_, s) <- pipeBoth "git" (toCommand params) $ join "\0" absfiles
return $ map (topair $ cwd++"/") $ lines s return $ map (topair $ cwd++"/") $ lines s
where where
params = gitCommandLine repo [Param "check-attr", Param attr, Params "-z --stdin"] params = gitCommandLine repo [Param "check-attr", Param attr, Params "-z --stdin"]

View file

@ -12,6 +12,7 @@ module Utility (
readFileStrict, readFileStrict,
parentDir, parentDir,
absPath, absPath,
absPathFrom,
relPathCwdToDir, relPathCwdToDir,
relPathDirToDir, relPathDirToDir,
boolSystem, boolSystem,
@ -165,8 +166,14 @@ dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b'
absPath :: FilePath -> IO FilePath absPath :: FilePath -> IO FilePath
absPath file = do absPath file = do
cwd <- getCurrentDirectory cwd <- getCurrentDirectory
return $ absPathFrom cwd file
{- Converts a filename into a normalized, absolute path
- from the specified cwd. -}
absPathFrom :: FilePath -> FilePath -> FilePath
absPathFrom cwd file =
case absNormPath cwd file of case absNormPath cwd file of
Just f -> return f Just f -> f
Nothing -> error $ "unable to normalize " ++ file Nothing -> error $ "unable to normalize " ++ file
{- Constructs a relative path from the CWD to a directory. {- Constructs a relative path from the CWD to a directory.

1
debian/changelog vendored
View file

@ -12,6 +12,7 @@ git-annex (0.20110321) UNRELEASED; urgency=low
* fsck: In fast mode, avoid checking checksums. * fsck: In fast mode, avoid checking checksums.
* unused: In fast mode, just show all existing temp files as unused, * unused: In fast mode, just show all existing temp files as unused,
and avoid expensive scan for other unused content. and avoid expensive scan for other unused content.
* Fix space leak in fsck and drop commands.
-- Joey Hess <joeyh@debian.org> Tue, 22 Mar 2011 16:52:00 -0400 -- Joey Hess <joeyh@debian.org> Tue, 22 Mar 2011 16:52:00 -0400