git-annex/Command/Unlock.hs

59 lines
1.3 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.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
import Content
import Utility.Conditional
2011-07-06 00:24:10 +00:00
import Utility.CopyFile
import Utility.Path
2010-11-09 19:59:49 +00:00
command :: [Command]
command =
[ repoCommand "unlock" paramPath seek "unlock files for modification"
, repoCommand "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
2011-05-15 06:02:46 +00:00
next $ 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
unlessM (inAnnex key) $ error "content not present"
checkDiskSpace key
2010-11-09 19:59:49 +00:00
g <- Annex.gitRepo
let src = gitAnnexLocation g key
2011-06-21 02:38:18 +00:00
let tmpdest = gitAnnexTmpLocation g key
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
showAction "copying"
2011-06-21 02:38:18 +00:00
ok <- liftIO $ copyFile src tmpdest
2010-11-09 19:59:49 +00:00
if ok
2010-11-10 16:50:00 +00:00
then do
2011-06-21 02:38:18 +00:00
liftIO $ do
removeFile dest
renameFile tmpdest dest
allowWrite dest
2011-05-15 06:02:46 +00:00
next $ return True
else error "copy failed!"