git-annex/Command/Fix.hs

49 lines
1.1 KiB
Haskell
Raw Normal View History

{- 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
import qualified Annex
import Utility
import Content
2010-11-08 19:15:21 +00:00
import Messages
command :: [Command]
command = [repoCommand "fix" paramPath seek
"fix up symlinks to point to annexed content"]
seek :: [CommandSeek]
2010-11-11 22:54:52 +00:00
seek = [withFilesInGit start]
{- Fixes the symlink to an annexed file. -}
start :: CommandStartString
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
then return Nothing
else do
showStart "fix" file
return $ Just $ perform file link
perform :: FilePath -> FilePath -> CommandPerform
perform file link = do
liftIO $ createDirectoryIfMissing True (parentDir file)
liftIO $ removeFile file
liftIO $ createSymbolicLink link file
return $ Just $ cleanup file
cleanup :: FilePath -> CommandCleanup
cleanup file = do
Annex.queue "add" [Param "--"] file
return True