git-annex/Command/Fix.hs

44 lines
1,019 B
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
2011-10-04 04:40:47 +00:00
import Annex.Common
import Command
2011-10-04 04:40:47 +00:00
import qualified Annex.Queue
import Annex.Content
command :: [Command]
2011-09-15 18:33:37 +00:00
command = [repoCommand "fix" paramPaths 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 :: FilePath -> CommandStart
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
else do
showStart "fix" file
2011-05-15 06:02:46 +00:00
next $ perform file link
perform :: FilePath -> FilePath -> CommandPerform
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
cleanup :: FilePath -> CommandCleanup
cleanup file = do
2011-10-04 04:40:47 +00:00
Annex.Queue.add "add" [Param "--"] [file]
return True