[haiku-commits] haiku: hrev54244 - src/kits/package

  • From: Andrew Lindesay <apl@xxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 22 May 2020 06:04:57 -0400 (EDT)

hrev54244 adds 1 changeset to branch 'master'
old head: 582b7d16856bef57f65c055a2051a1297c13bda3
new head: 9d8d114499db1f50f105c48c1a2172ea56e18bcd
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=9d8d114499db+%5E582b7d16856b

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

9d8d114499db: Packages: Local Repo Config Formats
  
  The local storage of the various repositories' config
  needs to cater for different generations of storage
  formats and also needs to be able to swap out legacy
  repository identifiers.
  
  Change-Id: Ib4b3857254b7b703858eff6815e2d6c54d69da3c
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/1963
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                                    [ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

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

Revision:    hrev54244
Commit:      9d8d114499db1f50f105c48c1a2172ea56e18bcd
URL:         https://git.haiku-os.org/haiku/commit/?id=9d8d114499db
Author:      Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Date:        Thu May 14 10:56:05 2020 UTC

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

1 file changed, 76 insertions(+), 18 deletions(-)
src/kits/package/RepositoryConfig.cpp | 94 +++++++++++++++++++++++++------

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

diff --git a/src/kits/package/RepositoryConfig.cpp 
b/src/kits/package/RepositoryConfig.cpp
index b4d61d80a1..78ba6c452d 100644
--- a/src/kits/package/RepositoryConfig.cpp
+++ b/src/kits/package/RepositoryConfig.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2018, Haiku, Inc. All Rights Reserved.
+ * Copyright 2011-2020, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -25,16 +25,35 @@
 
 #define STORAGE_VERSION 2
 
-#define KEY_BASE_URL "baseurl"
-#define KEY_BASE_URL_LEGACY "url"
-       // deprecated
-#define KEY_URL "url"
+#define KEY_BASE_URL_V1 "url"
+#define KEY_IDENTIFIER_V1 "url"
+
+#define KEY_BASE_URL_V2 "baseurl"
+#define KEY_IDENTIFIER_V2 "identifier"
+#define KEY_IDENTIFIER_V2_ALT "url"
+       // should not be used any more in favour of 'identifier'
+
 #define KEY_PRIORITY "priority"
 #define KEY_CONFIG_VERSION "cfgversion"
 
 namespace BPackageKit {
 
 
+// these are mappings of known legacy identifier URLs that are possibly
+// still present in some installations.  These are in pairs; the first
+// being the legacy URL and the next being the replacement.  This can
+// be phased out over time.
+
+static const char* kLegacyUrlMappings[] = {
+       "https://eu.hpkg.haiku-os.org/haikuports/master/x86_gcc2/current";,
+       "https://hpkg.haiku-os.org/haikuports/master/x86_gcc2/current";,
+       "https://eu.hpkg.haiku-os.org/haikuports/master/x86_64/current";,
+       "https://hpkg.haiku-os.org/haikuports/master/x86_64/current";,
+       NULL,
+       NULL
+};
+
+
 BRepositoryConfig::BRepositoryConfig()
        :
        fInitStatus(B_NO_INIT),
@@ -78,18 +97,27 @@ BRepositoryConfig::Store(const BEntry& entry) const
        BString configString;
        configString << KEY_CONFIG_VERSION << "=" << STORAGE_VERSION << "\n";
        configString << "\n";
-       configString << "# This is the URL where the repository data can be "
+       configString << "# the url where the repository data can be "
                "accessed.\n";
-       configString << KEY_BASE_URL << "=" << fBaseURL << "\n";
+       configString << KEY_BASE_URL_V2 << "=" << fBaseURL << "\n";
        configString << "\n";
-       configString << "# This URL is an identifier for the repository that is 
"
+
+       configString << "# an identifier for the repository that is "
                "consistent across mirrors\n";
+       if (fIdentifier.IsEmpty())
+               configString << "# " << KEY_IDENTIFIER_V2 << "=???\n";
+       else
+               configString << KEY_IDENTIFIER_V2 << "=" << fIdentifier << "\n";
+       configString << "\n";
 
+       configString << "# a deprecated copy of the ["
+               << KEY_IDENTIFIER_V2 << "] key above for older os versions\n";
        if (fIdentifier.IsEmpty())
-               configString << "# " << KEY_URL << "=???\n";
+               configString << "# " << KEY_IDENTIFIER_V2_ALT << "=???\n";
        else
-               configString << KEY_URL << "=" << fIdentifier << "\n";
+               configString << KEY_IDENTIFIER_V2_ALT << "=" << fIdentifier << 
"\n";
        configString << "\n";
+
        configString << KEY_PRIORITY << "=" << fPriority << "\n";
 
        int32 size = configString.Length();
@@ -107,6 +135,17 @@ BRepositoryConfig::InitCheck() const
 }
 
 
+static const char*
+repository_config_swap_legacy_identifier_v1(const char* identifier)
+{
+       for (int32 i = 0; kLegacyUrlMappings[i] != NULL; i += 2) {
+               if (strcmp(identifier, kLegacyUrlMappings[i]) == 0)
+                       return kLegacyUrlMappings[i + 1];
+       }
+       return identifier;
+}
+
+
 status_t
 BRepositoryConfig::SetTo(const BEntry& entry)
 {
@@ -123,26 +162,45 @@ BRepositoryConfig::SetTo(const BEntry& entry)
        if (result != B_OK)
                return result;
 
-       const char* identifier = NULL;
        const char* version = 
driverSettings.GetParameterValue(KEY_CONFIG_VERSION);
-       const char *baseUrlKey = KEY_BASE_URL;
-
-       if (version == NULL || atoi(version) < 2)
-               baseUrlKey = KEY_BASE_URL_LEGACY;
-       else
-               identifier = driverSettings.GetParameterValue(KEY_URL);
+       int versionNumber = version == NULL ? 1 : atoi(version);
+       const char *baseUrlKey;
+       const char *identifierKeys[3] = { NULL, NULL, NULL };
+
+       switch (versionNumber) {
+               case 1:
+                       baseUrlKey = KEY_BASE_URL_V1;
+                       identifierKeys[0] = KEY_IDENTIFIER_V1;
+                       break;
+               case 2:
+                       baseUrlKey = KEY_BASE_URL_V2;
+                       identifierKeys[0] = KEY_IDENTIFIER_V2;
+                       identifierKeys[1] = KEY_IDENTIFIER_V2_ALT;
+                       break;
+               default:
+                       return B_BAD_DATA;
+       }
 
        const char* baseUrl = driverSettings.GetParameterValue(baseUrlKey);
        const char* priorityString = 
driverSettings.GetParameterValue(KEY_PRIORITY);
+       const char* identifier = NULL;
+
+       for (int32 i = 0; identifier == NULL && identifierKeys[i] != NULL; i++)
+               identifier = 
driverSettings.GetParameterValue(identifierKeys[i]);
 
        if (baseUrl == NULL || *baseUrl == '\0')
                return B_BAD_DATA;
+       if (identifier == NULL || *identifier == '\0')
+               return B_BAD_DATA;
+
+       if (versionNumber == 1)
+               identifier = 
repository_config_swap_legacy_identifier_v1(identifier);
 
        fName = entry.Name();
        fBaseURL = baseUrl;
        fPriority = priorityString == NULL
                ? kUnsetPriority : atoi(priorityString);
-       fIdentifier = identifier == NULL ? "" : identifier;
+       fIdentifier = identifier;
 
        BPath userSettingsPath;
        if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == 
B_OK) {


Other related posts:

  • » [haiku-commits] haiku: hrev54244 - src/kits/package - Andrew Lindesay