2011-03-16 19:48:26 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2020-03-09 20:47:57 +00:00
|
|
|
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
2011-03-16 19:48:26 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-03-16 19:48:26 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Upgrade where
|
|
|
|
|
|
|
|
import Command
|
2011-03-19 22:58:10 +00:00
|
|
|
import Upgrade
|
2016-03-31 21:20:43 +00:00
|
|
|
import Annex.Version
|
|
|
|
import Annex.Init
|
remove dead nodes when loading the cluster log
This is to avoid inserting a cluster uuid into the location log when
only dead nodes in the cluster contain the content of a key.
One reason why this is necessary is Remote.keyLocations, which excludes
dead repositories from the list. But there are probably many more.
Implementing this was challenging, because Logs.Location importing
Logs.Cluster which imports Logs.Trust which imports Remote.List resulted
in an import cycle through several other modules.
Resorted to making Logs.Location not import Logs.Cluster, and instead
it assumes that Annex.clusters gets populated when necessary before it's
called.
That's done in Annex.Startup, which is run by the git-annex command
(but not other commands) at early startup in initialized repos. Or,
is run after initialization.
Note that is Remote.Git, it is unable to import Annex.Startup, because
Remote.Git importing Logs.Cluster leads the the same import cycle.
So ensureInitialized is not passed annexStartup in there.
Other commands, like git-annex-shell currently don't run annexStartup
either.
So there are cases where Logs.Location will not see clusters. So it won't add
any cluster UUIDs when loading the log. That's ok, the only reason to do
that is to make display of where objects are located include clusters,
and to make commands like git-annex get --from treat keys as being located
in a cluster. git-annex-shell certainly does not do anything like that,
and I'm pretty sure Remote.Git (and callers to Remote.Git.onLocalRepo)
don't either.
2024-06-16 18:35:07 +00:00
|
|
|
import Annex.Startup
|
2011-03-16 19:48:26 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2020-05-11 06:40:13 +00:00
|
|
|
cmd = dontCheck
|
|
|
|
-- because an old version may not seem to exist
|
2019-09-01 17:29:55 +00:00
|
|
|
-- and also, this avoids automatic silent upgrades before
|
|
|
|
-- this command can start up.
|
2020-05-11 06:40:13 +00:00
|
|
|
repoExists $
|
|
|
|
-- avoid upgrading repo out from under daemon
|
2019-09-01 17:29:55 +00:00
|
|
|
noDaemonRunning $
|
2023-05-10 16:41:43 +00:00
|
|
|
withAnnexOptions [jsonOptions] $
|
2019-09-01 17:29:55 +00:00
|
|
|
command "upgrade" SectionMaintenance "upgrade repository"
|
2020-03-09 20:47:57 +00:00
|
|
|
paramNothing (seek <$$> optParser)
|
2011-03-16 19:48:26 +00:00
|
|
|
|
2020-03-09 20:47:57 +00:00
|
|
|
data UpgradeOptions = UpgradeOptions
|
|
|
|
{ autoOnly :: Bool
|
|
|
|
}
|
2011-03-16 19:48:26 +00:00
|
|
|
|
2020-03-09 20:47:57 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser UpgradeOptions
|
|
|
|
optParser _ = UpgradeOptions
|
|
|
|
<$> switch
|
|
|
|
( long "autoonly"
|
|
|
|
<> help "only do automatic upgrades"
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: UpgradeOptions -> CommandSeek
|
|
|
|
seek o = commandAction (start o)
|
|
|
|
|
|
|
|
start :: UpgradeOptions -> CommandStart
|
2020-10-19 15:14:01 +00:00
|
|
|
start (UpgradeOptions { autoOnly = True }) =
|
2020-09-14 20:49:33 +00:00
|
|
|
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
|
2020-10-19 15:14:01 +00:00
|
|
|
getVersion >>= maybe noop checkUpgrade
|
|
|
|
next $ return True
|
|
|
|
start _ =
|
|
|
|
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
|
|
|
|
whenM (isNothing <$> getVersion) $ do
|
remove dead nodes when loading the cluster log
This is to avoid inserting a cluster uuid into the location log when
only dead nodes in the cluster contain the content of a key.
One reason why this is necessary is Remote.keyLocations, which excludes
dead repositories from the list. But there are probably many more.
Implementing this was challenging, because Logs.Location importing
Logs.Cluster which imports Logs.Trust which imports Remote.List resulted
in an import cycle through several other modules.
Resorted to making Logs.Location not import Logs.Cluster, and instead
it assumes that Annex.clusters gets populated when necessary before it's
called.
That's done in Annex.Startup, which is run by the git-annex command
(but not other commands) at early startup in initialized repos. Or,
is run after initialization.
Note that is Remote.Git, it is unable to import Annex.Startup, because
Remote.Git importing Logs.Cluster leads the the same import cycle.
So ensureInitialized is not passed annexStartup in there.
Other commands, like git-annex-shell currently don't run annexStartup
either.
So there are cases where Logs.Location will not see clusters. So it won't add
any cluster UUIDs when loading the log. That's ok, the only reason to do
that is to make display of where objects are located include clusters,
and to make commands like git-annex get --from treat keys as being located
in a cluster. git-annex-shell certainly does not do anything like that,
and I'm pretty sure Remote.Git (and callers to Remote.Git.onLocalRepo)
don't either.
2024-06-16 18:35:07 +00:00
|
|
|
initialize startupAnnex Nothing Nothing
|
2020-10-19 15:14:01 +00:00
|
|
|
r <- upgrade False latestVersion
|
|
|
|
next $ return r
|