From 2d0c5e0adcca4251bb580f874f01691ffd435796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 7 Jun 2006 17:13:18 +0000 Subject: [PATCH] * 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 --- src/kits/storage/mime/MimeUpdateThread.cpp | 60 +++++++++++++--------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/kits/storage/mime/MimeUpdateThread.cpp b/src/kits/storage/mime/MimeUpdateThread.cpp index 6c7a296c3a..11cf41ea61 100644 --- a/src/kits/storage/mime/MimeUpdateThread.cpp +++ b/src/kits/storage/mime/MimeUpdateThread.cpp @@ -1,7 +1,12 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- +/* + * Copyright 2002-2006, Haiku Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tyler Dauwalder + * Ingo Weinhold, bonefish@users.sf.net + */ + /*! \file MimeUpdateThread.cpp MimeUpdateThread implementation @@ -31,7 +36,7 @@ namespace Mime { update_mime_info() and create_app_meta_mime() */ -// constructor + /*! \brief Creates a new MimeUpdateThread object. If \a replyee is non-NULL and construction succeeds, the MimeThreadObject @@ -45,16 +50,16 @@ namespace Mime { MimeUpdateThread::MimeUpdateThread(const char *name, int32 priority, BMessenger managerMessenger, const entry_ref *root, bool recursive, int32 force, BMessage *replyee) - : RegistrarThread(name, priority, managerMessenger) - , fRoot(root ? *root : entry_ref()) - , fRecursive(recursive) - , fForce(force) - , fReplyee(replyee) - , fStatus(root ? B_OK : B_BAD_VALUE) -{ + : RegistrarThread(name, priority, managerMessenger), + fRoot(root ? *root : entry_ref()), + fRecursive(recursive), + fForce(force), + fReplyee(replyee), + fStatus(root ? B_OK : B_BAD_VALUE) +{ } -// destructor + /*! \brief Destroys the MimeUpdateThread object. If the object was properly initialized (i.e. InitCheck() returns \c B_OK) and @@ -68,7 +73,7 @@ MimeUpdateThread::~MimeUpdateThread() delete fReplyee; } -// InitCheck() + /*! \brief Returns the initialization status of the object */ status_t @@ -80,7 +85,7 @@ MimeUpdateThread::InitCheck() return err; } -// ThreadFunction + /*! \brief Implements the common functionality of update_mime_info() and create_app_meta_mime(), namely iterating through the filesystem and updating entries. @@ -89,9 +94,17 @@ status_t MimeUpdateThread::ThreadFunction() { status_t err = InitCheck(); - // Do the updates - if (!err) - err = UpdateEntry(&fRoot); + + // The registrar is using this, too, so we better make sure we + // don't run into troubles + try { + // Do the updates + if (!err) + err = UpdateEntry(&fRoot); + } catch (...) { + err = B_ERROR; + } + // Send a reply if we have a message to reply to if (fReplyee) { BMessage reply(B_REG_RESULT); @@ -100,6 +113,7 @@ MimeUpdateThread::ThreadFunction() if (!err) err = fReplyee->SendReply(&reply); } + // Flag ourselves as finished fIsFinished = true; // Notify the thread manager to make a cleanup run @@ -115,7 +129,7 @@ MimeUpdateThread::ThreadFunction() return err; } -// DeviceSupportsAttributes + /*! \brief Returns true if the given device supports attributes, false if not (or if an error occurs while determining). @@ -183,15 +197,15 @@ MimeUpdateThread::UpdateEntry(const entry_ref *ref) //BPath path(ref); //printf("Updating '%s' (%s)... \n", path.Path(), // (DeviceSupportsAttributes(ref->device) ? "yes" : "no")); - - if (!err - && (device_is_root_device(ref->device) - || DeviceSupportsAttributes(ref->device))) { + + if (!err && (device_is_root_device(ref->device) + || DeviceSupportsAttributes(ref->device))) { // Update this entry if (!err) { // R5 appears to ignore whether or not the update succeeds. DoMimeUpdate(ref, &entryIsDir); } + // If we're recursing and this is a directory, update // each of the directory's children as well if (!err && fRecursive && entryIsDir) {