From fda6d9ab6f89cadee02edfe70cb577c62cc981f9 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Fri, 10 Dec 2010 15:48:05 +0000 Subject: [PATCH] As suggested by Rene and Jerome, switch to BDirectory::Contains(), which is way cleaner. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39806 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/mail/MailProtocol.cpp | 16 ++++++++-------- src/servers/mail/DeskbarView.cpp | 23 +++++++++-------------- src/servers/mail/main.cpp | 23 +++++++++-------------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/kits/mail/MailProtocol.cpp b/src/kits/mail/MailProtocol.cpp index ff20de187f..a8fd5028b5 100644 --- a/src/kits/mail/MailProtocol.cpp +++ b/src/kits/mail/MailProtocol.cpp @@ -158,14 +158,14 @@ class TrashMonitor : public BHandler { } if (opcode == B_ENTRY_MOVED) { - entry_ref entry; + entry_ref ref; const char* name; - msg->FindInt64("to directory", &entry.directory); - msg->FindInt32("device", &entry.device); + msg->FindInt64("to directory", &ref.directory); + msg->FindInt32("device", &ref.device); msg->FindString("name", &name); - entry.set_name(name); + ref.set_name(name); - BNode node(&entry); + BNode node(&ref); int32 chain; // check it's a mail @@ -179,7 +179,7 @@ class TrashMonitor : public BHandler { // check if it was moved to trash bool moved_to_trash = false; BPath trashPath; - BPath entryPath(&entry); + BEntry entry(&ref); BVolumeRoster volumes; BVolume volume; while (volumes.GetNextVolume(&volume) == B_OK) { @@ -189,8 +189,8 @@ class TrashMonitor : public BHandler { continue; } - if (strncmp(entryPath.Path(), trashPath.Path(), - strlen(trashPath.Path())) == 0) { + BDirectory trash(trashPath.Path()); + if (trash.Contains(&entry)) { moved_to_trash = true; break; } diff --git a/src/servers/mail/DeskbarView.cpp b/src/servers/mail/DeskbarView.cpp index 59961f050b..2a62712542 100644 --- a/src/servers/mail/DeskbarView.cpp +++ b/src/servers/mail/DeskbarView.cpp @@ -126,22 +126,17 @@ void DeskbarView::AttachedToWindow() } -bool DeskbarView::_EntryInTrash(const entry_ref* entry) +bool DeskbarView::_EntryInTrash(const entry_ref* ref) { - BPath trashPath; - BPath entryPath(entry); - BVolume volume(entry->device); - if (volume.InitCheck() == B_OK - && find_directory(B_TRASH_DIRECTORY, &trashPath, false, - &volume) == B_OK) { - char path[PATH_MAX]; - strncpy(path, trashPath.Path(), sizeof(path)); - strncat(path, "/", sizeof(path)); - if (strncmp(entryPath.Path(), path, strlen(path)) == 0) - return true; - } + BEntry entry(ref); + BVolume volume(ref->device); + BPath path; + if (volume.InitCheck() != B_OK + || find_directory(B_TRASH_DIRECTORY, &path, false, &volume) != B_OK) + return false; - return false; + BDirectory trash(path.Path()); + return trash.Contains(&entry); } diff --git a/src/servers/mail/main.cpp b/src/servers/mail/main.cpp index d901c38983..c8991c6c2b 100644 --- a/src/servers/mail/main.cpp +++ b/src/servers/mail/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -633,22 +634,16 @@ bool MailDaemonApp::_IsEntryInTrash(BEntry& entry) { entry_ref ref; - entry.GetRef(&ref); - BPath trashPath; - BPath entryPath(&entry); - BVolume volume(ref.device); - if (volume.InitCheck() == B_OK - && find_directory(B_TRASH_DIRECTORY, &trashPath, - false, &volume) == B_OK) { - char path[PATH_MAX]; - strncpy(path, trashPath.Path(), sizeof(path)); - strncat(path, "/", sizeof(path)); - if (strncmp(entryPath.Path(), path, strlen(path)) == 0) - return true; - } - return false; + BVolume volume(ref.device); + BPath path; + if (volume.InitCheck() != B_OK + || find_directory(B_TRASH_DIRECTORY, &path, false, &volume) != B_OK) + return false; + + BDirectory trash(path.Path()); + return trash.Contains(&entry); }