blob: 9db832cc76e43392dd1a9922e38f99a4a7f04d40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
{- 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
import Messages
{- 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
|