git-annex/Command/Unlock.hs

55 lines
1.2 KiB
Haskell
Raw Normal View History

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
import Control.Monad (when)
2010-11-09 19:59:49 +00:00
import Control.Monad.State (liftIO)
import System.Directory hiding (copyFile)
2010-11-09 19:59:49 +00:00
import Command
import qualified Annex
import qualified Backend
2010-11-09 19:59:49 +00:00
import Types
import Messages
import Locations
import Content
import CopyFile
2010-11-09 19:59:49 +00:00
command :: [Command]
command =
[ Command "unlock" paramPath seek "unlock files for modification"
, Command "edit" paramPath seek "same as unlock"
]
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. -}
start :: CommandStartString
2010-11-09 19:59:49 +00:00
start file = isAnnexed file $ \(key, _) -> do
showStart "unlock" file
return $ Just $ perform file key
2010-11-09 19:59:49 +00:00
perform :: FilePath -> Key -> CommandPerform
2010-11-09 19:59:49 +00:00
perform dest key = do
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..."
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
else error "copy failed!"