From 5301f108efb9e3d82920fc6c4d3488d69772a4eb Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 5 Aug 2018 18:24:02 -0400 Subject: [PATCH] packagefs: Directories with more attributes take precedence over ones with less. This still preserves the behavior that system packages take precedence over non-system packages. Fixes #10071 (at last.) --- .../packagefs/package/PackageDirectory.cpp | 20 +++++++++++++++++++ .../packagefs/package/PackageDirectory.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.cpp b/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.cpp index e24542c6f3..2cfaaff884 100644 --- a/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.cpp @@ -5,6 +5,7 @@ #include "PackageDirectory.h" +#include "Package.h" PackageDirectory::PackageDirectory(Package* package, mode_t mode) @@ -35,3 +36,22 @@ PackageDirectory::RemoveChild(PackageNode* node) fChildren.Remove(node); node->ReleaseReference(); } + + +bool +PackageDirectory::operator<(const PackageDirectory& other) const +{ + // If one of us has the SYSTEM_PACKAGE flag and the other doesn't, + // let PackageNode take care of the comparison. + if ((fPackageFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE) + != (other.fPackageFlags + & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)) { + return PackageNode::operator<(other); + } + + const int32 attrs = fAttributes.Count(), + otherAttrs = other.fAttributes.Count(); + if (attrs != otherAttrs) + return attrs < otherAttrs; + return PackageNode::operator<(other); +} diff --git a/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.h b/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.h index 624b8694c8..6f2ddad140 100644 --- a/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.h +++ b/src/add-ons/kernel/file_systems/packagefs/package/PackageDirectory.h @@ -26,6 +26,10 @@ public: const PackageNodeList& Children() const { return fChildren; } + bool operator<(const PackageDirectory& other) const; + inline bool operator>(const PackageDirectory& other) const + { return other < *this; } + private: PackageNodeList fChildren; };