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