git-annex/Command/Fix.hs

42 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 System.PosixCompat.Files
2011-10-05 20:02:51 +00:00
import Common.Annex
import Command
2011-10-04 04:40:47 +00:00
import qualified Annex.Queue
def :: [Command]
def = [notDirect $ noCommit $ command "fix" paramPaths seek
SectionMaintenance "fix up symlinks to point to annexed content"]
seek :: [CommandSeek]
seek = [withFilesInGit $ whenAnnexed start]
2010-11-11 22:54:52 +00:00
{- Fixes the symlink to an annexed file. -}
2011-12-31 08:11:39 +00:00
start :: FilePath -> (Key, Backend) -> CommandStart
start file (key, _) = do
link <- inRepo $ gitAnnexLink file key
stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
showStart "fix" file
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
Annex.Queue.addCommand "add" [Param "--force", Param "--"] [file]
return True