2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-07-11 15:39:42 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
module Command.Fix where
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import qualified Annex.Queue
|
2013-11-13 01:05:04 +00:00
|
|
|
#ifdef WITH_CLIBS
|
2013-07-11 15:39:42 +00:00
|
|
|
#ifndef __ANDROID__
|
|
|
|
import Utility.Touch
|
|
|
|
#endif
|
2013-11-13 01:05:04 +00:00
|
|
|
#endif
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
2012-12-29 18:28:19 +00:00
|
|
|
def = [notDirect $ noCommit $ command "fix" paramPaths seek
|
2013-03-24 22:28:21 +00:00
|
|
|
SectionMaintenance "fix up symlinks to point to annexed content"]
|
2010-12-30 19:06:26 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek :: CommandSeek
|
|
|
|
seek = withFilesInGit $ whenAnnexed start
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- Fixes the symlink to an annexed file. -}
|
2011-12-31 08:11:39 +00:00
|
|
|
start :: FilePath -> (Key, Backend) -> CommandStart
|
2011-11-11 03:35:08 +00:00
|
|
|
start file (key, _) = do
|
2013-04-04 19:46:33 +00:00
|
|
|
link <- inRepo $ gitAnnexLink file key
|
2013-01-05 20:07:27 +00:00
|
|
|
stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
|
2011-12-09 16:23:45 +00:00
|
|
|
showStart "fix" file
|
|
|
|
next $ perform file link
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: FilePath -> FilePath -> CommandPerform
|
2010-11-02 23:04:24 +00:00
|
|
|
perform file link = do
|
2013-07-11 15:39:42 +00:00
|
|
|
liftIO $ do
|
2013-11-13 01:05:04 +00:00
|
|
|
#ifdef WITH_CLIBS
|
2013-07-11 15:39:42 +00:00
|
|
|
#ifndef __ANDROID__
|
|
|
|
-- preserve mtime of symlink
|
|
|
|
mtime <- catchMaybeIO $ TimeSpec . modificationTime
|
|
|
|
<$> getSymbolicLinkStatus file
|
2013-11-13 01:05:04 +00:00
|
|
|
#endif
|
2013-07-11 15:39:42 +00:00
|
|
|
#endif
|
|
|
|
createDirectoryIfMissing True (parentDir file)
|
|
|
|
removeFile file
|
|
|
|
createSymbolicLink link file
|
2013-11-13 01:05:04 +00:00
|
|
|
#ifdef WITH_CLIBS
|
2013-07-11 15:39:42 +00:00
|
|
|
#ifndef __ANDROID__
|
|
|
|
maybe noop (\t -> touch file t False) mtime
|
2013-11-13 01:05:04 +00:00
|
|
|
#endif
|
2013-07-11 15:39:42 +00:00
|
|
|
#endif
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ cleanup file
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: FilePath -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup file = do
|
2012-06-07 19:19:44 +00:00
|
|
|
Annex.Queue.addCommand "add" [Param "--force", Param "--"] [file]
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|