git-annex/Command/Unlock.hs

51 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
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
2010-11-09 19:59:49 +00:00
def :: [Command]
def =
[ c "unlock" "unlock files for modification"
, c "edit" "same as unlock"
]
2012-11-12 05:05:04 +00:00
where
c n = notDirect . command n paramPaths seek SectionCommon
seek :: CommandSeek
seek = withFilesInGit $ whenAnnexed start
2010-11-11 22:54:52 +00:00
2010-11-09 19:59:49 +00:00
{- The unlock subcommand replaces the symlink with a copy of the file's
- content. -}
2011-12-31 08:11:39 +00:00
start :: FilePath -> (Key, Backend) -> CommandStart
start 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"
unlessM (checkDiskSpace Nothing key 0) $ error "cannot unlock"
src <- calcRepo $ gitAnnexLocation key
tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key
2011-06-21 02:38:18 +00:00
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
showAction "copying"
2012-12-13 04:45:27 +00:00
ifM (liftIO $ copyFileExternal src tmpdest)
( do
2011-06-21 02:38:18 +00:00
liftIO $ do
removeFile dest
moveFile tmpdest dest
thawContent dest
2011-05-15 06:02:46 +00:00
next $ return True
2012-12-13 04:45:27 +00:00
, error "copy failed!"
)