1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "PackageDirectory.h" 8 #include "Package.h" 9 10 #include "ClassCache.h" 11 12 13 CLASS_CACHE(PackageDirectory); 14 15 16 PackageDirectory::PackageDirectory(Package* package, mode_t mode) 17 : 18 PackageNode(package, mode) 19 { 20 } 21 22 23 PackageDirectory::~PackageDirectory() 24 { 25 while (PackageNode* child = fChildren.RemoveHead()) 26 child->ReleaseReference(); 27 } 28 29 30 void 31 PackageDirectory::AddChild(PackageNode* node) 32 { 33 fChildren.Add(node); 34 node->AcquireReference(); 35 } 36 37 38 void 39 PackageDirectory::RemoveChild(PackageNode* node) 40 { 41 fChildren.Remove(node); 42 node->ReleaseReference(); 43 } 44 45 46 bool 47 PackageDirectory::HasPrecedenceOver(const PackageDirectory* other) const 48 { 49 // If one of us has the SYSTEM_PACKAGE flag and the other doesn't, 50 // let PackageNode take care of the comparison. 51 uint32 packageFlags = 0, otherPackageFlags = 0; 52 BReference<Package> package(GetPackage()), otherPackage(other->GetPackage()); 53 if (package) 54 packageFlags = package->Flags(); 55 if (otherPackage) 56 otherPackageFlags = otherPackage->Flags(); 57 if ((packageFlags & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE) 58 != (otherPackageFlags 59 & BPackageKit::B_PACKAGE_FLAG_SYSTEM_PACKAGE)) { 60 return PackageNode::HasPrecedenceOver(other); 61 } 62 63 const int32 attrs = fAttributes.Count(), 64 otherAttrs = other->fAttributes.Count(); 65 if (attrs != otherAttrs) 66 return attrs > otherAttrs; 67 return PackageNode::HasPrecedenceOver(other); 68 } 69