packagefs: Remove the packages directory node monitoring
This commit is contained in:
parent
3d53bd473b
commit
af5c10ab19
@ -16,8 +16,6 @@
|
|||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include <fs/KPath.h>
|
#include <fs/KPath.h>
|
||||||
#include <fs/node_monitor.h>
|
|
||||||
#include <Notifications.h>
|
|
||||||
#include <team.h>
|
#include <team.h>
|
||||||
#include <vfs.h>
|
#include <vfs.h>
|
||||||
|
|
||||||
@ -29,8 +27,7 @@ PackageDomain::PackageDomain(::Volume* volume)
|
|||||||
:
|
:
|
||||||
fVolume(volume),
|
fVolume(volume),
|
||||||
fPath(NULL),
|
fPath(NULL),
|
||||||
fDirFD(-1),
|
fDirFD(-1)
|
||||||
fListener(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +36,6 @@ PackageDomain::~PackageDomain()
|
|||||||
{
|
{
|
||||||
PRINT("PackageDomain::~PackageDomain()\n");
|
PRINT("PackageDomain::~PackageDomain()\n");
|
||||||
|
|
||||||
if (fListener != NULL) {
|
|
||||||
remove_node_listener(fDeviceID, fNodeID, *fListener);
|
|
||||||
delete fListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
Package* package = fPackages.Clear(true);
|
Package* package = fPackages.Clear(true);
|
||||||
while (package != NULL) {
|
while (package != NULL) {
|
||||||
Package* next = package->FileNameHashTableNext();
|
Package* next = package->FileNameHashTableNext();
|
||||||
@ -128,21 +120,6 @@ PackageDomain::Init(const char* path, struct stat* _st)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
PackageDomain::Prepare(NotificationListener* listener)
|
|
||||||
{
|
|
||||||
ObjectDeleter<NotificationListener> listenerDeleter(listener);
|
|
||||||
|
|
||||||
status_t error = add_node_listener(fDeviceID, fNodeID, B_WATCH_DIRECTORY,
|
|
||||||
*listener);
|
|
||||||
if (error != B_OK)
|
|
||||||
RETURN_ERROR(error);
|
|
||||||
fListener = listenerDeleter.Detach();
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageDomain::AddPackage(Package* package)
|
PackageDomain::AddPackage(Package* package)
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
|
|
||||||
class NotificationListener;
|
|
||||||
class Volume;
|
class Volume;
|
||||||
|
|
||||||
|
|
||||||
@ -32,8 +31,6 @@ public:
|
|||||||
ino_t NodeID() { return fNodeID; }
|
ino_t NodeID() { return fNodeID; }
|
||||||
|
|
||||||
status_t Init(const char* path, struct stat* _st);
|
status_t Init(const char* path, struct stat* _st);
|
||||||
status_t Prepare(NotificationListener* listener);
|
|
||||||
// takes over ownership of the listener
|
|
||||||
|
|
||||||
void AddPackage(Package* package);
|
void AddPackage(Package* package);
|
||||||
void RemovePackage(Package* package);
|
void RemovePackage(Package* package);
|
||||||
@ -49,7 +46,6 @@ private:
|
|||||||
int fDirFD;
|
int fDirFD;
|
||||||
dev_t fDeviceID;
|
dev_t fDeviceID;
|
||||||
ino_t fNodeID;
|
ino_t fNodeID;
|
||||||
NotificationListener* fListener;
|
|
||||||
PackageFileNameHashTable fPackages;
|
PackageFileNameHashTable fPackages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include <Notifications.h>
|
|
||||||
#include <vfs.h>
|
#include <vfs.h>
|
||||||
|
|
||||||
#include "AttributeIndex.h"
|
#include "AttributeIndex.h"
|
||||||
@ -112,72 +111,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - DomainDirectoryEventJob
|
|
||||||
|
|
||||||
|
|
||||||
struct Volume::DomainDirectoryEventJob : Job {
|
|
||||||
DomainDirectoryEventJob(Volume* volume, PackageDomain* domain)
|
|
||||||
:
|
|
||||||
Job(volume),
|
|
||||||
fDomain(domain),
|
|
||||||
fEvent()
|
|
||||||
{
|
|
||||||
fDomain->AcquireReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~DomainDirectoryEventJob()
|
|
||||||
{
|
|
||||||
fDomain->ReleaseReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t Init(const KMessage* event)
|
|
||||||
{
|
|
||||||
RETURN_ERROR(fEvent.SetTo(event->Buffer(), -1,
|
|
||||||
KMessage::KMESSAGE_CLONE_BUFFER));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Do()
|
|
||||||
{
|
|
||||||
fVolume->_DomainListenerEventOccurred(fDomain, &fEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
PackageDomain* fDomain;
|
|
||||||
KMessage fEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - DomainDirectoryListener
|
|
||||||
|
|
||||||
|
|
||||||
struct Volume::DomainDirectoryListener : NotificationListener {
|
|
||||||
DomainDirectoryListener(Volume* volume, PackageDomain* domain)
|
|
||||||
:
|
|
||||||
fVolume(volume),
|
|
||||||
fDomain(domain)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void EventOccurred(NotificationService& service,
|
|
||||||
const KMessage* event)
|
|
||||||
{
|
|
||||||
// TODO: Remove!
|
|
||||||
// DomainDirectoryEventJob* job = new(std::nothrow)
|
|
||||||
// DomainDirectoryEventJob(fVolume, fDomain);
|
|
||||||
// if (job == NULL || job->Init(event)) {
|
|
||||||
// delete job;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fVolume->_PushJob(job);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Volume* fVolume;
|
|
||||||
PackageDomain* fDomain;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - ShineThroughDirectory
|
// #pragma mark - ShineThroughDirectory
|
||||||
|
|
||||||
|
|
||||||
@ -870,20 +803,6 @@ Volume::_AddPackageDomain(PackageDomain* domain, bool notify)
|
|||||||
{
|
{
|
||||||
dprintf("packagefs: Adding package domain \"%s\"\n", domain->Path());
|
dprintf("packagefs: Adding package domain \"%s\"\n", domain->Path());
|
||||||
|
|
||||||
// create a directory listener
|
|
||||||
DomainDirectoryListener* listener = new(std::nothrow)
|
|
||||||
DomainDirectoryListener(this, domain);
|
|
||||||
if (listener == NULL)
|
|
||||||
RETURN_ERROR(B_NO_MEMORY);
|
|
||||||
|
|
||||||
// prepare the package domain
|
|
||||||
status_t error = domain->Prepare(listener);
|
|
||||||
if (error != B_OK) {
|
|
||||||
ERROR("Failed to prepare package domain \"%s\": %s\n",
|
|
||||||
domain->Path(), strerror(errno));
|
|
||||||
RETURN_ERROR(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
// iterate through the dir and create packages
|
// iterate through the dir and create packages
|
||||||
int fd = dup(domain->DirectoryFD());
|
int fd = dup(domain->DirectoryFD());
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -904,9 +823,15 @@ Volume::_AddPackageDomain(PackageDomain* domain, bool notify)
|
|||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_DomainEntryCreated(domain, domain->DeviceID(), domain->NodeID(),
|
Package* package;
|
||||||
-1, entry->d_name, false, notify);
|
if (_LoadPackage(domain, entry->d_name, package) != B_OK)
|
||||||
// TODO: -1 node ID?
|
continue;
|
||||||
|
BReference<Package> packageReference(package, true);
|
||||||
|
|
||||||
|
VolumeWriteLocker systemVolumeLocker(_SystemVolumeIfNotSelf());
|
||||||
|
VolumeWriteLocker volumeLocker(this);
|
||||||
|
domain->AddPackage(package);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the packages to the node tree
|
// add the packages to the node tree
|
||||||
@ -914,7 +839,7 @@ Volume::_AddPackageDomain(PackageDomain* domain, bool notify)
|
|||||||
VolumeWriteLocker volumeLocker(this);
|
VolumeWriteLocker volumeLocker(this);
|
||||||
for (PackageFileNameHashTable::Iterator it
|
for (PackageFileNameHashTable::Iterator it
|
||||||
= domain->Packages().GetIterator(); Package* package = it.Next();) {
|
= domain->Packages().GetIterator(); Package* package = it.Next();) {
|
||||||
error = _AddPackageContent(package, notify);
|
status_t error = _AddPackageContent(package, notify);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
for (it.Rewind(); Package* activePackage = it.Next();) {
|
for (it.Rewind(); Package* activePackage = it.Next();) {
|
||||||
if (activePackage == package)
|
if (activePackage == package)
|
||||||
@ -1411,141 +1336,6 @@ Volume::_RemoveNodeAndVNode(Node* node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Volume::_DomainListenerEventOccurred(PackageDomain* domain,
|
|
||||||
const KMessage* event)
|
|
||||||
{
|
|
||||||
int32 opcode;
|
|
||||||
if (event->What() != B_NODE_MONITOR
|
|
||||||
|| event->FindInt32("opcode", &opcode) != B_OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (opcode) {
|
|
||||||
case B_ENTRY_CREATED:
|
|
||||||
{
|
|
||||||
int32 device;
|
|
||||||
int64 directory;
|
|
||||||
int64 node;
|
|
||||||
const char* name;
|
|
||||||
if (event->FindInt32("device", &device) == B_OK
|
|
||||||
&& event->FindInt64("directory", &directory) == B_OK
|
|
||||||
&& event->FindInt64("node", &node) == B_OK
|
|
||||||
&& event->FindString("name", &name) == B_OK) {
|
|
||||||
_DomainEntryCreated(domain, device, directory, node, name,
|
|
||||||
true, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_ENTRY_REMOVED:
|
|
||||||
{
|
|
||||||
int32 device;
|
|
||||||
int64 directory;
|
|
||||||
int64 node;
|
|
||||||
const char* name;
|
|
||||||
if (event->FindInt32("device", &device) == B_OK
|
|
||||||
&& event->FindInt64("directory", &directory) == B_OK
|
|
||||||
&& event->FindInt64("node", &node) == B_OK
|
|
||||||
&& event->FindString("name", &name) == B_OK) {
|
|
||||||
_DomainEntryRemoved(domain, device, directory, node, name,
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case B_ENTRY_MOVED:
|
|
||||||
{
|
|
||||||
int32 device;
|
|
||||||
int64 fromDirectory;
|
|
||||||
int64 toDirectory;
|
|
||||||
int32 nodeDevice;
|
|
||||||
int64 node;
|
|
||||||
const char* fromName;
|
|
||||||
const char* name;
|
|
||||||
if (event->FindInt32("device", &device) == B_OK
|
|
||||||
&& event->FindInt64("from directory", &fromDirectory) == B_OK
|
|
||||||
&& event->FindInt64("to directory", &toDirectory) == B_OK
|
|
||||||
&& event->FindInt32("node device", &nodeDevice) == B_OK
|
|
||||||
&& event->FindInt64("node", &node) == B_OK
|
|
||||||
&& event->FindString("from name", &fromName) == B_OK
|
|
||||||
&& event->FindString("name", &name) == B_OK) {
|
|
||||||
_DomainEntryMoved(domain, device, fromDirectory, toDirectory,
|
|
||||||
nodeDevice, node, fromName, name, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Volume::_DomainEntryCreated(PackageDomain* domain, dev_t deviceID,
|
|
||||||
ino_t directoryID, ino_t nodeID, const char* name, bool addContent,
|
|
||||||
bool notify)
|
|
||||||
{
|
|
||||||
// let's see, if things look plausible
|
|
||||||
if (deviceID != domain->DeviceID() || directoryID != domain->NodeID()
|
|
||||||
|| domain->FindPackage(name) != NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Package* package;
|
|
||||||
if (_LoadPackage(domain, name, package) != B_OK)
|
|
||||||
return;
|
|
||||||
BReference<Package> packageReference(package, true);
|
|
||||||
|
|
||||||
VolumeWriteLocker systemVolumeLocker(_SystemVolumeIfNotSelf());
|
|
||||||
VolumeWriteLocker volumeLocker(this);
|
|
||||||
domain->AddPackage(package);
|
|
||||||
|
|
||||||
// add the package to the node tree
|
|
||||||
if (addContent) {
|
|
||||||
status_t error = _AddPackageContent(package, notify);
|
|
||||||
if (error != B_OK) {
|
|
||||||
domain->RemovePackage(package);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Volume::_DomainEntryRemoved(PackageDomain* domain, dev_t deviceID,
|
|
||||||
ino_t directoryID, ino_t nodeID, const char* name, bool notify)
|
|
||||||
{
|
|
||||||
// let's see, if things look plausible
|
|
||||||
if (deviceID != domain->DeviceID() || directoryID != domain->NodeID())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Package* package = domain->FindPackage(name);
|
|
||||||
if (package == NULL)
|
|
||||||
return;
|
|
||||||
BReference<Package> packageReference(package);
|
|
||||||
|
|
||||||
// remove the package
|
|
||||||
VolumeWriteLocker systemVolumeLocker(_SystemVolumeIfNotSelf());
|
|
||||||
VolumeWriteLocker volumeLocker(this);
|
|
||||||
_RemovePackageContent(package, NULL, true);
|
|
||||||
domain->RemovePackage(package);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Volume::_DomainEntryMoved(PackageDomain* domain, dev_t deviceID,
|
|
||||||
ino_t fromDirectoryID, ino_t toDirectoryID, dev_t nodeDeviceID,
|
|
||||||
ino_t nodeID, const char* fromName, const char* name, bool notify)
|
|
||||||
{
|
|
||||||
_DomainEntryRemoved(domain, deviceID, fromDirectoryID, nodeID, fromName,
|
|
||||||
notify);
|
|
||||||
_DomainEntryCreated(domain, deviceID, toDirectoryID, nodeID, name, true,
|
|
||||||
notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*static*/ status_t
|
/*static*/ status_t
|
||||||
Volume::_LoadPackage(PackageDomain* domain, const char* name,
|
Volume::_LoadPackage(PackageDomain* domain, const char* name,
|
||||||
Package*& _package)
|
Package*& _package)
|
||||||
|
@ -108,15 +108,10 @@ private:
|
|||||||
struct Job;
|
struct Job;
|
||||||
struct AddPackageDomainJob;
|
struct AddPackageDomainJob;
|
||||||
struct DomainDirectoryEventJob;
|
struct DomainDirectoryEventJob;
|
||||||
struct PackageLoaderErrorOutput;
|
|
||||||
struct PackageLoaderContentHandler;
|
|
||||||
struct DomainDirectoryListener;
|
|
||||||
struct ShineThroughDirectory;
|
struct ShineThroughDirectory;
|
||||||
struct ActivationChangeRequest;
|
struct ActivationChangeRequest;
|
||||||
|
|
||||||
friend struct AddPackageDomainJob;
|
friend struct AddPackageDomainJob;
|
||||||
friend struct DomainDirectoryEventJob;
|
|
||||||
friend struct DomainDirectoryListener;
|
|
||||||
|
|
||||||
typedef DoublyLinkedList<Job> JobList;
|
typedef DoublyLinkedList<Job> JobList;
|
||||||
typedef DoublyLinkedList<PackageDomain> PackageDomainList;
|
typedef DoublyLinkedList<PackageDomain> PackageDomainList;
|
||||||
@ -160,23 +155,6 @@ private:
|
|||||||
void _RemoveNodeAndVNode(Node* node);
|
void _RemoveNodeAndVNode(Node* node);
|
||||||
// caller must hold a reference
|
// caller must hold a reference
|
||||||
|
|
||||||
void _DomainListenerEventOccurred(
|
|
||||||
PackageDomain* domain,
|
|
||||||
const KMessage* event);
|
|
||||||
void _DomainEntryCreated(PackageDomain* domain,
|
|
||||||
dev_t deviceID, ino_t directoryID,
|
|
||||||
ino_t nodeID, const char* name,
|
|
||||||
bool addContent, bool notify);
|
|
||||||
void _DomainEntryRemoved(PackageDomain* domain,
|
|
||||||
dev_t deviceID, ino_t directoryID,
|
|
||||||
ino_t nodeID, const char* name,
|
|
||||||
bool notify);
|
|
||||||
void _DomainEntryMoved(PackageDomain* domain,
|
|
||||||
dev_t deviceID, ino_t fromDirectoryID,
|
|
||||||
ino_t toDirectoryID, dev_t nodeDeviceID,
|
|
||||||
ino_t nodeID, const char* fromName,
|
|
||||||
const char* name, bool notify);
|
|
||||||
|
|
||||||
static status_t _LoadPackage(PackageDomain* domain,
|
static status_t _LoadPackage(PackageDomain* domain,
|
||||||
const char* name, Package*& _package);
|
const char* name, Package*& _package);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user