Move PackageFamily table to PackageLinksDirectory

This commit is contained in:
Ingo Weinhold 2011-06-24 01:20:41 +02:00
parent b8a96de929
commit 7e57d12523
4 changed files with 67 additions and 45 deletions

View File

@ -54,16 +54,13 @@ PackageFSRoot::GlobalUninit()
status_t
PackageFSRoot::Init()
{
status_t error = fPackageFamilies.Init();
if (error != B_OK)
RETURN_ERROR(error);
// create package links directory
fPackageLinksDirectory = new(std::nothrow) PackageLinksDirectory;
if (fPackageLinksDirectory == NULL)
return B_NO_MEMORY;
error = fPackageLinksDirectory->Init(NULL, kPackageLinksDirectoryName);
status_t error = fPackageLinksDirectory->Init(NULL,
kPackageLinksDirectoryName);
if (error != B_OK)
RETURN_ERROR(error);
@ -162,50 +159,14 @@ PackageFSRoot::UnregisterVolume(Volume* volume)
status_t
PackageFSRoot::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
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;
return fPackageLinksDirectory->AddPackage(package);
}
void
PackageFSRoot::RemovePackage(Package* package)
{
PackageFSRootWriteLocker writeLocker(this);
PackageFamily* packageFamily = package->Family();
if (packageFamily == NULL)
return;
packageFamily->RemovePackage(package);
if (packageFamily->IsEmpty()) {
fPackageFamilies.Remove(packageFamily);
delete packageFamily;
}
// TODO:...
fPackageLinksDirectory->RemovePackage(package);
}

View File

@ -13,7 +13,6 @@
#include <lock.h>
#include "PackageFamily.h"
#include "Volume.h"
@ -73,7 +72,6 @@ private:
ino_t fNodeID;
VolumeList fVolumes;
Volume* fSystemVolume;
PackageFamilyHashTable fPackageFamilies;
PackageLinksDirectory* fPackageLinksDirectory;
};

View File

@ -6,7 +6,10 @@
#include "PackageLinksDirectory.h"
#include <AutoDeleter.h>
#include "AttributeDirectoryCookie.h"
#include "DebugSupport.h"
namespace {
@ -55,6 +58,10 @@ PackageLinksDirectory::~PackageLinksDirectory()
status_t
PackageLinksDirectory::Init(Directory* parent, const char* name)
{
status_t error = fPackageFamilies.Init();
if (error != B_OK)
RETURN_ERROR(error);
return Directory::Init(parent, name);
}
@ -114,3 +121,54 @@ PackageLinksDirectory::OpenAttribute(const char* name, int openMode,
{
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:...
}

View File

@ -7,6 +7,7 @@
#include "Directory.h"
#include "PackageFamily.h"
class PackageLinksDirectory : public Directory {
@ -27,8 +28,12 @@ public:
virtual status_t OpenAttribute(const char* name, int openMode,
AttributeCookie*& _cookie);
status_t AddPackage(Package* package);
void RemovePackage(Package* package);
private:
timespec fModifiedTime;
PackageFamilyHashTable fPackageFamilies;
};