git-annex/Command/Unlock.hs

43 lines
962 B
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.State (liftIO)
import System.Directory hiding (copyFile)
2010-11-09 19:59:49 +00:00
import Command
import qualified Annex
import Types
import Messages
import Locations
2010-11-10 16:50:00 +00:00
import Core
import CopyFile
2010-11-09 19:59:49 +00:00
2010-11-11 22:54:52 +00:00
seek :: [SubCmdSeek]
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 :: SubCmdStartString
start file = isAnnexed file $ \(key, _) -> do
showStart "unlock" file
return $ Just $ perform file key
perform :: FilePath -> Key -> SubCmdPerform
perform dest key = do
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!"