2010-11-02 19:04:24 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Fix where
|
|
|
|
|
2011-10-05 16:02:51 -04:00
|
|
|
import Common.Annex
|
2010-11-02 19:04:24 -04:00
|
|
|
import Command
|
2011-10-04 00:40:47 -04:00
|
|
|
import qualified Annex.Queue
|
|
|
|
import Annex.Content
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-10-29 15:19:05 -04:00
|
|
|
def :: [Command]
|
|
|
|
def = [command "fix" paramPaths seek
|
2010-12-30 15:06:26 -04:00
|
|
|
"fix up symlinks to point to annexed content"]
|
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
seek :: [CommandSeek]
|
2011-11-10 23:35:08 -04:00
|
|
|
seek = [withFilesInGit $ whenAnnexed start]
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2010-11-02 19:04:24 -04:00
|
|
|
{- Fixes the symlink to an annexed file. -}
|
2011-12-31 04:11:39 -04:00
|
|
|
start :: FilePath -> (Key, Backend) -> CommandStart
|
2011-11-10 23:35:08 -04:00
|
|
|
start file (key, _) = do
|
2010-11-02 19:04:24 -04:00
|
|
|
link <- calcGitLink file key
|
2011-12-09 12:23:45 -04:00
|
|
|
stopUnless ((/=) link <$> liftIO (readSymbolicLink file)) $ do
|
|
|
|
showStart "fix" file
|
|
|
|
next $ perform file link
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
perform :: FilePath -> FilePath -> CommandPerform
|
2010-11-02 19:04:24 -04:00
|
|
|
perform file link = do
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
|
|
|
liftIO $ removeFile file
|
|
|
|
liftIO $ createSymbolicLink link file
|
2011-05-15 02:02:46 -04:00
|
|
|
next $ cleanup file
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
cleanup :: FilePath -> CommandCleanup
|
2010-11-02 19:04:24 -04:00
|
|
|
cleanup file = do
|
2011-11-07 18:10:31 -04:00
|
|
|
Annex.Queue.add "add" [Param "--force", Param "--"] [file]
|
2010-11-02 19:04:24 -04:00
|
|
|
return True
|