HaikuDepot: Refresh Repo Cache
When HD first loads in a new install, it will experience a near-empty set of repositories. This is because only build-time repo caches are present. This change will cause HD to pull data from remotes on first load, in the case that the cache is somehow missing and on a user- initiated update. Resolves #14840 Change-Id: I4f0e6c9fdba4141841cc167d7953967edb526033 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2821 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
299385f719
commit
d309d94089
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <package/PackageRoster.h>
|
||||
#include <package/RefreshRepositoryRequest.h>
|
||||
|
||||
#include "App.h"
|
||||
#include "AppUtils.h"
|
||||
#include "DecisionProvider.h"
|
||||
#include "JobStateListener.h"
|
||||
@ -67,7 +68,7 @@ LocalRepositoryUpdateProcess::RunInternal()
|
||||
BStringList repoNames;
|
||||
|
||||
if (Logger::IsInfoEnabled()) {
|
||||
printf("[%s] will update local repositories\n", Name());
|
||||
printf("[%s] will update local repositories' caches\n", Name());
|
||||
}
|
||||
|
||||
status_t result = roster.GetRepositoryNames(repoNames);
|
||||
@ -91,13 +92,53 @@ LocalRepositoryUpdateProcess::RunInternal()
|
||||
}
|
||||
|
||||
if (result == B_OK && Logger::IsInfoEnabled()) {
|
||||
printf("[%s] did update %" B_PRIi32 " local repositories\n",
|
||||
printf("[%s] did update %" B_PRIi32 " local repositories' caches\n",
|
||||
Name(), repoNames.CountStrings());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
LocalRepositoryUpdateProcess::_ShouldRunForRepositoryName(
|
||||
const BString& repoName, BPackageKit::BPackageRoster& roster,
|
||||
BPackageKit::BRepositoryCache* cache)
|
||||
{
|
||||
if (fForce) {
|
||||
if (Logger::IsInfoEnabled()) {
|
||||
printf("[%s] am refreshing cache for repo [%s] as it was forced\n",
|
||||
Name(), repoName.String());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (roster.GetRepositoryCache(repoName, cache) != B_OK) {
|
||||
if (Logger::IsInfoEnabled()) {
|
||||
printf("[%s] am updating cache for repo [%s] as there was no"
|
||||
" cache\n", Name(), repoName.String());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (static_cast<App*>(be_app)->IsFirstRun()) {
|
||||
if (Logger::IsInfoEnabled()) {
|
||||
printf("[%s] am updating cache for repo [%s] as this is the first"
|
||||
" time that the application has run\n", Name(),
|
||||
repoName.String());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Logger::IsDebugEnabled()) {
|
||||
printf("[%s] skipped update local repo [%s] cache\n", Name(),
|
||||
repoName.String());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LocalRepositoryUpdateProcess::_RunForRepositoryName(const BString& repoName,
|
||||
BPackageKit::BContext& context, BPackageKit::BPackageRoster& roster,
|
||||
@ -107,10 +148,14 @@ LocalRepositoryUpdateProcess::_RunForRepositoryName(const BString& repoName,
|
||||
BRepositoryConfig repoConfig;
|
||||
result = roster.GetRepositoryConfig(repoName, &repoConfig);
|
||||
if (result == B_OK) {
|
||||
if (roster.GetRepositoryCache(repoName, cache) != B_OK || fForce) {
|
||||
if (_ShouldRunForRepositoryName(repoName, roster, cache)) {
|
||||
try {
|
||||
BRefreshRepositoryRequest refreshRequest(context, repoConfig);
|
||||
result = refreshRequest.Process();
|
||||
if (Logger::IsInfoEnabled()) {
|
||||
printf("[%s] did update local repo [%s] cache\n", Name(),
|
||||
repoName.String());
|
||||
}
|
||||
result = B_OK;
|
||||
} catch (BFatalErrorException& ex) {
|
||||
_NotifyError(ex.Message(), ex.Details());
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -43,10 +43,16 @@ protected:
|
||||
virtual status_t RunInternal();
|
||||
|
||||
private:
|
||||
bool _ShouldRunForRepositoryName(
|
||||
const BString& repoName,
|
||||
BPackageKit::BPackageRoster& roster,
|
||||
BPackageKit::BRepositoryCache* cache);
|
||||
|
||||
status_t _RunForRepositoryName(const BString& repoName,
|
||||
BPackageKit::BContext& context,
|
||||
BPackageKit::BPackageRoster& roster,
|
||||
BPackageKit::BRepositoryCache* cache);
|
||||
|
||||
void _NotifyError(const BString& error) const;
|
||||
void _NotifyError(const BString& error,
|
||||
const BString& details) const;
|
||||
|
@ -45,6 +45,7 @@ App::App()
|
||||
{
|
||||
srand((unsigned int) time(NULL));
|
||||
_CheckPackageDaemonRuns();
|
||||
fIsFirstRun = _CheckIsFirstRun();
|
||||
}
|
||||
|
||||
|
||||
@ -96,6 +97,13 @@ App::ReadyToRun()
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
App::IsFirstRun()
|
||||
{
|
||||
return fIsFirstRun;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
App::MessageReceived(BMessage* message)
|
||||
{
|
||||
@ -515,6 +523,21 @@ App::_LaunchPackageDaemon()
|
||||
}
|
||||
|
||||
|
||||
/*static*/ bool
|
||||
App::_CheckIsFirstRun()
|
||||
{
|
||||
BPath testFilePath;
|
||||
bool exists = false;
|
||||
status_t status = StorageUtils::LocalWorkingFilesPath("testfile.txt",
|
||||
testFilePath, false);
|
||||
if (status != B_OK)
|
||||
printf("! unable to establish the location of the test file\n");
|
||||
else
|
||||
status = StorageUtils::ExistsObject(testFilePath, &exists, NULL, NULL);
|
||||
return !exists;
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Checks to ensure that a working file is able to be written.
|
||||
\return false if the startup should be stopped and the application should
|
||||
quit.
|
||||
|
@ -21,6 +21,8 @@ public:
|
||||
|
||||
virtual bool QuitRequested();
|
||||
virtual void ReadyToRun();
|
||||
bool IsFirstRun();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void RefsReceived(BMessage* message);
|
||||
virtual void ArgvReceived(int32 argc, char* argv[]);
|
||||
@ -37,6 +39,7 @@ private:
|
||||
bool _LaunchPackageDaemon();
|
||||
|
||||
bool _CheckTestFile();
|
||||
static bool _CheckIsFirstRun();
|
||||
|
||||
private:
|
||||
MainWindow* fMainWindow;
|
||||
@ -44,6 +47,8 @@ private:
|
||||
|
||||
BMessage fSettings;
|
||||
bool fSettingsRead;
|
||||
|
||||
bool fIsFirstRun;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user