[haiku-commits] haiku: hrev53370 - src/system/boot/loader

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 13 Aug 2019 09:44:00 -0400 (EDT)

hrev53370 adds 1 changeset to branch 'master'
old head: 6e5ca42d21205902c94b125dfd90a214ef994f39
new head: c1c99c5c00c973df71afcbe938808fd1fd298132
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=c1c99c5c00c9+%5E6e5ca42d2120

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

c1c99c5c00c9: boot_loader: Only load old package states in the boot menu
  
  Normal boots should not be slowed down by old package states.
  
  Should fix #12498.
  
  Later I will fix the package kit to merge old states so they don't build up
  indefinitely.
  
  Change-Id: I6830dd4ed65a3a659c0a68590238be0dcefff451
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/1703
  Reviewed-by: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>

                                  [ Ryan Leavengood <leavengood@xxxxxxxxx> ]

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

Revision:    hrev53370
Commit:      c1c99c5c00c973df71afcbe938808fd1fd298132
URL:         https://git.haiku-os.org/haiku/commit/?id=c1c99c5c00c9
Author:      Ryan Leavengood <leavengood@xxxxxxxxx>
Date:        Mon Aug 12 02:29:29 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Tue Aug 13 13:43:57 2019 UTC

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

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

3 files changed, 39 insertions(+), 15 deletions(-)
src/system/boot/loader/menu.cpp            |  4 +--
src/system/boot/loader/package_support.cpp | 47 +++++++++++++++++++-------
src/system/boot/loader/package_support.h   |  3 ++

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

