Resolve #10435.
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:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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, rene@gollent.com.
|
||||||
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
* Ingo Weinhold <ingo_weinhold@gmx.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user