* Made updating the MIME info more safe, this was just one source the registrar

could use as an excuse to die.
* Minor cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17765 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-06-07 17:13:18 +00:00
parent 9041bc71e3
commit 2d0c5e0adc
+31 -17
View File
@@ -1,7 +1,12 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file MimeUpdateThread.cpp \file MimeUpdateThread.cpp
MimeUpdateThread implementation MimeUpdateThread implementation
@@ -31,7 +36,7 @@ namespace Mime {
update_mime_info() and create_app_meta_mime() update_mime_info() and create_app_meta_mime()
*/ */
// constructor
/*! \brief Creates a new MimeUpdateThread object. /*! \brief Creates a new MimeUpdateThread object.
If \a replyee is non-NULL and construction succeeds, the MimeThreadObject If \a replyee is non-NULL and construction succeeds, the MimeThreadObject
@@ -45,16 +50,16 @@ namespace Mime {
MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority, MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority,
BMessenger managerMessenger, const entry_ref *root, bool recursive, BMessenger managerMessenger, const entry_ref *root, bool recursive,
int32 force, BMessage *replyee) int32 force, BMessage *replyee)
: RegistrarThread(name, priority, managerMessenger) : RegistrarThread(name, priority, managerMessenger),
, fRoot(root ? *root : entry_ref()) fRoot(root ? *root : entry_ref()),
, fRecursive(recursive) fRecursive(recursive),
, fForce(force) fForce(force),
, fReplyee(replyee) fReplyee(replyee),
, fStatus(root ? B_OK : B_BAD_VALUE) fStatus(root ? B_OK : B_BAD_VALUE)
{ {
} }
// destructor
/*! \brief Destroys the MimeUpdateThread object. /*! \brief Destroys the MimeUpdateThread object.
If the object was properly initialized (i.e. InitCheck() returns \c B_OK) and If the object was properly initialized (i.e. InitCheck() returns \c B_OK) and
@@ -68,7 +73,7 @@ MimeUpdateThread::~MimeUpdateThread()
delete fReplyee; delete fReplyee;
} }
// InitCheck()
/*! \brief Returns the initialization status of the object /*! \brief Returns the initialization status of the object
*/ */
status_t status_t
@@ -80,7 +85,7 @@ MimeUpdateThread::InitCheck()
return err; return err;
} }
// ThreadFunction
/*! \brief Implements the common functionality of update_mime_info() and /*! \brief Implements the common functionality of update_mime_info() and
create_app_meta_mime(), namely iterating through the filesystem and create_app_meta_mime(), namely iterating through the filesystem and
updating entries. updating entries.
@@ -89,9 +94,17 @@ status_t
MimeUpdateThread::ThreadFunction() MimeUpdateThread::ThreadFunction()
{ {
status_t err = InitCheck(); status_t err = InitCheck();
// The registrar is using this, too, so we better make sure we
// don't run into troubles
try {
// Do the updates // Do the updates
if (!err) if (!err)
err = UpdateEntry(&fRoot); err = UpdateEntry(&fRoot);
} catch (...) {
err = B_ERROR;
}
// Send a reply if we have a message to reply to // Send a reply if we have a message to reply to
if (fReplyee) { if (fReplyee) {
BMessage reply(B_REG_RESULT); BMessage reply(B_REG_RESULT);
@@ -100,6 +113,7 @@ MimeUpdateThread::ThreadFunction()
if (!err) if (!err)
err = fReplyee->SendReply(&reply); err = fReplyee->SendReply(&reply);
} }
// Flag ourselves as finished // Flag ourselves as finished
fIsFinished = true; fIsFinished = true;
// Notify the thread manager to make a cleanup run // Notify the thread manager to make a cleanup run
@@ -115,7 +129,7 @@ MimeUpdateThread::ThreadFunction()
return err; return err;
} }
// DeviceSupportsAttributes
/*! \brief Returns true if the given device supports attributes, false /*! \brief Returns true if the given device supports attributes, false
if not (or if an error occurs while determining). if not (or if an error occurs while determining).
@@ -184,14 +198,14 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref)
//printf("Updating '%s' (%s)... \n", path.Path(), //printf("Updating '%s' (%s)... \n", path.Path(),
// (DeviceSupportsAttributes(ref->device) ? "yes" : "no")); // (DeviceSupportsAttributes(ref->device) ? "yes" : "no"));
if (!err if (!err && (device_is_root_device(ref->device)
&& (device_is_root_device(ref->device)
|| DeviceSupportsAttributes(ref->device))) { || DeviceSupportsAttributes(ref->device))) {
// Update this entry // Update this entry
if (!err) { if (!err) {
// R5 appears to ignore whether or not the update succeeds. // R5 appears to ignore whether or not the update succeeds.
DoMimeUpdate(ref, &entryIsDir); DoMimeUpdate(ref, &entryIsDir);
} }
// If we're recursing and this is a directory, update // If we're recursing and this is a directory, update
// each of the directory's children as well // each of the directory's children as well
if (!err && fRecursive && entryIsDir) { if (!err && fRecursive && entryIsDir) {