diff --git a/src/system/boot/loader/menu.cpp b/src/system/boot/loader/menu.cpp
index 5b22682945..acf1be8756 100644
--- a/src/system/boot/loader/menu.cpp
+++ b/src/system/boot/loader/menu.cpp
@@ -786,7 +786,7 @@ public:
        {
                free(fStateChoiceText);
                fStateChoiceText = NULL;
-       
+
                if (volumeState != NULL && volumeState->Name() != NULL) {
                        char nameBuffer[128];
                        snprintf(nameBuffer, sizeof(nameBuffer), "%s (%s)", 
Label(),
@@ -1189,7 +1189,7 @@ add_boot_volume_item(Menu* menu, Directory* volume, const 
char* name)
 
        Menu* subMenu = NULL;
 
-       if (volumeInfo != NULL) {
+       if (volumeInfo != NULL && volumeInfo->LoadOldStates() == B_OK) {
                subMenu = new(std::nothrow) Menu(CHOICE_MENU, "Select Haiku 
version");
 
                for (PackageVolumeStateList::ConstIterator it
diff --git a/src/system/boot/loader/package_support.cpp 
b/src/system/boot/loader/package_support.cpp
index 56f66cfc4c..a96e886d43 100644
--- a/src/system/boot/loader/package_support.cpp
+++ b/src/system/boot/loader/package_support.cpp
@@ -152,7 +152,8 @@ PackageVolumeState::IsNewer(const PackageVolumeState* a,
 PackageVolumeInfo::PackageVolumeInfo()
        :
        BReferenceable(),
-       fStates()
+       fStates(),
+       fPackagesDir(NULL)
 {
 }
 
@@ -161,6 +162,9 @@ PackageVolumeInfo::~PackageVolumeInfo()
 {
        while (PackageVolumeState* state = fStates.RemoveHead())
                delete state;
+
+       if (fPackagesDir != NULL)
+               closedir(fPackagesDir);
 }
 
 
@@ -169,31 +173,45 @@ PackageVolumeInfo::SetTo(Directory* baseDirectory, const 
char* packagesPath)
 {
        TRACE("PackageVolumeInfo::SetTo()\n");
 
+       if (fPackagesDir != NULL)
+               closedir(fPackagesDir);
+
        // get the packages directory
-       DIR* dir = open_directory(baseDirectory, packagesPath);
-       if (dir == NULL) {
+       fPackagesDir = open_directory(baseDirectory, packagesPath);
+       if (fPackagesDir == NULL) {
                TRACE("PackageVolumeInfo::SetTo(): failed to open packages 
directory: "
                        "%s\n", strerror(errno));
                return errno;
        }
-       CObjectDeleter<DIR, int> dirCloser(dir, &closedir);
 
-       Directory* packagesDirectory = directory_from(dir);
+       Directory* packagesDirectory = directory_from(fPackagesDir);
        packagesDirectory->Acquire();
 
        // add the current state
        PackageVolumeState* state = _AddState(NULL);
        if (state == NULL)
                return B_NO_MEMORY;
-       status_t error = _InitState(packagesDirectory, dir, state);
+       status_t error = _InitState(packagesDirectory, fPackagesDir, state);
        if (error != B_OK) {
                TRACE("PackageVolumeInfo::SetTo(): failed to init current 
state: "
                        "%s\n", strerror(error));
                return error;
        }
 
-       // Iterate through the packages/administrative directory to find old 
state
-       // directories.
+       return B_OK;
+}
+
+
+status_t
+PackageVolumeInfo::LoadOldStates() {
+       if (fPackagesDir == NULL) {
+               TRACE("PackageVolumeInfo::LoadOldStates(): package directory is 
NULL");
+               return B_ERROR;
+       }
+
+       Directory* packagesDirectory = directory_from(fPackagesDir);
+       packagesDirectory->Acquire();
+
        if (DIR* administrativeDir = open_directory(packagesDirectory,
                        kAdministrativeDirectory)) {
                while (dirent* entry = readdir(administrativeDir)) {
@@ -208,13 +226,16 @@ PackageVolumeInfo::SetTo(Directory* baseDirectory, const 
char* packagesPath)
                fStates.Sort(&PackageVolumeState::IsNewer);
 
                // initialize the old states
+               PackageVolumeState* state;
+               status_t error;
                for (state = fStates.GetNext(state); state != NULL;) {
                        PackageVolumeState* nextState = fStates.GetNext(state);
                        if (state->Name()) {
-                               error = _InitState(packagesDirectory, dir, 
state);
+                               error = _InitState(packagesDirectory, 
fPackagesDir, state);
                                if (error != B_OK) {
-                                       TRACE("PackageVolumeInfo::SetTo(): 
failed to init state "
-                                               "\"%s\": %s\n", state->Name(), 
strerror(error));
+                                       
TRACE("PackageVolumeInfo::LoadOldStates(): failed to "
+                                               "init state \"%s\": %s\n", 
state->Name(),
+                                               strerror(error));
                                        fStates.Remove(state);
                                        delete state;
                                }
@@ -222,8 +243,8 @@ PackageVolumeInfo::SetTo(Directory* baseDirectory, const 
char* packagesPath)
                        state = nextState;
                }
        } else {
-               TRACE("PackageVolumeInfo::SetTo(): failed to open 
administrative "
-                       "directory: %s\n", strerror(errno));
+               TRACE("PackageVolumeInfo::LoadOldStates(): failed to open "
+                       "administrative directory: %s\n", strerror(errno));
        }
 
        return B_OK;
diff --git a/src/system/boot/loader/package_support.h 
b/src/system/boot/loader/package_support.h
index 3c38ede776..97cf3ee006 100644
--- a/src/system/boot/loader/package_support.h
+++ b/src/system/boot/loader/package_support.h
@@ -57,6 +57,8 @@ public:
                        status_t                        SetTo(Directory* 
baseDirectory,
                                                                        const 
char* packagesPath);
 
+                       status_t                        LoadOldStates();
+
                        const StateList&        States() const
                                                                        { 
return fStates; }
 
@@ -71,6 +73,7 @@ private:
 
 private:
                        StateList                       fStates;
+                       DIR*                            fPackagesDir;
 };
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev53370 - src/system/boot/loader - waddlesplash