PackageItem: Fixed rewriting item paths

* The version of BString::Replace() that was used takes the offset at which
   replacing should start, not the number of replacements. So did this ever
   work? Use ReplaceFirst() instead.
 * Address the performance issues which Pawel commented on, plus some more.
 * I've left some debug output in the code (commented out), since I want to
   work on this some more. For example, I noticed that GoBe Productive puts
   files into /boot/beos/...
This commit is contained in:
Stephan Aßmus
2014-02-11 23:19:12 +01:00
parent ad1c3c44bf
commit be94359ce4
+35 -22
View File
@@ -177,52 +177,65 @@ PackageItem::InitPath(const char *path, BPath *destination)
status_t ret = B_OK; status_t ret = B_OK;
if (fPathType == P_INSTALL_PATH) { if (fPathType == P_INSTALL_PATH) {
if (!path) { // printf("InitPath - relative: %s + %s\n", path, fPath.String());
if (path == NULL) {
parser_debug("InitPath path is NULL\n"); parser_debug("InitPath path is NULL\n");
return B_ERROR; return B_ERROR;
} }
ret = destination->SetTo(path, fPath.String()); ret = destination->SetTo(path, fPath.String());
} } else if (fPathType == P_SYSTEM_PATH) {
else if (fPathType == P_SYSTEM_PATH) // printf("InitPath - absolute: %s\n", fPath.String());
ret = destination->SetTo(fPath.String()); ret = destination->SetTo(fPath.String());
else { } else {
if (!path) { // printf("InitPath - volume: %s + %s\n", path, fPath.String());
if (path == NULL) {
parser_debug("InitPath path is NULL\n"); parser_debug("InitPath path is NULL\n");
return B_ERROR; return B_ERROR;
} }
BVolume volume(dev_for_path(path)); BVolume volume(dev_for_path(path));
ret = volume.InitCheck(); ret = volume.InitCheck();
if (ret != B_OK) if (ret == B_OK) {
return ret;
BDirectory temp; BDirectory temp;
ret = volume.GetRootDirectory(&temp); ret = volume.GetRootDirectory(&temp);
if (ret != B_OK) if (ret == B_OK) {
return ret;
BPath mountPoint(&temp, NULL); BPath mountPoint(&temp, NULL);
ret = destination->SetTo(mountPoint.Path(), fPath.String()); ret = destination->SetTo(mountPoint.Path(), fPath.String());
} }
}
}
BPath systemNonPackagedDir; if (ret != B_OK) {
find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY, &systemNonPackagedDir); fprintf(stderr, "InitPath(%s): %s\n", path, strerror(ret));
return ret;
BPath userNonPackagedDir; }
find_directory(B_USER_NONPACKAGED_DIRECTORY, &userNonPackagedDir);
BString pathString(destination->Path()); BString pathString(destination->Path());
// Hardcoded paths, the .pkg files hardcode this to the same // Hardcoded paths, the .pkg files hardcode this to the same
if (pathString.FindFirst("/boot/system") == 0 && pathString.FindFirst("non-packaged") == B_ERROR) { if (pathString.FindFirst("non-packaged") < 0) {
pathString.Replace("/boot/system", systemNonPackagedDir.Path(), 1); bool wasRewritten = false;
}
if (pathString.StartsWith("/boot/system")) {
if (pathString.FindFirst("/boot/home/config") == 0 && pathString.FindFirst("non-packaged") == B_ERROR) { BPath systemNonPackagedDir;
pathString.Replace("/boot/home/config", userNonPackagedDir.Path(), 1); find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY,
&systemNonPackagedDir);
pathString.ReplaceFirst("/boot/system",
systemNonPackagedDir.Path());
wasRewritten = true;
} else if (pathString.StartsWith("/boot/home/config")) {
BPath userNonPackagedDir;
find_directory(B_USER_NONPACKAGED_DIRECTORY, &userNonPackagedDir);
pathString.ReplaceFirst("/boot/home/config",
userNonPackagedDir.Path());
wasRewritten = true;
} }
if (wasRewritten) {
// printf("rewritten: %s\n", pathString.String());
destination->SetTo(pathString.String()); destination->SetTo(pathString.String());
}
}
return ret; return ret;
} }