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
|
|
|
|
2023-03-01 19:55:58 +00:00
|
|
|
import System.PosixCompat.Files (fileMode)
|
|
|
|
|
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
|
2022-06-29 17:28:08 +00:00
|
|
|
mkcmd n d = withAnnexOptions [jsonOptions, annexedMatchingOptions] $
|
2019-08-26 19:52:19 +00:00
|
|
|
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
|
2023-04-25 23:26:20 +00:00
|
|
|
ww = WarnUnmatchLsFiles "unlock"
|
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
|
2023-10-26 17:36:49 +00:00
|
|
|
r <- linkFromAnnex' key tmp destmode
|
2016-06-09 18:40:44 +00:00
|
|
|
case r of
|
|
|
|
LinkAnnexOk -> return ()
|
|
|
|
LinkAnnexNoop -> return ()
|
2023-04-10 17:38:14 +00:00
|
|
|
LinkAnnexFailed -> giveup "unlock failed"
|
2023-10-26 17:36:49 +00:00
|
|
|
, liftIO $ writePointerFile tmp key destmode
|
2016-06-09 18:40:44 +00:00
|
|
|
)
|
2023-10-26 17:36:49 +00:00
|
|
|
withTSDelta (liftIO . genInodeCache tmp)
|
2022-02-18 18:23:25 +00:00
|
|
|
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
|