Move PackageFamily table to PackageLinksDirectory

This commit is contained in:
Ingo Weinhold
2011-11-25 06:18:00 +01:00
parent 63875d1702
commit ad9c25bfea
4 changed files with 67 additions and 45 deletions
@@ -54,16 +54,13 @@ PackageFSRoot::GlobalUninit()
status_t status_t
PackageFSRoot::Init() PackageFSRoot::Init()
{ {
status_t error = fPackageFamilies.Init();
if (error != B_OK)
RETURN_ERROR(error);
// create package links directory // create package links directory
fPackageLinksDirectory = new(std::nothrow) PackageLinksDirectory; fPackageLinksDirectory = new(std::nothrow) PackageLinksDirectory;
if (fPackageLinksDirectory == NULL) if (fPackageLinksDirectory == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
error = fPackageLinksDirectory->Init(NULL, kPackageLinksDirectoryName); status_t error = fPackageLinksDirectory->Init(NULL,
kPackageLinksDirectoryName);
if (error != B_OK) if (error != B_OK)
RETURN_ERROR(error); RETURN_ERROR(error);
@@ -162,50 +159,14 @@ PackageFSRoot::UnregisterVolume(Volume* volume)
status_t status_t
PackageFSRoot::AddPackage(Package* package) PackageFSRoot::AddPackage(Package* package)
{ {
// Create a package family -- there might already be one, but since that's return fPackageLinksDirectory->AddPackage(package);
// unlikely, we don't bother to check and recheck later.
PackageFamily* packageFamily = new(std::nothrow) PackageFamily;
if (packageFamily == NULL)
return B_NO_MEMORY;
ObjectDeleter<PackageFamily> packageFamilyDeleter(packageFamily);
status_t error = packageFamily->Init(package);
if (error != B_OK)
RETURN_ERROR(error);
// add the family
PackageFSRootWriteLocker writeLocker(this);
if (PackageFamily* otherPackageFamily
= fPackageFamilies.Lookup(packageFamily->Name())) {
packageFamily->RemovePackage(package);
packageFamily = otherPackageFamily;
packageFamily->AddPackage(package);
} else
fPackageFamilies.Insert(packageFamilyDeleter.Detach());
// TODO:...
return B_OK;
} }
void void
PackageFSRoot::RemovePackage(Package* package) PackageFSRoot::RemovePackage(Package* package)
{ {
PackageFSRootWriteLocker writeLocker(this); fPackageLinksDirectory->RemovePackage(package);
PackageFamily* packageFamily = package->Family();
if (packageFamily == NULL)
return;
packageFamily->RemovePackage(package);
if (packageFamily->IsEmpty()) {
fPackageFamilies.Remove(packageFamily);
delete packageFamily;
}
// TODO:...
} }
@@ -13,7 +13,6 @@
#include <lock.h> #include <lock.h>
#include "PackageFamily.h"
#include "Volume.h" #include "Volume.h"
@@ -73,7 +72,6 @@ private:
ino_t fNodeID; ino_t fNodeID;
VolumeList fVolumes; VolumeList fVolumes;
Volume* fSystemVolume; Volume* fSystemVolume;
PackageFamilyHashTable fPackageFamilies;
PackageLinksDirectory* fPackageLinksDirectory; PackageLinksDirectory* fPackageLinksDirectory;
}; };
@@ -6,7 +6,10 @@
#include "PackageLinksDirectory.h" #include "PackageLinksDirectory.h"
#include <AutoDeleter.h>
#include "AttributeDirectoryCookie.h" #include "AttributeDirectoryCookie.h"
#include "DebugSupport.h"
namespace { namespace {
@@ -55,6 +58,10 @@ PackageLinksDirectory::~PackageLinksDirectory()
status_t status_t
PackageLinksDirectory::Init(Directory* parent, const char* name) PackageLinksDirectory::Init(Directory* parent, const char* name)
{ {
status_t error = fPackageFamilies.Init();
if (error != B_OK)
RETURN_ERROR(error);
return Directory::Init(parent, name); return Directory::Init(parent, name);
} }
@@ -114,3 +121,54 @@ PackageLinksDirectory::OpenAttribute(const char* name, int openMode,
{ {
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
status_t
PackageLinksDirectory::AddPackage(Package* package)
{
// Create a package family -- there might already be one, but since that's
// unlikely, we don't bother to check and recheck later.
PackageFamily* packageFamily = new(std::nothrow) PackageFamily;
if (packageFamily == NULL)
return B_NO_MEMORY;
ObjectDeleter<PackageFamily> packageFamilyDeleter(packageFamily);
status_t error = packageFamily->Init(package);
if (error != B_OK)
RETURN_ERROR(error);
// add the family
NodeWriteLocker writeLocker(this);
if (PackageFamily* otherPackageFamily
= fPackageFamilies.Lookup(packageFamily->Name())) {
packageFamily->RemovePackage(package);
packageFamily = otherPackageFamily;
packageFamily->AddPackage(package);
} else
fPackageFamilies.Insert(packageFamilyDeleter.Detach());
// TODO:...
return B_OK;
}
void
PackageLinksDirectory::RemovePackage(Package* package)
{
NodeWriteLocker writeLocker(this);
PackageFamily* packageFamily = package->Family();
if (packageFamily == NULL)
return;
packageFamily->RemovePackage(package);
if (packageFamily->IsEmpty()) {
fPackageFamilies.Remove(packageFamily);
delete packageFamily;
}
// TODO:...
}
@@ -7,6 +7,7 @@
#include "Directory.h" #include "Directory.h"
#include "PackageFamily.h"
class PackageLinksDirectory : public Directory { class PackageLinksDirectory : public Directory {
@@ -27,8 +28,12 @@ public:
virtual status_t OpenAttribute(const char* name, int openMode, virtual status_t OpenAttribute(const char* name, int openMode,
AttributeCookie*& _cookie); AttributeCookie*& _cookie);
status_t AddPackage(Package* package);
void RemovePackage(Package* package);
private: private:
timespec fModifiedTime; timespec fModifiedTime;
PackageFamilyHashTable fPackageFamilies;
}; };