HaikuDepot / PackageKit: Repositories 'Identifier' URL

Repositories are identified with a 'url' in the
remote 'repo.info' file.  There is also a
'base url' which is the URL locally with which
the system is able to access the repository
data on.  There is some confusion between these
two terms in the source.  This change aims to
separate the two out and consistently name them.
The settings for the repository locally also was
not storing these values and that has been fixed.
Debug info about the repositories also did not
display the two urls consistently and will now
also do so.  Finally, HaikuDepot now correlates
locally configured repositories with the data in
HaikuDepotServer using the identifier URL; this
makes the use of mirrors with HaikuDepot possible.

Fixes #13888
Change-Id: I66dfe589b05c24e1ab123a6945352e0f24b60bf1
This commit is contained in:
Andrew Lindesay
2018-07-05 20:06:54 +00:00
committed by Kacper Kasper
parent a00c8c4491
commit 3b17d8dd7f
21 changed files with 314 additions and 84 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2011, Haiku, Inc. * Copyright 2011-2018, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__REPOSITORY_CONFIG_H_ #ifndef _PACKAGE__REPOSITORY_CONFIG_H_
@@ -28,6 +28,7 @@ public:
const BString& Name() const; const BString& Name() const;
const BString& BaseURL() const; const BString& BaseURL() const;
const BString& URL() const;
uint8 Priority() const; uint8 Priority() const;
bool IsUserSpecific() const; bool IsUserSpecific() const;
@@ -37,6 +38,7 @@ public:
void SetName(const BString& name); void SetName(const BString& name);
void SetBaseURL(const BString& url); void SetBaseURL(const BString& url);
void SetURL(const BString& url);
void SetPriority(uint8 priority); void SetPriority(uint8 priority);
void SetIsUserSpecific(bool isUserSpecific); void SetIsUserSpecific(bool isUserSpecific);
@@ -48,6 +50,11 @@ private:
BString fName; BString fName;
BString fBaseURL; BString fBaseURL;
// this URL is the URL that can be used to access the data of
// the repository - it points to a single mirror.
BString fURL;
// this URL is actually an identifier for the repository
// that is consistent across mirrors.
uint8 fPriority; uint8 fPriority;
bool fIsUserSpecific; bool fIsUserSpecific;
+11 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2011, Haiku, Inc. * Copyright 2011-2018, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _PACKAGE__REPOSITORY_INFO_H_ #ifndef _PACKAGE__REPOSITORY_INFO_H_
@@ -33,7 +33,8 @@ public:
status_t InitCheck() const; status_t InitCheck() const;
const BString& Name() const; const BString& Name() const;
const BString& OriginalBaseURL() const; const BString& BaseURL() const;
const BString& URL() const;
const BString& Vendor() const; const BString& Vendor() const;
const BString& Summary() const; const BString& Summary() const;
uint8 Priority() const; uint8 Priority() const;
@@ -42,7 +43,8 @@ public:
const BStringList& LicenseTexts() const; const BStringList& LicenseTexts() const;
void SetName(const BString& name); void SetName(const BString& name);
void SetOriginalBaseURL(const BString& url); void SetBaseURL(const BString& url);
void SetURL(const BString& url);
void SetVendor(const BString& vendor); void SetVendor(const BString& vendor);
void SetSummary(const BString& summary); void SetSummary(const BString& summary);
void SetPriority(uint8 priority); void SetPriority(uint8 priority);
@@ -59,6 +61,7 @@ public:
static const char* const kNameField; static const char* const kNameField;
static const char* const kURLField; static const char* const kURLField;
static const char* const kBaseURLField;
static const char* const kVendorField; static const char* const kVendorField;
static const char* const kSummaryField; static const char* const kSummaryField;
static const char* const kPriorityField; static const char* const kPriorityField;
@@ -74,7 +77,11 @@ private:
status_t fInitStatus; status_t fInitStatus;
BString fName; BString fName;
BString fOriginalBaseURL; BString fBaseURL;
// This is the URL to a single mirror. This field is optional.
BString fURL;
// This is an identifier for the repository that applies
// across mirrors.
BString fVendor; BString fVendor;
BString fSummary; BString fSummary;
uint8 fPriority; uint8 fPriority;
+1
View File
@@ -116,6 +116,7 @@ Application HaikuDepot :
#util #util
DataIOUtils.cpp DataIOUtils.cpp
RepositoryUrlUtils.cpp
StorageUtils.cpp StorageUtils.cpp
ToFileUrlProtocolListener.cpp ToFileUrlProtocolListener.cpp
+16 -22
View File
@@ -24,6 +24,7 @@
#include "Logger.h" #include "Logger.h"
#include "StorageUtils.h" #include "StorageUtils.h"
#include "RepositoryUrlUtils.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -1057,20 +1058,6 @@ Model::_NotifyAuthorizationChanged()
} }
// temporary - should not be required once the repo info url is used.
static void
normalize_repository_base_url(BUrl& url)
{
if (url.Protocol() == "https")
url.SetProtocol("http");
BString path(url.Path());
if (path.EndsWith("/"))
url.SetPath(path.Truncate(path.Length() - 1));
}
void void
Model::ForAllDepots(void (*func)(const DepotInfo& depot, void* context), Model::ForAllDepots(void (*func)(const DepotInfo& depot, void* context),
void* context) void* context)
@@ -1082,21 +1069,28 @@ Model::ForAllDepots(void (*func)(const DepotInfo& depot, void* context),
} }
// TODO; should use the repo.info url and not the base url. /*! This method will find the stored 'DepotInfo' that correlates to the
supplied 'url' or 'baseUrl' and will invoke the mapper function in
order to get a replacement for the 'DepotInfo'. The two URLs are
different. The 'url' is a unique identifier for the repository that
holds across mirrors. The 'baseUrl' is the URL stem that was used
to access the repository data in the first place. The 'baseUrl' is
a legacy construct that exists from a time where the identifying
'url' was not being relayed properly.
*/
void void
Model::ReplaceDepotByUrl(const BString& url, Model::ReplaceDepotByUrl(
const BString& URL,
const BString& baseURL,
// deprecated
DepotMapper* depotMapper, void* context) DepotMapper* depotMapper, void* context)
{ {
BUrl filterUrl(url);
normalize_repository_base_url(filterUrl);
for (int32 i = 0; i < fDepots.CountItems(); i++) { for (int32 i = 0; i < fDepots.CountItems(); i++) {
DepotInfo depotInfo = fDepots.ItemAtFast(i); DepotInfo depotInfo = fDepots.ItemAtFast(i);
BUrl depotUrlNormalized(depotInfo.BaseURL());
normalize_repository_base_url(depotUrlNormalized);
if (filterUrl == depotUrlNormalized) { if (RepositoryUrlUtils::EqualsOnUrlOrBaseUrl(URL, depotInfo.URL(),
baseURL, depotInfo.BaseURL())) {
BAutolock locker(&fLock); BAutolock locker(&fLock);
fDepots.Replace(i, depotMapper->MapDepot(depotInfo, context)); fDepots.Replace(i, depotMapper->MapDepot(depotInfo, context));
} }
+2 -1
View File
@@ -167,7 +167,8 @@ public:
{ return fWebAppInterface; } { return fWebAppInterface; }
void ReplaceDepotByUrl( void ReplaceDepotByUrl(
const BString& url, const BString& URL,
const BString& baseURL,
DepotMapper* depotMapper, DepotMapper* depotMapper,
void* context); void* context);
+10 -1
View File
@@ -1064,7 +1064,8 @@ DepotInfo::DepotInfo(const DepotInfo& other)
fPackages(other.fPackages), fPackages(other.fPackages),
fWebAppRepositoryCode(other.fWebAppRepositoryCode), fWebAppRepositoryCode(other.fWebAppRepositoryCode),
fWebAppRepositorySourceCode(other.fWebAppRepositorySourceCode), fWebAppRepositorySourceCode(other.fWebAppRepositorySourceCode),
fBaseURL(other.fBaseURL) fBaseURL(other.fBaseURL),
fURL(other.fURL)
{ {
} }
@@ -1075,6 +1076,7 @@ DepotInfo::operator=(const DepotInfo& other)
fName = other.fName; fName = other.fName;
fPackages = other.fPackages; fPackages = other.fPackages;
fBaseURL = other.fBaseURL; fBaseURL = other.fBaseURL;
fURL = other.fURL;
fWebAppRepositoryCode = other.fWebAppRepositoryCode; fWebAppRepositoryCode = other.fWebAppRepositoryCode;
fWebAppRepositorySourceCode = other.fWebAppRepositorySourceCode; fWebAppRepositorySourceCode = other.fWebAppRepositorySourceCode;
return *this; return *this;
@@ -1174,6 +1176,13 @@ DepotInfo::SetBaseURL(const BString& baseURL)
} }
void
DepotInfo::SetURL(const BString& URL)
{
fURL = URL;
}
void void
DepotInfo::SetWebAppRepositoryCode(const BString& code) DepotInfo::SetWebAppRepositoryCode(const BString& code)
{ {
+8
View File
@@ -431,6 +431,10 @@ public:
const BString& BaseURL() const const BString& BaseURL() const
{ return fBaseURL; } { return fBaseURL; }
void SetURL(const BString& URL);
const BString& URL() const
{ return fURL; }
void SetWebAppRepositoryCode(const BString& code); void SetWebAppRepositoryCode(const BString& code);
const BString& WebAppRepositoryCode() const const BString& WebAppRepositoryCode() const
{ return fWebAppRepositoryCode; } { return fWebAppRepositoryCode; }
@@ -446,6 +450,10 @@ private:
BString fWebAppRepositoryCode; BString fWebAppRepositoryCode;
BString fWebAppRepositorySourceCode; BString fWebAppRepositorySourceCode;
BString fBaseURL; BString fBaseURL;
// this is the URL at which the configured repository will be
// accessed to get data.
BString fURL;
// this is actually a unique identifier for the repository.
}; };
@@ -1,5 +1,5 @@
/* /*
* Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2017-2018, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@@ -116,11 +116,14 @@ DepotMatchingRepositoryListener::Handle(DumpExportRepository* repository)
repositoryAndRepositorySource.repositorySource = repositoryAndRepositorySource.repositorySource =
repository->RepositorySourcesItemAt(i); repository->RepositorySourcesItemAt(i);
// TODO; replace with the repo info url BString* baseURL = repositoryAndRepositorySource
BString* url = repositoryAndRepositorySource.repositorySource->Url(); .repositorySource->Url();
BString* URL = repositoryAndRepositorySource
.repositorySource->RepoInfoUrl();
if (url->Length() > 0) {
fModel->ReplaceDepotByUrl(*url, this, if (!baseURL->IsEmpty() || !URL->IsEmpty()) {
fModel->ReplaceDepotByUrl(*URL, *baseURL, this,
&repositoryAndRepositorySource); &repositoryAndRepositorySource);
} }
} }
+49 -18
View File
@@ -12,9 +12,9 @@
#include "MainWindow.h" #include "MainWindow.h"
#include <map> #include <map>
#include <vector>
#include <stdio.h> #include <stdio.h>
#include <Alert.h> #include <Alert.h>
#include <Autolock.h> #include <Autolock.h>
#include <Application.h> #include <Application.h>
@@ -55,6 +55,7 @@
#include "PackageListView.h" #include "PackageListView.h"
#include "PackageManager.h" #include "PackageManager.h"
#include "RatePackageWindow.h" #include "RatePackageWindow.h"
#include "RepositoryUrlUtils.h"
#include "support.h" #include "support.h"
#include "ScreenshotWindow.h" #include "ScreenshotWindow.h"
#include "UserLoginWindow.h" #include "UserLoginWindow.h"
@@ -87,7 +88,6 @@ using namespace BPackageKit::BManager::BPrivate;
typedef std::map<BString, PackageInfoRef> PackageInfoMap; typedef std::map<BString, PackageInfoRef> PackageInfoMap;
typedef std::map<BString, DepotInfo> DepotInfoMap;
struct RefreshWorkerParameters { struct RefreshWorkerParameters {
@@ -943,7 +943,7 @@ MainWindow::_RefreshPackageList(bool force)
if (result != B_OK) if (result != B_OK)
return; return;
DepotInfoMap depots; std::vector<DepotInfo> depots(repositoryNames.CountStrings());
for (int32 i = 0; i < repositoryNames.CountStrings(); i++) { for (int32 i = 0; i < repositoryNames.CountStrings(); i++) {
const BString& repoName = repositoryNames.StringAt(i); const BString& repoName = repositoryNames.StringAt(i);
DepotInfo depotInfo = DepotInfo(repoName); DepotInfo depotInfo = DepotInfo(repoName);
@@ -954,13 +954,22 @@ MainWindow::_RefreshPackageList(bool force)
if (getRepositoryConfigStatus == B_OK) { if (getRepositoryConfigStatus == B_OK) {
depotInfo.SetBaseURL(repoConfig.BaseURL()); depotInfo.SetBaseURL(repoConfig.BaseURL());
depotInfo.SetURL(repoConfig.URL());
if (Logger::IsDebugEnabled()) {
printf("local repository [%s] info;\n"
" * base url [%s]\n"
" * url [%s]\n",
repoName.String(), repoConfig.BaseURL().String(),
repoConfig.URL().String());
}
} else { } else {
printf("unable to obtain the repository config for local " printf("unable to obtain the repository config for local "
"repository '%s'; %s\n", "repository '%s'; %s\n",
repoName.String(), strerror(getRepositoryConfigStatus)); repoName.String(), strerror(getRepositoryConfigStatus));
} }
depots[repoName] = depotInfo; depots[i] = depotInfo;
} }
PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME); PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME);
@@ -1039,16 +1048,34 @@ MainWindow::_RefreshPackageList(bool force)
modelInfo->AddListener(this); modelInfo->AddListener(this);
BSolverRepository* repository = package->Repository(); BSolverRepository* repository = package->Repository();
if (dynamic_cast<BPackageManager::RemoteRepository*>(repository) BPackageManager::RemoteRepository* remoteRepository =
!= NULL) { dynamic_cast<BPackageManager::RemoteRepository*>(repository);
if (depots.count(repositoryName) == 0) {
if (remoteRepository != NULL) {
std::vector<DepotInfo>::iterator it;
for (it = depots.begin(); it != depots.end(); it++) {
if (RepositoryUrlUtils::EqualsOnUrlOrBaseUrl(
it->URL(), remoteRepository->Config().URL(),
it->BaseURL(), remoteRepository->Config().BaseURL())) {
break;
}
}
if (it == depots.end()) {
if (Logger::IsDebugEnabled()) { if (Logger::IsDebugEnabled()) {
printf("pkg [%s] is in an unknown repository [%s] so will " printf("pkg [%s] repository [%s] not recognized"
"be excluded from the list of managed packages\n", " --> ignored\n",
modelInfo->Name().String(), repositoryName.String()); modelInfo->Name().String(), repositoryName.String());
} }
} else { } else {
depots[repositoryName].AddPackage(modelInfo); it->AddPackage(modelInfo);
if (Logger::IsTraceEnabled()) {
printf("pkg [%s] assigned to [%s]\n",
modelInfo->Name().String(), repositoryName.String());
}
} }
remotePackages[modelInfo->Name()] = modelInfo; remotePackages[modelInfo->Name()] = modelInfo;
@@ -1091,19 +1118,23 @@ MainWindow::_RefreshPackageList(bool force)
if (!foundPackages.empty()) { if (!foundPackages.empty()) {
BString repoName = B_TRANSLATE("Local"); BString repoName = B_TRANSLATE("Local");
depots[repoName] = DepotInfo(repoName); depots.push_back(DepotInfo(repoName));
DepotInfoMap::iterator depot = depots.find(repoName);
for (PackageInfoMap::iterator it = foundPackages.begin(); for (PackageInfoMap::iterator it = foundPackages.begin();
it != foundPackages.end(); ++it) { it != foundPackages.end(); ++it) {
depot->second.AddPackage(it->second); depots.back().AddPackage(it->second);
} }
} }
for (DepotInfoMap::iterator it = depots.begin(); it != depots.end(); it++) { {
if (fModel.HasDepot(it->second.Name())) std::vector<DepotInfo>::iterator it;
fModel.SyncDepot(it->second);
else for (it = depots.begin(); it != depots.end(); it++) {
fModel.AddDepot(it->second); if (fModel.HasDepot(it->Name()))
fModel.SyncDepot(*it);
else
fModel.AddDepot(*it);
}
} }
// start retrieving package icons and average ratings // start retrieving package icons and average ratings
@@ -0,0 +1,50 @@
/*
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "RepositoryUrlUtils.h"
void
RepositoryUrlUtils::NormalizeUrl(BUrl& url)
{
if (url.Protocol() == "https")
url.SetProtocol("http");
BString path(url.Path());
if (path.EndsWith("/"))
url.SetPath(path.Truncate(path.Length() - 1));
}
bool
RepositoryUrlUtils::EqualsNormalized(const BString& url1, const BString& url2)
{
if (url1.IsEmpty())
return false;
BUrl normalizedUrl1(url1);
NormalizeUrl(normalizedUrl1);
BUrl normalizedUrl2(url2);
NormalizeUrl(normalizedUrl2);
return normalizedUrl1 == normalizedUrl2;
}
/*! Matches on either the identifier URL of the repo or the 'base' URL that was
used to access the repository over the internet. The use of the 'base' URL
is deprecated.
*/
bool
RepositoryUrlUtils::EqualsOnUrlOrBaseUrl(const BString& url1,
const BString& url2, const BString& baseUrl1,
const BString& baseUrl2)
{
return (!url1.IsEmpty() && url1 == url2)
|| EqualsNormalized(baseUrl1, baseUrl2);
}
@@ -0,0 +1,26 @@
/*
* Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef REPOSITORY_URL_UTILS_H
#define REPOSITORY_URL_UTILS_H
#include <Url.h>
class RepositoryUrlUtils {
public:
static void NormalizeUrl(BUrl& url);
static bool EqualsNormalized(const BString& url1,
const BString& url2);
static bool EqualsNormalized(const BUrl& normalizedUrl1,
const BString& url2);
static bool EqualsOnUrlOrBaseUrl(const BString& url1,
const BString& url2, const BString& baseUrl1,
const BString& baseUrl2);
};
#endif // REPOSITORY_URL_UTILS_H
+2 -1
View File
@@ -69,7 +69,8 @@ struct RepositoryContentListHandler : BRepositoryContentHandler {
printf("repository-info:\n"); printf("repository-info:\n");
printf("\tname: %s\n", repositoryInfo.Name().String()); printf("\tname: %s\n", repositoryInfo.Name().String());
printf("\tsummary: %s\n", repositoryInfo.Summary().String()); printf("\tsummary: %s\n", repositoryInfo.Summary().String());
printf("\turl: %s\n", repositoryInfo.OriginalBaseURL().String()); printf("\tbase-url: %s\n", repositoryInfo.BaseURL().String());
printf("\turl: %s\n", repositoryInfo.URL().String());
printf("\tvendor: %s\n", repositoryInfo.Vendor().String()); printf("\tvendor: %s\n", repositoryInfo.Vendor().String());
printf("\tpriority: %u\n", repositoryInfo.Priority()); printf("\tpriority: %u\n", repositoryInfo.Priority());
printf("\tarchitecture: %s\n", printf("\tarchitecture: %s\n",
+5 -2
View File
@@ -104,6 +104,7 @@ ListReposCommand::Execute(int argc, const char* const* argv)
repoConfig.IsUserSpecific() ? "[User]" : " ", repoConfig.IsUserSpecific() ? "[User]" : " ",
repoConfig.Name().String()); repoConfig.Name().String());
printf("\t\tbase-url: %s\n", repoConfig.BaseURL().String()); printf("\t\tbase-url: %s\n", repoConfig.BaseURL().String());
printf("\t\turl: %s\n", repoConfig.URL().String());
printf("\t\tpriority: %u\n", repoConfig.Priority()); printf("\t\tpriority: %u\n", repoConfig.Priority());
if (verbose) { if (verbose) {
@@ -118,8 +119,10 @@ ListReposCommand::Execute(int argc, const char* const* argv)
repoCache.Info().Architecture()]); repoCache.Info().Architecture()]);
printf("\t\tpkg-count: %" B_PRIu32 "\n", printf("\t\tpkg-count: %" B_PRIu32 "\n",
repoCache.CountPackages()); repoCache.CountPackages());
printf("\t\torig-url: %s\n", printf("\t\tbase-url: %s\n",
repoCache.Info().OriginalBaseURL().String()); repoCache.Info().BaseURL().String());
printf("\t\turl: %s\n",
repoCache.Info().URL().String());
printf("\t\torig-prio: %u\n", repoCache.Info().Priority()); printf("\t\torig-prio: %u\n", repoCache.Info().Priority());
} else } else
printf("\t\t<no repository cache found>\n"); printf("\t\t<no repository cache found>\n");
+2 -1
View File
@@ -2,5 +2,6 @@ name Haiku
vendor "Haiku Project" vendor "Haiku Project"
summary "The Haiku repository (for Haiku %HAIKU_VERSION_NO_REVISION%)" summary "The Haiku repository (for Haiku %HAIKU_VERSION_NO_REVISION%)"
priority 1 priority 1
url https://packages.haiku-os.org/haiku/master/%HAIKU_PACKAGING_ARCH%/current baseurl https://download.haiku-os.org/haiku-repositories/master/%HAIKU_PACKAGING_ARCH%/current
url https://download.haiku-os.org/haiku-repositories/master/%HAIKU_PACKAGING_ARCH%/current
architecture %HAIKU_PACKAGING_ARCH% architecture %HAIKU_PACKAGING_ARCH%
+1
View File
@@ -2,5 +2,6 @@ name HaikuPorts
vendor "Haiku Project" vendor "Haiku Project"
summary "The HaikuPorts repository (for Haiku %HAIKU_VERSION_NO_REVISION%)" summary "The HaikuPorts repository (for Haiku %HAIKU_VERSION_NO_REVISION%)"
priority 1 priority 1
baseurl https://eu.hpkg.haiku-os.org/haikuports/master/repository/%HAIKU_PACKAGING_ARCH%/current
url https://eu.hpkg.haiku-os.org/haikuports/master/repository/%HAIKU_PACKAGING_ARCH%/current url https://eu.hpkg.haiku-os.org/haikuports/master/repository/%HAIKU_PACKAGING_ARCH%/current
architecture %HAIKU_PACKAGING_ARCH% architecture %HAIKU_PACKAGING_ARCH%
@@ -1,9 +1,10 @@
/* /*
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved. * Copyright 2011-2018, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Oliver Tappe <zooey@hirschkaefer.de> * Oliver Tappe <zooey@hirschkaefer.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/ */
@@ -59,11 +60,19 @@ ActivateRepositoryConfigJob::Execute()
} }
// create and store the configuration (injecting the BaseURL that was // create and store the configuration (injecting the BaseURL that was
// actually used) // actually used).
BRepositoryConfig repoConfig; BRepositoryConfig repoConfig;
repoConfig.SetName(repoInfo.Name()); repoConfig.SetName(repoInfo.Name());
repoConfig.SetBaseURL(fRepositoryBaseURL); repoConfig.SetBaseURL(fRepositoryBaseURL);
repoConfig.SetURL(repoInfo.URL());
repoConfig.SetPriority(repoInfo.Priority()); repoConfig.SetPriority(repoInfo.Priority());
if (fRepositoryBaseURL.IsEmpty()) {
repoConfig.SetBaseURL(repoInfo.BaseURL());
} else {
repoConfig.SetBaseURL(fRepositoryBaseURL);
}
if ((result = repoConfig.Store(fTargetEntry)) != B_OK) if ((result = repoConfig.Store(fTargetEntry)) != B_OK)
return result; return result;
+54 -8
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2011-2013, Haiku, Inc. All Rights Reserved. * Copyright 2011-2018, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Oliver Tappe <zooey@hirschkaefer.de> * Oliver Tappe <zooey@hirschkaefer.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/ */
@@ -22,6 +23,15 @@
#include <DriverSettings.h> #include <DriverSettings.h>
#define STORAGE_VERSION 2
#define KEY_BASE_URL "baseurl"
#define KEY_BASE_URL_LEGACY "url"
// deprecated
#define KEY_URL "url"
#define KEY_PRIORITY "priority"
#define KEY_CONFIG_VERSION "cfgversion"
namespace BPackageKit { namespace BPackageKit {
@@ -66,9 +76,21 @@ BRepositoryConfig::Store(const BEntry& entry) const
return result; return result;
BString configString; BString configString;
configString configString << KEY_CONFIG_VERSION << "=" << STORAGE_VERSION << "\n";
<< "url=" << fBaseURL << "\n" configString << "\n";
<< "priority=" << fPriority << "\n"; configString << "# This is the URL where the repository data can be "
"accessed.\n";
configString << KEY_BASE_URL << "=" << fBaseURL << "\n";
configString << "\n";
configString << "# This URL is an identifier for the repository that is "
"consistent across mirrors\n";
if (fURL.IsEmpty())
configString << "# " << KEY_URL << "=???\n";
else
configString << KEY_URL << "=" << fURL << "\n";
configString << "\n";
configString << KEY_PRIORITY << "=" << fPriority << "\n";
int32 size = configString.Length(); int32 size = configString.Length();
if ((result = file.Write(configString.String(), size)) < size) if ((result = file.Write(configString.String(), size)) < size)
@@ -101,16 +123,26 @@ BRepositoryConfig::SetTo(const BEntry& entry)
if (result != B_OK) if (result != B_OK)
return result; return result;
const char* url = driverSettings.GetParameterValue("url"); const char* url = NULL;
const char* priorityString = driverSettings.GetParameterValue("priority"); const char* version = driverSettings.GetParameterValue(KEY_CONFIG_VERSION);
const char *baseUrlKey = KEY_BASE_URL;
if (url == NULL || *url == '\0') if (version == NULL || atoi(version) < 2)
baseUrlKey = KEY_BASE_URL_LEGACY;
else
url = driverSettings.GetParameterValue(KEY_URL);
const char* baseUrl = driverSettings.GetParameterValue(baseUrlKey);
const char* priorityString = driverSettings.GetParameterValue(KEY_PRIORITY);
if (baseUrl == NULL || *baseUrl == '\0')
return B_BAD_DATA; return B_BAD_DATA;
fName = entry.Name(); fName = entry.Name();
fBaseURL = url; fBaseURL = baseUrl;
fPriority = priorityString == NULL fPriority = priorityString == NULL
? kUnsetPriority : atoi(priorityString); ? kUnsetPriority : atoi(priorityString);
fURL = url == NULL ? "" : url;
BPath userSettingsPath; BPath userSettingsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &userSettingsPath) == B_OK) {
@@ -139,6 +171,13 @@ BRepositoryConfig::BaseURL() const
} }
const BString&
BRepositoryConfig::URL() const
{
return fURL;
}
uint8 uint8
BRepositoryConfig::Priority() const BRepositoryConfig::Priority() const
{ {
@@ -183,6 +222,13 @@ BRepositoryConfig::SetBaseURL(const BString& baseURL)
} }
void
BRepositoryConfig::SetURL(const BString& URL)
{
fURL = URL;
}
void void
BRepositoryConfig::SetPriority(uint8 priority) BRepositoryConfig::SetPriority(uint8 priority)
{ {
+35 -10
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2011, Haiku, Inc. All Rights Reserved. * Copyright 2011-2018, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Oliver Tappe <zooey@hirschkaefer.de> * Oliver Tappe <zooey@hirschkaefer.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/ */
@@ -28,6 +29,7 @@ const uint8 BRepositoryInfo::kDefaultPriority = 50;
const char* const BRepositoryInfo::kNameField = "name"; const char* const BRepositoryInfo::kNameField = "name";
const char* const BRepositoryInfo::kURLField = "url"; const char* const BRepositoryInfo::kURLField = "url";
const char* const BRepositoryInfo::kBaseURLField = "baseUrl";
const char* const BRepositoryInfo::kVendorField = "vendor"; const char* const BRepositoryInfo::kVendorField = "vendor";
const char* const BRepositoryInfo::kSummaryField = "summary"; const char* const BRepositoryInfo::kSummaryField = "summary";
const char* const BRepositoryInfo::kPriorityField = "priority"; const char* const BRepositoryInfo::kPriorityField = "priority";
@@ -82,9 +84,14 @@ BRepositoryInfo::Archive(BMessage* data, bool deep) const
if (result != B_OK) if (result != B_OK)
return result; return result;
if (!fBaseURL.IsEmpty()) {
if ((result = data->AddString(kBaseURLField, fBaseURL)) != B_OK)
return result;
}
if ((result = data->AddString(kNameField, fName)) != B_OK) if ((result = data->AddString(kNameField, fName)) != B_OK)
return result; return result;
if ((result = data->AddString(kURLField, fOriginalBaseURL)) != B_OK) if ((result = data->AddString(kURLField, fURL)) != B_OK)
return result; return result;
if ((result = data->AddString(kVendorField, fVendor)) != B_OK) if ((result = data->AddString(kVendorField, fVendor)) != B_OK)
return result; return result;
@@ -139,9 +146,16 @@ BRepositoryInfo::Name() const
const BString& const BString&
BRepositoryInfo::OriginalBaseURL() const BRepositoryInfo::BaseURL() const
{ {
return fOriginalBaseURL; return fBaseURL;
}
const BString&
BRepositoryInfo::URL() const
{
return fURL;
} }
@@ -195,9 +209,16 @@ BRepositoryInfo::SetName(const BString& name)
void void
BRepositoryInfo::SetOriginalBaseURL(const BString& url) BRepositoryInfo::SetURL(const BString& url)
{ {
fOriginalBaseURL = url; fURL = url;
}
void
BRepositoryInfo::SetBaseURL(const BString& url)
{
fBaseURL = url;
} }
@@ -254,15 +275,17 @@ BRepositoryInfo::_SetTo(const BMessage* data)
if (data == NULL) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
data->FindString(kBaseURLField, &fBaseURL);
// optional value for historical reasons
status_t result; status_t result;
if ((result = data->FindString(kNameField, &fName)) != B_OK) if ((result = data->FindString(kNameField, &fName)) != B_OK)
return result; return result;
if ((result = data->FindString(kURLField, &fOriginalBaseURL)) != B_OK) if ((result = data->FindString(kURLField, &fURL)) != B_OK)
return result; return result;
if ((result = data->FindString(kVendorField, &fVendor)) != B_OK) if ((result = data->FindString(kVendorField, &fVendor)) != B_OK)
return result; return result;
result = data->FindString(kSummaryField, &fSummary); if ((result = data->FindString(kSummaryField, &fSummary)) != B_OK)
if (result != B_OK)
return result; return result;
if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK) if ((result = data->FindUInt8(kPriorityField, &fPriority)) != B_OK)
return result; return result;
@@ -319,6 +342,7 @@ BRepositoryInfo::_SetTo(const BEntry& entry)
const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL); const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL); const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
const char* baseUrl = get_driver_parameter(settingsHandle, "baseurl", NULL, NULL);
const char* vendor const char* vendor
= get_driver_parameter(settingsHandle, "vendor", NULL, NULL); = get_driver_parameter(settingsHandle, "vendor", NULL, NULL);
const char* summary const char* summary
@@ -343,7 +367,8 @@ BRepositoryInfo::_SetTo(const BEntry& entry)
} }
fName = name; fName = name;
fOriginalBaseURL = url; fBaseURL = baseUrl;
fURL = url;
fVendor = vendor; fVendor = vendor;
fSummary = summary; fSummary = summary;
fPriority = atoi(priorityString); fPriority = atoi(priorityString);
+1 -1
View File
@@ -22,7 +22,7 @@ main(int argc, const char** argv)
BRepositoryInfo repoInfo; BRepositoryInfo repoInfo;
repoInfo.SetName(argv[1]); repoInfo.SetName(argv[1]);
repoInfo.SetOriginalBaseURL(argv[2]); repoInfo.SetURL(argv[2]);
repoInfo.SetPriority(atoi(argv[3])); repoInfo.SetPriority(atoi(argv[3]));
BMessage repoInfoArchive; BMessage repoInfoArchive;
@@ -1,9 +1,10 @@
/* /*
* Copyright 2013, Haiku, Inc. All Rights Reserved. * Copyright 2013-2018, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/ */
@@ -59,7 +60,7 @@ main(int argc, const char* const* argv)
} }
int argi = 1; int argi = 1;
const char* url = argc == 4 ? argv[argi++] : NULL; const char* baseUrl = argc == 4 ? argv[argi++] : NULL;
const char* infoPath = argv[argi++]; const char* infoPath = argv[argi++];
const char* configPath = argv[argi++]; const char* configPath = argv[argi++];
@@ -68,13 +69,18 @@ main(int argc, const char* const* argv)
DIE_ON_ERROR(repoInfo.SetTo(infoPath), DIE_ON_ERROR(repoInfo.SetTo(infoPath),
"failed to read repository info file \"%s\"", infoPath); "failed to read repository info file \"%s\"", infoPath);
if (url == NULL) if (baseUrl == NULL) {
url = repoInfo.OriginalBaseURL(); if (repoInfo.BaseURL().IsEmpty())
baseUrl = repoInfo.URL();
else
baseUrl = repoInfo.BaseURL();
}
// init and write the config // init and write the config
BPackageKit::BRepositoryConfig repoConfig; BPackageKit::BRepositoryConfig repoConfig;
repoConfig.SetName(repoInfo.Name()); repoConfig.SetName(repoInfo.Name());
repoConfig.SetBaseURL(url); repoConfig.SetBaseURL(baseUrl);
repoConfig.SetURL(repoInfo.URL());
repoConfig.SetPriority(repoInfo.Priority()); repoConfig.SetPriority(repoInfo.Priority());
DIE_ON_ERROR(repoConfig.Store(configPath), DIE_ON_ERROR(repoConfig.Store(configPath),
"failed to write repository config file \"%s\"", configPath); "failed to write repository config file \"%s\"", configPath);
@@ -1,9 +1,10 @@
/* /*
* Copyright 2013, Haiku, Inc. All Rights Reserved. * Copyright 2013-2018, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Andrew Lindesay <apl@lindesay.co.nz>
*/ */
@@ -154,7 +155,7 @@ main(int argc, const char* const* argv)
if (package->Repository() != &installedRepository) { if (package->Repository() != &installedRepository) {
const BRepositoryInfo& info const BRepositoryInfo& info
= repositoryInfos[package->Repository()]; = repositoryInfos[package->Repository()];
BString url = info.OriginalBaseURL(); BString url = info.URL();
url << "/packages/" << package->Info().CanonicalFileName(); url << "/packages/" << package->Info().CanonicalFileName();
printf("%s\n", url.String()); printf("%s\n", url.String());
} }