2010-11-09 19:59:49 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Unlock where
|
|
|
|
|
2011-01-14 04:02:33 +00:00
|
|
|
import Control.Monad (when)
|
2010-11-09 19:59:49 +00:00
|
|
|
import Control.Monad.State (liftIO)
|
2010-11-18 17:48:28 +00:00
|
|
|
import System.Directory hiding (copyFile)
|
2010-11-09 19:59:49 +00:00
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
2011-01-14 03:46:02 +00:00
|
|
|
import qualified Backend
|
2010-11-09 19:59:49 +00:00
|
|
|
import Types
|
|
|
|
import Messages
|
|
|
|
import Locations
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-18 17:48:28 +00:00
|
|
|
import CopyFile
|
2010-11-09 19:59:49 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
|
|
|
command =
|
|
|
|
[ Command "unlock" paramPath seek "unlock files for modification"
|
|
|
|
, Command "edit" paramPath seek "same as unlock"
|
|
|
|
]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withFilesInGit start]
|
|
|
|
|
2010-11-09 19:59:49 +00:00
|
|
|
{- The unlock subcommand replaces the symlink with a copy of the file's
|
|
|
|
- content. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2010-11-09 19:59:49 +00:00
|
|
|
start file = isAnnexed file $ \(key, _) -> do
|
2011-01-14 04:02:33 +00:00
|
|
|
showStart "unlock" file
|
|
|
|
return $ Just $ perform file key
|
2010-11-09 19:59:49 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2010-11-09 19:59:49 +00:00
|
|
|
perform dest key = do
|
2011-01-14 04:02:33 +00:00
|
|
|
inbackend <- Backend.hasKey key
|
|
|
|
when (not inbackend) $
|
|
|
|
error "content not present"
|
|
|
|
|
2010-11-09 19:59:49 +00:00
|
|
|
g <- Annex.gitRepo
|
|
|
|
let src = annexLocation g key
|
|
|
|
liftIO $ removeFile dest
|
|
|
|
showNote "copying..."
|
2010-11-18 17:48:28 +00:00
|
|
|
ok <- liftIO $ copyFile src dest
|
2010-11-09 19:59:49 +00:00
|
|
|
if ok
|
2010-11-10 16:50:00 +00:00
|
|
|
then do
|
|
|
|
liftIO $ allowWrite dest
|
|
|
|
return $ Just $ return True
|
2010-11-18 17:48:28 +00:00
|
|
|
else error "copy failed!"
|