From 3209bc40c523d63e98d635ae302df6bece0966d3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 22 Jun 2013 13:41:48 +0200 Subject: [PATCH] BPathMonitor: PathHandler::_NotifyTarget(): simplify * Add optional entry_ref return parameter to _HasFile(). * Simplify _NotifyTarget() by using _HasDirectory() and _HasFile(). --- src/kits/storage/PathMonitor.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kits/storage/PathMonitor.cpp b/src/kits/storage/PathMonitor.cpp index cab06a52da..9e43750d0f 100644 --- a/src/kits/storage/PathMonitor.cpp +++ b/src/kits/storage/PathMonitor.cpp @@ -126,7 +126,8 @@ class PathHandler : public BHandler { status_t _RemoveDirectory(const node_ref& nodeRef, 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 _RemoveFile(const node_ref& nodeRef); 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); - WatchedDirectory directory; - directory.node = nodeRef; - - DirectorySet::const_iterator iterator = fDirectories.find(directory); - if (iterator != fDirectories.end()) { + if (_HasDirectory(nodeRef)) { if (_WatchFilesOnly()) { // stat or attr notification for a directory return; @@ -655,13 +652,10 @@ PathHandler::_NotifyTarget(BMessage* message, const node_ref& nodeRef) const // this is bound to be a notification for a file return; } - FileEntry setEntry; - setEntry.ref.device = nodeRef.device; - setEntry.node = nodeRef.node; - // name does not need to be set, since it's not used for comparing - FileSet::const_iterator i = fFiles.find(setEntry); - if (i != fFiles.end()) { - BPath path(&(i->ref)); + + const entry_ref* entryRef; + if (_HasFile(nodeRef, &entryRef)) { + BPath path(entryRef); update.AddString("path", path.Path()); } } @@ -815,14 +809,20 @@ PathHandler::_RemoveDirectory(BEntry& entry, ino_t directoryNode) bool -PathHandler::_HasFile(const node_ref& nodeRef) const +PathHandler::_HasFile(const node_ref& nodeRef, + const entry_ref** _ref /*= NULL*/) const { FileEntry setEntry; setEntry.ref.device = nodeRef.device; setEntry.node = nodeRef.node; // name does not need to be set, since it's not used for comparing 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; }