diff options
author | Joey Hess <joey@kitenet.net> | 2010-11-02 19:04:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-11-02 19:04:24 -0400 |
commit | 0eae5b806c76b0fa3e21fbae6e5f2d9a39a04cce (patch) | |
tree | 53aada39ec10bc6217507bce1a9add3b86b3793b /Command/Fix.hs | |
parent | 606ed6bb3566fa86c1783e3f1c7d799a6f1be8d1 (diff) |
broke subcommands out into separate modules
Diffstat (limited to 'Command/Fix.hs')
-rw-r--r-- | Command/Fix.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Command/Fix.hs b/Command/Fix.hs new file mode 100644 index 000000000..90257a8a5 --- /dev/null +++ b/Command/Fix.hs @@ -0,0 +1,40 @@ +{- 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 Core + +{- Fixes the symlink to an annexed file. -} +start :: SubCmdStartString +start file = isAnnexed file $ \(key, _) -> do + link <- calcGitLink file key + l <- liftIO $ readSymbolicLink file + if (link == l) + then return Nothing + else do + showStart "fix" file + return $ Just $ perform file link + +perform :: FilePath -> FilePath -> SubCmdPerform +perform file link = do + liftIO $ createDirectoryIfMissing True (parentDir file) + liftIO $ removeFile file + liftIO $ createSymbolicLink link file + return $ Just $ cleanup file + +cleanup :: FilePath -> SubCmdCleanup +cleanup file = do + Annex.queue "add" [] file + return True |