[haiku-commits] haiku: hrev54276 - in src/apps/haikudepot: server ui

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 29 May 2020 22:33:22 -0400 (EDT)

hrev54276 adds 1 changeset to branch 'master'
old head: 299385f71979c1d45a3ed2bb62ae2f0189b23598
new head: d309d94089574624dac4d8551a9343ed83c51f0a
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=d309d9408957+%5E299385f71979

----------------------------------------------------------------------------

d309d9408957: 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@xxxxxxxxx>

                                    [ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev54276
Commit:      d309d94089574624dac4d8551a9343ed83c51f0a
URL:         https://git.haiku-os.org/haiku/commit/?id=d309d9408957
Author:      Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Date:        Fri May 29 06:22:00 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sat May 30 02:33:19 2020 UTC

Ticket:      https://dev.haiku-os.org/ticket/14840

----------------------------------------------------------------------------

4 files changed, 84 insertions(+), 5 deletions(-)
.../server/LocalRepositoryUpdateProcess.cpp      | 53 ++++++++++++++++++--
.../server/LocalRepositoryUpdateProcess.h        |  8 ++-
src/apps/haikudepot/ui/App.cpp                   | 23 +++++++++
src/apps/haikudepot/ui/App.h                     |  5 ++

----------------------------------------------------------------------------

diff --git a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp 
b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
index 9e1fc09cab..9804599f95 100644
--- a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2018-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
  * 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());
diff --git a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.h 
b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.h
index 0062af6df2..0be85db715 100644
--- a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.h
+++ b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2018-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
  * 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;
diff --git a/src/apps/haikudepot/ui/App.cpp b/src/apps/haikudepot/ui/App.cpp
index e48573cd45..e2dd2df9f9 100644
--- a/src/apps/haikudepot/ui/App.cpp
+++ b/src/apps/haikudepot/ui/App.cpp
@@ -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.
diff --git a/src/apps/haikudepot/ui/App.h b/src/apps/haikudepot/ui/App.h
index 1eb3f00864..05bba7d784 100644
--- a/src/apps/haikudepot/ui/App.h
+++ b/src/apps/haikudepot/ui/App.h
@@ -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;
 };
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev54276 - in src/apps/haikudepot: server ui - waddlesplash