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 =
|
2011-03-19 22:58:49 +00:00
|
|
|
[ repoCommand "unlock" paramPath seek "unlock files for modification"
|
|
|
|
, repoCommand "edit" paramPath seek "same as unlock"
|
2010-12-30 19:06:26 +00:00
|
|
|
]
|
|
|
|
|
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"
|
2011-03-22 21:27:04 +00:00
|
|
|
|
|
|
|
checkDiskSpace key
|
2011-01-14 04:02:33 +00:00
|
|
|
|
2010-11-09 19:59:49 +00:00
|
|
|
g <- Annex.gitRepo
|
2011-01-27 21:00:32 +00:00
|
|
|
let src = gitAnnexLocation g key
|
2010-11-09 19:59:49 +00:00
|
|
|
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!"
|