From bf2657c5d7fa78dca270519c7e77b8a43ba7b9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 8 Mar 2006 15:54:51 +0000 Subject: [PATCH] Database::Delete() now supports deleting super types as well (by deleting all sub types first). Also, if removing the type from the supporting application lists fails, this is no longer propagated to the user - the MIME type got deleted after all, and that's the purpose of this function. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16651 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/storage/mime/Database.cpp | 41 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/kits/storage/mime/Database.cpp b/src/kits/storage/mime/Database.cpp index 74dbdbbc4c..623d2883ef 100644 --- a/src/kits/storage/mime/Database.cpp +++ b/src/kits/storage/mime/Database.cpp @@ -143,20 +143,45 @@ Database::Delete(const char *type) // Open the type BEntry entry; - status_t err = entry.SetTo(type_to_filename(type).c_str()); + status_t status = entry.SetTo(type_to_filename(type).c_str()); + if (status != B_OK) + return status; + // Remove it - if (!err) - err = entry.Remove(); + if (entry.IsDirectory()) { + // We need to remove all files in this directory + BDirectory directory(&entry); + if (directory.InitCheck() == B_OK) { + size_t length = strlen(type); + char subType[B_PATH_NAME_LENGTH]; + memcpy(subType, type, length); + subType[length++] = '/'; + + BEntry subEntry; + while (directory.GetNextEntry(&subEntry) == B_OK) { + // Construct MIME type and remove it + if (subEntry.GetName(subType + length) == B_OK) { + status = Delete(subType); + if (status != B_OK) + return status; + } + } + } + } + + status = entry.Remove(); + // Notify the installed types database - if (!err) + if (status != B_OK) fInstalledTypes.RemoveType(type); // Notify the supporting apps database - if (!err) - err = fSupportingApps.DeleteSupportedTypes(type, true); + if (status != B_OK) + fSupportingApps.DeleteSupportedTypes(type, true); // Notify the monitor service - if (!err) + if (status != B_OK) _SendDeleteNotification(type); - return err; + + return status; }