BPathMonitor: PathHandler::_NotifyTarget(): simplify
* Add optional entry_ref return parameter to _HasFile(). * Simplify _NotifyTarget() by using _HasDirectory() and _HasFile().
This commit is contained in:
@@ -126,7 +126,8 @@ class PathHandler : public BHandler {
|
|||||||
status_t _RemoveDirectory(const node_ref& nodeRef, ino_t directoryNode);
|
status_t _RemoveDirectory(const node_ref& nodeRef, ino_t directoryNode);
|
||||||
status_t _RemoveDirectory(BEntry& entry, ino_t directoryNode);
|
status_t _RemoveDirectory(BEntry& entry, ino_t directoryNode);
|
||||||
|
|
||||||
bool _HasFile(const node_ref& nodeRef) const;
|
bool _HasFile(const node_ref& nodeRef, const entry_ref** _ref = NULL)
|
||||||
|
const;
|
||||||
status_t _AddFile(BEntry& entry, bool notify = false);
|
status_t _AddFile(BEntry& entry, bool notify = false);
|
||||||
status_t _RemoveFile(const node_ref& nodeRef);
|
status_t _RemoveFile(const node_ref& nodeRef);
|
||||||
status_t _RemoveFile(BEntry& entry);
|
status_t _RemoveFile(BEntry& entry);
|
||||||
@@ -635,11 +636,7 @@ PathHandler::_NotifyTarget(BMessage* message, const node_ref& nodeRef) const
|
|||||||
|
|
||||||
TRACE("_NotifyTarget(): node ref %ld.%Ld\n", nodeRef.device, nodeRef.node);
|
TRACE("_NotifyTarget(): node ref %ld.%Ld\n", nodeRef.device, nodeRef.node);
|
||||||
|
|
||||||
WatchedDirectory directory;
|
if (_HasDirectory(nodeRef)) {
|
||||||
directory.node = nodeRef;
|
|
||||||
|
|
||||||
DirectorySet::const_iterator iterator = fDirectories.find(directory);
|
|
||||||
if (iterator != fDirectories.end()) {
|
|
||||||
if (_WatchFilesOnly()) {
|
if (_WatchFilesOnly()) {
|
||||||
// stat or attr notification for a directory
|
// stat or attr notification for a directory
|
||||||
return;
|
return;
|
||||||
@@ -655,13 +652,10 @@ PathHandler::_NotifyTarget(BMessage* message, const node_ref& nodeRef) const
|
|||||||
// this is bound to be a notification for a file
|
// this is bound to be a notification for a file
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileEntry setEntry;
|
|
||||||
setEntry.ref.device = nodeRef.device;
|
const entry_ref* entryRef;
|
||||||
setEntry.node = nodeRef.node;
|
if (_HasFile(nodeRef, &entryRef)) {
|
||||||
// name does not need to be set, since it's not used for comparing
|
BPath path(entryRef);
|
||||||
FileSet::const_iterator i = fFiles.find(setEntry);
|
|
||||||
if (i != fFiles.end()) {
|
|
||||||
BPath path(&(i->ref));
|
|
||||||
update.AddString("path", path.Path());
|
update.AddString("path", path.Path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -815,14 +809,20 @@ PathHandler::_RemoveDirectory(BEntry& entry, ino_t directoryNode)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PathHandler::_HasFile(const node_ref& nodeRef) const
|
PathHandler::_HasFile(const node_ref& nodeRef,
|
||||||
|
const entry_ref** _ref /*= NULL*/) const
|
||||||
{
|
{
|
||||||
FileEntry setEntry;
|
FileEntry setEntry;
|
||||||
setEntry.ref.device = nodeRef.device;
|
setEntry.ref.device = nodeRef.device;
|
||||||
setEntry.node = nodeRef.node;
|
setEntry.node = nodeRef.node;
|
||||||
// name does not need to be set, since it's not used for comparing
|
// name does not need to be set, since it's not used for comparing
|
||||||
FileSet::const_iterator iterator = fFiles.find(setEntry);
|
FileSet::const_iterator iterator = fFiles.find(setEntry);
|
||||||
return iterator != fFiles.end();
|
if (iterator == fFiles.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_ref != NULL)
|
||||||
|
*_ref = &iterator->ref;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user