add startAction parameter for KeySha

I have a use planned for this in Command.Migrate.

Sponsored-by: unqueued on Patreon
This commit is contained in:
Joey Hess 2023-12-06 13:04:32 -04:00
parent 1f811c340d
commit b55efc179a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
22 changed files with 34 additions and 31 deletions

View file

@ -4,7 +4,7 @@
- the values a user passes to a command, and prepare actions operating - the values a user passes to a command, and prepare actions operating
- on them. - on them.
- -
- Copyright 2010-2022 Joey Hess <id@joeyh.name> - Copyright 2010-2023 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -58,11 +58,14 @@ import System.PosixCompat.Files (isDirectory, isSymbolicLink, deviceID, fileID)
import qualified System.FilePath.ByteString as P import qualified System.FilePath.ByteString as P
data AnnexedFileSeeker = AnnexedFileSeeker data AnnexedFileSeeker = AnnexedFileSeeker
{ startAction :: SeekInput -> RawFilePath -> Key -> CommandStart { startAction :: Maybe KeySha -> SeekInput -> RawFilePath -> Key -> CommandStart
, checkContentPresent :: Maybe Bool , checkContentPresent :: Maybe Bool
, usesLocationLog :: Bool , usesLocationLog :: Bool
} }
-- The Sha that was read to get the Key.
newtype KeySha = KeySha Git.Sha
withFilesInGitAnnex :: WarnUnmatchWhen -> AnnexedFileSeeker -> WorkTreeItems -> CommandSeek withFilesInGitAnnex :: WarnUnmatchWhen -> AnnexedFileSeeker -> WorkTreeItems -> CommandSeek
withFilesInGitAnnex ww a l = seekFilteredKeys a $ withFilesInGitAnnex ww a l = seekFilteredKeys a $
seekHelper fst3 ww LsFiles.inRepoDetails l seekHelper fst3 ww LsFiles.inRepoDetails l
@ -375,9 +378,9 @@ seekFilteredKeys seeker listfs = do
propagateLsFilesError cleanup propagateLsFilesError cleanup
where where
finisher mi oreader checktimelimit = liftIO oreader >>= \case finisher mi oreader checktimelimit = liftIO oreader >>= \case
Just ((si, f), content) -> checktimelimit (liftIO discard) $ do Just ((si, f, keysha), content) -> checktimelimit (liftIO discard) $ do
keyaction f mi content $ keyaction f mi content $
commandAction . startAction seeker si f commandAction . startAction seeker keysha si f
finisher mi oreader checktimelimit finisher mi oreader checktimelimit
Nothing -> return () Nothing -> return ()
where where
@ -386,12 +389,12 @@ seekFilteredKeys seeker listfs = do
Just _ -> discard Just _ -> discard
precachefinisher mi lreader checktimelimit = liftIO lreader >>= \case precachefinisher mi lreader checktimelimit = liftIO lreader >>= \case
Just ((logf, (si, f), k), logcontent) -> checktimelimit (liftIO discard) $ do Just ((logf, (si, f, keysha), k), logcontent) -> checktimelimit (liftIO discard) $ do
maybe noop (Annex.Branch.precache logf) logcontent maybe noop (Annex.Branch.precache logf) logcontent
checkMatcherWhen mi checkMatcherWhen mi
(matcherNeedsLocationLog mi && not (matcherNeedsFileName mi)) (matcherNeedsLocationLog mi && not (matcherNeedsFileName mi))
(MatchingFile $ FileInfo f f (Just k)) (MatchingFile $ FileInfo f f (Just k))
(commandAction $ startAction seeker si f k) (commandAction $ startAction seeker keysha si f k)
precachefinisher mi lreader checktimelimit precachefinisher mi lreader checktimelimit
Nothing -> return () Nothing -> return ()
where where
@ -400,11 +403,11 @@ seekFilteredKeys seeker listfs = do
Just _ -> discard Just _ -> discard
precacher mi config oreader lfeeder lcloser = liftIO oreader >>= \case precacher mi config oreader lfeeder lcloser = liftIO oreader >>= \case
Just ((si, f), content) -> do Just ((si, f, keysha), content) -> do
keyaction f mi content $ \k -> keyaction f mi content $ \k ->
let logf = locationLogFile config k let logf = locationLogFile config k
ref = Git.Ref.branchFileRef Annex.Branch.fullname logf ref = Git.Ref.branchFileRef Annex.Branch.fullname logf
in liftIO $ lfeeder ((logf, (si, f), k), ref) in liftIO $ lfeeder ((logf, (si, f, keysha), k), ref)
precacher mi config oreader lfeeder lcloser precacher mi config oreader lfeeder lcloser
Nothing -> liftIO $ void lcloser Nothing -> liftIO $ void lcloser
@ -415,7 +418,7 @@ seekFilteredKeys seeker listfs = do
(not ((matcherNeedsKey mi || matcherNeedsLocationLog mi) (not ((matcherNeedsKey mi || matcherNeedsLocationLog mi)
&& not (matcherNeedsFileName mi))) && not (matcherNeedsFileName mi)))
(MatchingFile $ FileInfo f f Nothing) (MatchingFile $ FileInfo f f Nothing)
(liftIO $ ofeeder ((si, f), sha)) (liftIO $ ofeeder ((si, f, Just (KeySha sha)), sha))
keyaction f mi content a = keyaction f mi content a =
case parseLinkTargetOrPointerLazy =<< content of case parseLinkTargetOrPointerLazy =<< content of

