Adjust Database{Location} to only attempt to create a mimetype when
actually necessary, and fail otherwise if a writable version doesn't yet
exist. Correspondingly, adjust callers such as
DatabaseLocation::DeleteAttribute(). Fixes a problem where a caller asking
to perform a mimeset could fail early due to SetSupportedTypes() attempting
to update the read-only mime database entry supplied by a package, and
consequently most of the mimeset operations would be skipped.
This commit is contained in:
Rene Gollent
2014-01-20 20:52:32 -05:00
parent d56476656e
commit 701a5d6b79
4 changed files with 36 additions and 34 deletions
@@ -38,9 +38,9 @@ public:
// opening type nodes // opening type nodes
status_t OpenType(const char* type, BNode& _node) const; status_t OpenType(const char* type, BNode& _node) const;
status_t OpenOrCreateType(const char* type, status_t OpenWritableType(const char* type,
BNode& _node, bool* _didCreate = NULL) BNode& _node, bool create,
const; bool* _didCreate = NULL) const;
// generic type attributes access // generic type attributes access
+5 -4
View File
@@ -1,10 +1,11 @@
/* /*
* Copyright 2002-2006, Haiku. * Copyright 2002-2014, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Tyler Dauwalder * Tyler Dauwalder
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Rene Gollent, [email protected].
*/ */
@@ -126,7 +127,7 @@ Database::Install(const char *type)
else { else {
bool didCreate = false; bool didCreate = false;
BNode node; BNode node;
err = fLocation->OpenOrCreateType(type, node, &didCreate); err = fLocation->OpenWritableType(type, node, true, &didCreate);
if (!err && didCreate) { if (!err && didCreate) {
fInstalledTypes.AddType(type); fInstalledTypes.AddType(type);
_SendInstallNotification(type); _SendInstallNotification(type);
@@ -443,7 +444,7 @@ Database::SetIconForType(const char *type, const char *fileType,
BNode node; BNode node;
bool didCreate = false; bool didCreate = false;
status_t err = fLocation->OpenOrCreateType(type, node, &didCreate); status_t err = fLocation->OpenWritableType(type, node, true, &didCreate);
if (err != B_OK) if (err != B_OK)
return err; return err;
@@ -504,7 +505,7 @@ Database::SetIconForType(const char *type, const char *fileType,
BNode node; BNode node;
bool didCreate = false; bool didCreate = false;
status_t err = fLocation->OpenOrCreateType(type, node, &didCreate); status_t err = fLocation->OpenWritableType(type, node, true, &didCreate);
if (err != B_OK) if (err != B_OK)
return err; return err;
+22 -22
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2002-2013, Haiku, Inc. All Rights Reserved. * Copyright 2002-2014, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Tyler Dauwalder * Tyler Dauwalder
* Rene Gollent, [email protected].
* Ingo Weinhold <[email protected]> * Ingo Weinhold <[email protected]>
*/ */
@@ -69,16 +70,16 @@ DatabaseLocation::OpenType(const char* type, BNode& _node) const
/*! \brief Opens a BNode on the given type, creating a node of the /*! \brief Opens a BNode on the given type, creating a node of the
appropriate flavor if necessary. appropriate flavor if requested (and necessary).
All MIME types are converted to lowercase for use in the filesystem. All MIME types are converted to lowercase for use in the filesystem.
\param type The MIME type to open. \param type The MIME type to open.
\param _node Node opened on the given MIME type. \param _node Node opened on the given MIME type.
\param _didCreate If not \c NULL, the variable the pointer refers to is \param _didCreate If not \c NULL, the variable the pointer refers to is
set to \c true, if the node has been newly create, to \c false set to \c true, if the node has been newly created, to \c false
otherwise. otherwise.
*/ */
status_t status_t
DatabaseLocation::OpenOrCreateType(const char* type, BNode& _node, DatabaseLocation::OpenWritableType(const char* type, BNode& _node, bool create,
bool* _didCreate) const bool* _didCreate) const
{ {
if (_didCreate) if (_didCreate)
@@ -90,6 +91,8 @@ DatabaseLocation::OpenOrCreateType(const char* type, BNode& _node,
if (error == B_OK) { if (error == B_OK) {
if (index == 0) if (index == 0)
return B_OK; return B_OK;
else if (!create)
return B_ENTRY_NOT_FOUND;
// The caller wants a editable node, but the node found is not in the // The caller wants a editable node, but the node found is not in the
// user's settings directory. Copy the node. // user's settings directory. Copy the node.
@@ -106,7 +109,8 @@ DatabaseLocation::OpenOrCreateType(const char* type, BNode& _node,
if (_didCreate != NULL) if (_didCreate != NULL)
*_didCreate = true; *_didCreate = true;
return error; return error;
} } else if (!create)
return B_ENTRY_NOT_FOUND;
// type doesn't exist yet -- create the respective node // type doesn't exist yet -- create the respective node
error = _CreateTypeNode(type, _node); error = _CreateTypeNode(type, _node);
@@ -256,7 +260,7 @@ DatabaseLocation::WriteAttribute(const char* type, const char* attribute,
return B_BAD_VALUE; return B_BAD_VALUE;
BNode node; BNode node;
status_t error = OpenOrCreateType(type, node, _didCreate); status_t error = OpenWritableType(type, node, true, _didCreate);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -312,14 +316,10 @@ DatabaseLocation::DeleteAttribute(const char* type, const char* attribute) const
return B_BAD_VALUE; return B_BAD_VALUE;
BNode node; BNode node;
int32 index; status_t error = OpenWritableType(type, node, false);
status_t error = _OpenType(type, node, index);
if (error != B_OK) if (error != B_OK)
return error; return error;
if (index != 0)
return B_NOT_ALLOWED;
return node.RemoveAttr(attribute); return node.RemoveAttr(attribute);
} }
@@ -327,7 +327,7 @@ DatabaseLocation::DeleteAttribute(const char* type, const char* attribute) const
/*! \brief Fetches the application hint for the given MIME type. /*! \brief Fetches the application hint for the given MIME type.
The entry_ref pointed to by \c ref must be pre-allocated. The entry_ref pointed to by \c ref must be pre-allocated.
\param type The MIME type of interest \param type The MIME type of interest
\param _ref Reference to a pre-allocated \c entry_ref struct into \param _ref Reference to a pre-allocated \c entry_ref struct into
which the location of the hint application is copied. which the location of the hint application is copied.
@@ -418,7 +418,7 @@ DatabaseLocation::GetShortDescription(const char* type, char* description)
/*! The string pointed to by \c description must be long enough to /*! The string pointed to by \c description must be long enough to
hold the long description; a length of \c B_MIME_TYPE_LENGTH is hold the long description; a length of \c B_MIME_TYPE_LENGTH is
recommended. recommended.
\param type The MIME type of interest \param type The MIME type of interest
\param description Pointer to a pre-allocated string into which the long \param description Pointer to a pre-allocated string into which the long
description is copied. If the function fails, the contents of the string description is copied. If the function fails, the contents of the string
@@ -465,7 +465,7 @@ DatabaseLocation::GetFileExtensions(const char* type, BMessage& _extensions)
_extensions.what = 234; // Don't know why, but that's what R5 does. _extensions.what = 234; // Don't know why, but that's what R5 does.
err = _extensions.AddString("type", type); err = _extensions.AddString("type", type);
} }
return err; return err;
} }
@@ -524,7 +524,7 @@ DatabaseLocation::GetIcon(const char* type, uint8*& _data, size_t& _size)
\return \return
- \c B_OK: Success - \c B_OK: Success
- \c B_ENTRY_NOT_FOUND: No icon of the given size exists for the given type - \c B_ENTRY_NOT_FOUND: No icon of the given size exists for the given type
- "error code": Failure - "error code": Failure
*/ */
status_t status_t
@@ -562,7 +562,7 @@ DatabaseLocation::GetIconForType(const char* type, const char* fileType,
largeIconAttrName, which, &_icon); largeIconAttrName, which, &_icon);
// ssize_t err = type && icon ? B_OK : B_BAD_VALUE; // ssize_t err = type && icon ? B_OK : B_BAD_VALUE;
// //
// // Figure out what kind of data we *should* find // // Figure out what kind of data we *should* find
// uint32 attrType = 0; // uint32 attrType = 0;
// ssize_t attrSize = 0; // ssize_t attrSize = 0;
@@ -586,7 +586,7 @@ DatabaseLocation::GetIconForType(const char* type, const char* fileType,
// } // }
// } // }
// // Construct our attribute name // // Construct our attribute name
// std::string attr; // std::string attr;
// if (fileType) { // if (fileType) {
// attr = (which == B_MINI_ICON // attr = (which == B_MINI_ICON
// ? kMiniIconAttrPrefix // ? kMiniIconAttrPrefix
@@ -602,11 +602,11 @@ DatabaseLocation::GetIconForType(const char* type, const char* fileType,
// } // }
// //
// BNode node; // BNode node;
// if (!err) // if (!err)
// err = open_type(type, &node); // err = open_type(type, &node);
// //
// attr_info info; // attr_info info;
// if (!err) // if (!err)
// err = node.GetAttrInfo(attr.c_str(), &info); // err = node.GetAttrInfo(attr.c_str(), &info);
// //
// if (!err) // if (!err)
@@ -620,8 +620,8 @@ DatabaseLocation::GetIconForType(const char* type, const char* fileType,
// buffer = new(std::nothrow) char[attrSize]; // buffer = new(std::nothrow) char[attrSize];
// if (!buffer) // if (!buffer)
// err = B_NO_MEMORY; // err = B_NO_MEMORY;
// if (!err) // if (!err)
// err = node.ReadAttr(attr.c_str(), attrType, 0, buffer, attrSize); // err = node.ReadAttr(attr.c_str(), attrType, 0, buffer, attrSize);
// } else { // } else {
// // same color space, just read direct // // same color space, just read direct
// err = node.ReadAttr(attr.c_str(), attrType, 0, icon->Bits(), attrSize); // err = node.ReadAttr(attr.c_str(), attrType, 0, icon->Bits(), attrSize);
@@ -775,7 +775,7 @@ DatabaseLocation::GetSupportedTypes(const char* type, BMessage& _types)
err = B_OK; err = B_OK;
} }
if (err == B_OK) { if (err == B_OK) {
_types.what = 0; _types.what = 0;
err = _types.AddString("type", type); err = _types.AddString("type", type);
} }
return err; return err;
+6 -5
View File
@@ -1,11 +1,12 @@
/* /*
* Copyright 2002-2013, Haiku, Inc. All Rights Reserved. * Copyright 2002-2014, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Tyler Dauwalder * Tyler Dauwalder
* Jonas Sundström, jonas@kirilla.com * Rene Gollent, rene@gollent.com.
* Michael Lotz, mmlr@mlotz.ch * Michael Lotz, mmlr@mlotz.ch
* Jonas Sundström, jonas@kirilla.com
* Ingo Weinhold, ingo_weinhold@gmx.de * Ingo Weinhold, ingo_weinhold@gmx.de
*/ */
@@ -131,9 +132,9 @@ MimeInfoUpdater::Do(const entry_ref& entry, bool* _entryIsDir)
BAppFileInfo appFileInfoWrite; BAppFileInfo appFileInfoWrite;
if (!err && updateAppInfo && node.IsFile() if (!err && updateAppInfo && node.IsFile()
&& is_shared_object_mime_type(type) && is_shared_object_mime_type(type)
&& file.SetTo(&entry, B_READ_WRITE) == B_OK && (err = file.SetTo(&entry, B_READ_WRITE)) == B_OK
&& appFileInfoRead.SetTo(&file) == B_OK && (err = appFileInfoRead.SetTo(&file)) == B_OK
&& appFileInfoWrite.SetTo(&file) == B_OK) { && (err = appFileInfoWrite.SetTo(&file)) == B_OK) {
// we read from resources and write to attributes // we read from resources and write to attributes
appFileInfoRead.SetInfoLocation(B_USE_RESOURCES); appFileInfoRead.SetInfoLocation(B_USE_RESOURCES);