packagefs: replace ':' with '~' in the package link names

Otherwise paths containing those symlinks cannot be used in colon
separated search path lists.
This commit is contained in:
Ingo Weinhold
2013-08-13 14:20:41 +02:00
parent 623331eed5
commit b8ab901eeb
3 changed files with 29 additions and 3 deletions
@@ -208,7 +208,7 @@ PackageLinkDirectory::_UpdateDependencies(PackageLinksListener* listener)
Package* resolvablePackage = resolvable != NULL
? resolvable->Package() : NULL;
Node* node = FindChild(dependency->Name());
Node* node = FindChild(dependency->FileName());
if (node != NULL) {
// link already exists -- update
DependencyLink* link = static_cast<DependencyLink*>(node);
@@ -222,7 +222,7 @@ PackageLinkDirectory::_UpdateDependencies(PackageLinksListener* listener)
if (link == NULL)
return B_NO_MEMORY;
status_t error = link->Init(this, dependency->Name());
status_t error = link->Init(this, dependency->FileName());
if (error != B_OK) {
delete link;
RETURN_ERROR(error);
@@ -9,6 +9,8 @@
#include <stdlib.h>
#include <string.h>
#include <AutoDeleter.h>
#include "Version.h"
@@ -18,6 +20,7 @@ Dependency::Dependency(::Package* package)
fFamily(NULL),
fResolvable(NULL),
fName(),
fFileName(),
fVersion(NULL),
fVersionOperator(B_PACKAGE_RESOLVABLE_OP_EQUAL)
{
@@ -36,6 +39,26 @@ Dependency::Init(const char* name)
if (!fName.SetTo(name))
return B_NO_MEMORY;
// If the name contains a ':', replace it with '~' in the file name. We do
// that so that a path containing the symlink can be used in colon-separated
// search paths.
if (strchr(name, ':') != NULL) {
char* fileName = strdup(name);
if (fileName == NULL)
return B_NO_MEMORY;
MemoryDeleter fileNameDeleter(fileName);
char* remainder = fileName;
while (char* colon = strchr(remainder, ':')) {
*colon = '~';
remainder = colon + 1;
}
if (!fFileName.SetTo(fileName))
return B_NO_MEMORY;
} else
fFileName = fName;
return B_OK;
}
@@ -54,13 +54,16 @@ public:
bool ResolvableCompatibleVersionMatches(
Version* resolvableVersion) const;
const String& Name() const { return fName; }
const String& Name() const { return fName; }
const String& FileName() const { return fFileName; }
private:
::Package* fPackage;
DependencyFamily* fFamily;
::Resolvable* fResolvable;
String fName;
String fFileName;
// fName with ':' replaced by '~'
Version* fVersion;
BPackageResolvableOperator fVersionOperator;