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)
|
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
|
2011-05-17 07:10:13 +00:00
|
|
|
import Utility
|
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
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ 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-05-17 07:10:13 +00:00
|
|
|
unlessM (Backend.hasKey key) $ 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
|
2011-06-21 02:38:18 +00:00
|
|
|
let tmpdest = gitAnnexTmpLocation g key
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
|
2010-11-09 19:59:49 +00:00
|
|
|
showNote "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
|
2010-11-18 17:48:28 +00:00
|
|
|
else error "copy failed!"
|