UpdateMimeInfoThread class, which is a subclass of MimeUpdateThread

that implements updating specific to update_mime_info().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1268 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-09-29 07:09:50 +00:00
parent 56a452bb2c
commit 162f340b21
2 changed files with 103 additions and 0 deletions
@@ -0,0 +1,30 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file UpdateMimeInfoThread.h
UpdateMimeInfoThread interface declaration
*/
#ifndef _MIME_UPDATE_MIME_INFO_THREAD_H
#define _MIME_UPDATE_MIME_INFO_THREAD_H
#include <mime/MimeUpdateThread.h>
namespace BPrivate {
namespace Storage {
namespace Mime {
class UpdateMimeInfoThread : public MimeUpdateThread {
public:
UpdateMimeInfoThread(const char *name, int32 priority, BMessenger managerMessenger,
const entry_ref *root, bool recursive, bool force, BMessage *replyee);
status_t DoMimeUpdate(const entry_ref *entry, bool *entryIsDir);
};
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_UPDATE_MIME_INFO_THREAD_H
@@ -0,0 +1,73 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file UpdateMimeInfoThread.h
UpdateMimeInfoThread implementation
*/
#include "mime/UpdateMimeInfoThread.h"
#include <fs_attr.h>
#include <MimeType.h>
#include <mime/database_support.h>
#include <Node.h>
namespace BPrivate {
namespace Storage {
namespace Mime {
// constructor
//! Creates a new UpdateMimeInfoThread object
UpdateMimeInfoThread::UpdateMimeInfoThread(const char *name, int32 priority,
BMessenger managerMessenger, const entry_ref *root, bool recursive, bool force, BMessage *replyee)
: MimeUpdateThread(name, priority, managerMessenger, root, recursive, force, replyee)
{
}
// DoMimeUpdate
/*! \brief Performs an update_mime_info() update on the given entry
If the entry has no \c BEOS:TYPE attribute, or if \c fForce is true, the
entry is sniffed and its \c BEOS:TYPE attribute is set accordingly.
*/
status_t
UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
{
status_t err = entry ? B_OK : B_BAD_VALUE;
bool doUpdate = true;
BNode node;
if (!err)
err = node.SetTo(entry);
if (!err && !fForce) {
// If not forced, only update if the entry has no file type attribute
attr_info info;
if (!err)
doUpdate = node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND;
}
if (!err && doUpdate) {
BMimeType type;
err = BMimeType::GuessMimeType(entry, &type);
if (!err)
err = type.InitCheck();
if (!err) {
const char *typeStr = type.Type();
ssize_t len = strlen(typeStr)+1;
ssize_t bytes = node.WriteAttr(kFileTypeAttr, kFileTypeType, 0, typeStr, len);
if (bytes < B_OK)
err = bytes;
else
err = (bytes != len ? B_FILE_ERROR : B_OK);
}
}
if (!err && entryIsDir)
*entryIsDir = node.IsDirectory();
return err;
}
} // namespace Mime
} // namespace Storage
} // namespace BPrivate