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
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import qualified Annex.Queue
|
|
|
|
import Annex.Content
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-10-27 22:56:54 +00:00
|
|
|
command = [Command "fix" paramPaths defaultChecks 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. -}
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: FilePath -> CommandStart
|
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-10-04 04:40:47 +00:00
|
|
|
Annex.Queue.add "add" [Param "--"] [file]
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|