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-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-09 19:59:49 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-07-06 00:24:10 +00:00
|
|
|
import Utility.CopyFile
|
2011-09-23 22:13:24 +00:00
|
|
|
import Utility.FileMode
|
2010-11-09 19:59:49 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
|
|
|
def =
|
2011-10-27 20:31:35 +00:00
|
|
|
[ c "unlock" "unlock files for modification"
|
|
|
|
, c "edit" "same as unlock"
|
2010-12-30 19:06:26 +00:00
|
|
|
]
|
2011-10-27 20:31:35 +00:00
|
|
|
where
|
2011-10-29 19:19:05 +00:00
|
|
|
c n = command n paramPaths seek
|
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. -}
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: FilePath -> CommandStart
|
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-07-05 22:31:46 +00:00
|
|
|
unlessM (inAnnex key) $ error "content not present"
|
2011-03-22 21:27:04 +00:00
|
|
|
|
|
|
|
checkDiskSpace key
|
2011-01-14 04:02:33 +00:00
|
|
|
|
2011-11-08 19:34:10 +00:00
|
|
|
src <- fromRepo $ gitAnnexLocation key
|
|
|
|
tmpdest <- fromRepo $ gitAnnexTmpLocation key
|
2011-06-21 02:38:18 +00:00
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
|
2011-07-19 18:07:23 +00:00
|
|
|
showAction "copying"
|
2011-10-04 02:24:57 +00:00
|
|
|
ok <- liftIO $ copyFileExternal 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!"
|