2010-11-09 15:59:49 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2016-06-09 14:45:00 -04:00
|
|
|
- Copyright 2010-2016 Joey Hess <id@joeyh.name>
|
2010-11-09 15:59:49 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-09 15:59:49 -04:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Unlock where
|
|
|
|
|
|
|
|
import Command
|
2011-10-04 00:40:47 -04:00
|
|
|
import Annex.Content
|
2016-03-09 13:43:22 -04:00
|
|
|
import Annex.Perms
|
2015-12-10 16:12:05 -04:00
|
|
|
import Annex.Link
|
|
|
|
import Annex.ReplaceFile
|
2016-06-09 14:45:00 -04:00
|
|
|
import Git.FilePath
|
|
|
|
import qualified Database.Keys
|
2019-12-06 14:44:42 -04:00
|
|
|
import qualified Utility.RawFilePath as R
|
2010-11-09 15:59:49 -04:00
|
|
|
|
2015-07-08 12:33:27 -04:00
|
|
|
cmd :: Command
|
|
|
|
cmd = mkcmd "unlock" "unlock files for modification"
|
|
|
|
|
|
|
|
editcmd :: Command
|
|
|
|
editcmd = mkcmd "edit" "same as unlock"
|
|
|
|
|
|
|
|
mkcmd :: String -> String -> Command
|
2019-08-26 15:52:19 -04:00
|
|
|
mkcmd n d = withGlobalOptions [jsonOptions, annexedMatchingOptions] $
|
|
|
|
command n SectionCommon d paramPaths (withParams seek)
|
2010-12-30 15:06:26 -04:00
|
|
|
|
2015-07-08 15:08:02 -04:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2020-07-13 17:04:02 -04:00
|
|
|
seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
|
2020-05-28 15:55:17 -04:00
|
|
|
where
|
|
|
|
ww = WarnUnmatchLsFiles
|
2020-07-13 17:04:02 -04:00
|
|
|
seeker = AnnexedFileSeeker
|
2020-07-22 14:23:28 -04:00
|
|
|
{ startAction = start
|
2020-07-13 17:04:02 -04:00
|
|
|
, checkContentPresent = Nothing
|
|
|
|
, usesLocationLog = False
|
|
|
|
}
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2020-09-14 16:49:33 -04:00
|
|
|
start :: SeekInput -> RawFilePath -> Key -> CommandStart
|
|
|
|
start si file key = ifM (isJust <$> isAnnexLink file)
|
|
|
|
( starting "unlock" ai si $ perform file key
|
2015-12-10 16:12:05 -04:00
|
|
|
, stop
|
|
|
|
)
|
2020-09-14 16:49:33 -04:00
|
|
|
where
|
|
|
|
ai = mkActionItem (key, AssociatedFile (Just file))
|
2015-12-10 16:12:05 -04:00
|
|
|
|
2019-12-05 11:40:10 -04:00
|
|
|
perform :: RawFilePath -> Key -> CommandPerform
|
2019-08-30 13:54:57 -04:00
|
|
|
perform dest key = do
|
2019-12-06 14:44:42 -04:00
|
|
|
destmode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus dest
|
2020-03-06 11:31:01 -04:00
|
|
|
replaceWorkTreeFile (fromRawFilePath dest) $ \tmp ->
|
2016-06-09 14:40:44 -04:00
|
|
|
ifM (inAnnex key)
|
|
|
|
( do
|
2020-10-30 15:55:59 -04:00
|
|
|
r <- linkFromAnnex key (toRawFilePath tmp) destmode
|
2016-06-09 14:40:44 -04:00
|
|
|
case r of
|
|
|
|
LinkAnnexOk -> return ()
|
|
|
|
LinkAnnexNoop -> return ()
|
2016-10-17 15:19:47 -04:00
|
|
|
LinkAnnexFailed -> error "unlock failed"
|
2019-12-05 11:40:10 -04:00
|
|
|
, liftIO $ writePointerFile (toRawFilePath tmp) key destmode
|
2016-06-09 14:40:44 -04:00
|
|
|
)
|
2019-08-30 13:54:57 -04:00
|
|
|
next $ cleanup dest key destmode
|
2015-12-10 16:12:05 -04:00
|
|
|
|
2019-12-05 11:40:10 -04:00
|
|
|
cleanup :: RawFilePath -> Key -> Maybe FileMode -> CommandCleanup
|
2019-08-30 13:54:57 -04:00
|
|
|
cleanup dest key destmode = do
|
2016-04-14 14:30:15 -04:00
|
|
|
stagePointerFile dest destmode =<< hashPointerFile key
|
2019-12-09 13:49:05 -04:00
|
|
|
Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath dest)
|
2015-12-10 16:12:05 -04:00
|
|
|
return True
|