View file

@ -63,7 +63,7 @@ seek' o fto = startConcurrency (Command.Move.stages fto) $ do
ww = WarnUnmatchLsFiles "copy" ww = WarnUnmatchLsFiles "copy"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start o fto { startAction = const $ start o fto
, checkContentPresent = case fto of , checkContentPresent = case fto of
FromOrToRemote (FromRemote _) -> Just False FromOrToRemote (FromRemote _) -> Just False
FromOrToRemote (ToRemote _) -> Just True FromOrToRemote (ToRemote _) -> Just True

View file

@ -60,7 +60,7 @@ seek o = startConcurrency commandStages $ do
then pure Nothing then pure Nothing
else pure (Just remote) else pure (Just remote)
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start o from { startAction = const $ start o from
, checkContentPresent = case from of , checkContentPresent = case from of
Nothing -> Just True Nothing -> Just True
Just _ -> Nothing Just _ -> Nothing

View file

@ -157,7 +157,7 @@ seek o = withOtherTmp $ \tmpdir -> do
=<< Annex.Branch.get f =<< Annex.Branch.get f
next (return True) next (return True)
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = \_ _ k -> addkeyinfo k { startAction = \_ _ _ k -> addkeyinfo k
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -63,7 +63,7 @@ seek o = do
checkNotBareRepo checkNotBareRepo
isterminal <- liftIO $ checkIsTerminal stdout isterminal <- liftIO $ checkIsTerminal stdout
seeker <- contentPresentUnlessLimited $ AnnexedFileSeeker seeker <- contentPresentUnlessLimited $ AnnexedFileSeeker
{ startAction = start o isterminal { startAction = const (start o isterminal)
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -33,7 +33,7 @@ seek o = do
, usesLocationLog = False , usesLocationLog = False
-- startAction is not actually used since this -- startAction is not actually used since this
-- is not used to seek files -- is not used to seek files
, startAction = \_ _ key -> start' o isterminal key , startAction = \_ _ _ key -> start' o isterminal key
} }
withKeyOptions (Just WantAllKeys) False seeker withKeyOptions (Just WantAllKeys) False seeker
(commandAction . start o isterminal) (commandAction . start o isterminal)

View file

@ -37,7 +37,7 @@ seek ps = unlessM crippledFileSystem $
where where
ww = WarnUnmatchLsFiles "fix" ww = WarnUnmatchLsFiles "fix"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start FixAll { startAction = const $ start FixAll
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -102,7 +102,7 @@ seek o = startConcurrency commandStages $ do
checkDeadRepo u checkDeadRepo u
i <- prepIncremental u (incrementalOpt o) i <- prepIncremental u (incrementalOpt o)
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start from i { startAction = const $ start from i
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -41,7 +41,7 @@ seek :: GetOptions -> CommandSeek
seek o = startConcurrency transferStages $ do seek o = startConcurrency transferStages $ do
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o) from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start o from { startAction = const $ start o from
, checkContentPresent = Just False , checkContentPresent = Just False
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -42,7 +42,7 @@ seek o = do
_ -> do _ -> do
let s = S.fromList ts let s = S.fromList ts
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start isterminal s { startAction = const $ start isterminal s
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -50,7 +50,7 @@ seek o = do
list <- getList o list <- getList o
printHeader list printHeader list
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start list { startAction = const $ start list
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -34,7 +34,7 @@ seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where where
ww = WarnUnmatchLsFiles "lock" ww = WarnUnmatchLsFiles "lock"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start { startAction = const start
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -138,7 +138,7 @@ seek o = ifM (null <$> Annex.Branch.getUnmergedRefs)
zone <- liftIO getCurrentTimeZone zone <- liftIO getCurrentTimeZone
outputter <- mkOutputter m zone o <$> jsonOutputEnabled outputter <- mkOutputter m zone o <$> jsonOutputEnabled
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start o outputter { startAction = const $ start o outputter
, checkContentPresent = Nothing , checkContentPresent = Nothing
-- the way this uses the location log would not be -- the way this uses the location log would not be
-- helped by precaching the current value -- helped by precaching the current value

View file

@ -77,7 +77,7 @@ seek o = case batchOption o of
c <- currentVectorClock c <- currentVectorClock
let ww = WarnUnmatchLsFiles "metadata" let ww = WarnUnmatchLsFiles "metadata"
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start c o { startAction = const $ start c o
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -43,7 +43,7 @@ seek o = withFilesInGitAnnex ww seeker =<< workTreeItems ww (migrateThese o)
where where
ww = WarnUnmatchLsFiles "migrate" ww = WarnUnmatchLsFiles "migrate"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start o { startAction = const $ start o
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -52,7 +52,7 @@ seek o = startConcurrency stages $
ToRemote _ -> commandStages ToRemote _ -> commandStages
ww = WarnUnmatchLsFiles "mirror" ww = WarnUnmatchLsFiles "mirror"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start o { startAction = const $ start o
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -75,7 +75,7 @@ seek' o fto = startConcurrency (stages fto) $ do
batchAnnexed fmt seeker keyaction batchAnnexed fmt seeker keyaction
where where
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start fto (removeWhen o) { startAction = const $ start fto (removeWhen o)
, checkContentPresent = case fto of , checkContentPresent = case fto of
FromOrToRemote (FromRemote _) -> Nothing FromOrToRemote (FromRemote _) -> Nothing
FromOrToRemote (ToRemote _) -> Just True FromOrToRemote (ToRemote _) -> Just True

View file

@ -842,7 +842,7 @@ seekSyncContent o rs currbranch = do
where where
seekworktree mvar l bloomfeeder = do seekworktree mvar l bloomfeeder = do
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = gofile bloomfeeder mvar { startAction = const $ gofile bloomfeeder mvar
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }

View file

@ -34,7 +34,7 @@ seek ps = withFilesInGitAnnex ww (seeker False) =<< workTreeItems ww ps
seeker :: Bool -> AnnexedFileSeeker seeker :: Bool -> AnnexedFileSeeker
seeker fast = AnnexedFileSeeker seeker fast = AnnexedFileSeeker
{ startAction = start fast { startAction = const $ start fast
, checkContentPresent = Just True , checkContentPresent = Just True
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -35,7 +35,7 @@ seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where where
ww = WarnUnmatchLsFiles "unlock" ww = WarnUnmatchLsFiles "unlock"
seeker = AnnexedFileSeeker seeker = AnnexedFileSeeker
{ startAction = start { startAction = const start
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -49,7 +49,7 @@ seek o = withKeyOptions (Just (keyOptions o)) False dummyfileseeker
(commandAction . start o) dummyfilecommandseek (WorkTreeItems []) (commandAction . start o) dummyfilecommandseek (WorkTreeItems [])
where where
dummyfileseeker = AnnexedFileSeeker dummyfileseeker = AnnexedFileSeeker
{ startAction = \_ _ _ -> return Nothing { startAction = \_ _ _ _ -> return Nothing
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = False , usesLocationLog = False
} }

View file

@ -51,7 +51,7 @@ seek :: WhereisOptions -> CommandSeek
seek o = do seek o = do
m <- remoteMap id m <- remoteMap id
let seeker = AnnexedFileSeeker let seeker = AnnexedFileSeeker
{ startAction = start o m { startAction = const $ start o m
, checkContentPresent = Nothing , checkContentPresent = Nothing
, usesLocationLog = True , usesLocationLog = True
} }