git-annex/Command/Unlock.hs

67 lines
1.6 KiB
Haskell
Raw Normal View History

2010-11-09 19:59:49 +00:00
{- git-annex command
-
- Copyright 2010 Joey Hess <id@joeyh.name>
2010-11-09 19:59:49 +00:00
-
- 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
import Annex.CatFile
2011-07-06 00:24:10 +00:00
import Utility.CopyFile
2010-11-09 19:59:49 +00:00
cmd :: [Command]
cmd =
[ c "unlock" "unlock files for modification"
, c "edit" "same as unlock"
]
2012-11-12 05:05:04 +00:00
where
c n = notDirect . withOptions annexedMatchingOptions
. 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. -}
start :: FilePath -> Key -> CommandStart
start file key = do
showStart "unlock" file
ifM (inAnnex key)
( ifM (isJust <$> catKeyFileHEAD file)
( next $ perform file key
, do
warning "this has not yet been committed to git; cannot unlock it"
next $ next $ return False
)
, do
warning "content not present; cannot unlock"
next $ next $ return False
)
2010-11-09 19:59:49 +00:00
perform :: FilePath -> Key -> CommandPerform
perform dest key = ifM (checkDiskSpace Nothing key 0)
( do
src <- calcRepo $ gitAnnexLocation key
tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
showAction "copying"
ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest)
( do
liftIO $ do
removeFile dest
moveFile tmpdest dest
thawContent dest
next $ return True
, do
warning "copy failed!"
next $ return False
)
, do
warning "not enough disk space to copy file"
next $ return False
)