Storage Kit: do what the method says in InstalledTypes::_AddSupertype

That is, just add the supertype if it does not exist. Leave getting it
to the callers that need it.

Fixes: #19653
Change-Id: I79d804161d28684e16a0d84ec3a2fb6788c0b506
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9436
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Máximo Castañeda
2025-07-01 18:07:08 +00:00
committed by waddlesplash
parent 8f149016fb
commit 45f3d65457
2 changed files with 7 additions and 13 deletions
@@ -42,8 +42,7 @@ class InstalledTypes {
status_t RemoveType(const char *type); status_t RemoveType(const char *type);
private: private:
status_t _AddSupertype(const char *super, status_t _AddSupertype(const char* super);
std::map<std::string, Supertype>::iterator &i);
status_t _AddSubtype(const char *super, const char *sub); status_t _AddSubtype(const char *super, const char *sub);
status_t _AddSubtype(Supertype &super, const char *sub); status_t _AddSubtype(Supertype &super, const char *sub);
+6 -11
View File
@@ -173,8 +173,7 @@ InstalledTypes::AddType(const char *type)
} }
if (i == len) { if (i == len) {
// Supertype only // Supertype only
std::map<std::string, Supertype>::iterator i; return _AddSupertype(type);
return _AddSupertype(type, i);
} }
// Copy the supertype // Copy the supertype
@@ -235,16 +234,14 @@ InstalledTypes::RemoveType(const char *type)
- "error code": failure - "error code": failure
*/ */
status_t status_t
InstalledTypes::_AddSupertype(const char *super, InstalledTypes::_AddSupertype(const char* super)
std::map<std::string, Supertype>::iterator &i)
{ {
if (super == NULL) if (super == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t err = B_OK; status_t err = B_OK;
i = fSupertypes.find(super); if (fSupertypes.find(super) == fSupertypes.end()) {
if (i == fSupertypes.end()) {
Supertype &supertype = fSupertypes[super]; Supertype &supertype = fSupertypes[super];
supertype.SetName(super); supertype.SetName(super);
if (fCachedMessage) if (fCachedMessage)
@@ -274,10 +271,9 @@ InstalledTypes::_AddSubtype(const char *super, const char *sub)
if (super == NULL || sub == NULL) if (super == NULL || sub == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
std::map<std::string, Supertype>::iterator i; status_t err = _AddSupertype(super);
status_t err = _AddSupertype(super, i);
if (!err) if (!err)
err = _AddSubtype(i->second, sub); err = _AddSubtype(fSupertypes[super], sub);
return err; return err;
} }
@@ -408,8 +404,7 @@ InstalledTypes::_BuildInstalledTypesList()
BPrivate::Storage::to_lower(supertype); BPrivate::Storage::to_lower(supertype);
// Add this supertype // Add this supertype
std::map<std::string, Supertype>::iterator i; if (_AddSupertype(supertype) != B_OK)
if (_AddSupertype(supertype, i) != B_OK)
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList()" DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList()"
" -- Error adding supertype '%s': 0x%" B_PRIx32 "\n", " -- Error adding supertype '%s': 0x%" B_PRIx32 "\n",
supertype, err)); supertype, err));