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.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Fix where
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
import System.Posix.Files
|
|
|
|
import System.Directory
|
|
|
|
|
|
|
|
import Command
|
2011-04-07 17:59:31 +00:00
|
|
|
import qualified AnnexQueue
|
2011-08-22 20:14:12 +00:00
|
|
|
import Utility.Path
|
|
|
|
import Utility.SafeCommand
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "fix" paramPath seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"fix up symlinks to point to annexed content"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withFilesInGit start]
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- Fixes the symlink to an annexed file. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2010-11-02 23:04:24 +00:00
|
|
|
start file = isAnnexed file $ \(key, _) -> do
|
|
|
|
link <- calcGitLink file key
|
|
|
|
l <- liftIO $ readSymbolicLink file
|
2010-11-22 21:51:55 +00:00
|
|
|
if link == l
|
2011-05-15 06:02:46 +00:00
|
|
|
then stop
|
2010-11-02 23:04:24 +00:00
|
|
|
else do
|
|
|
|
showStart "fix" file
|
2011-05-15 06:02:46 +00:00
|
|
|
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
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
|
|
|
liftIO $ removeFile file
|
|
|
|
liftIO $ createSymbolicLink link file
|
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
|
2011-07-14 20:56:06 +00:00
|
|
|
AnnexQueue.add "add" [Param "--"] [file]
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|