* Construct the MIME data base directories lazily.

* Automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34399 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-12-01 08:52:13 +00:00
parent 6bb7a8908c
commit bc0693b219
8 changed files with 241 additions and 230 deletions
@@ -20,8 +20,8 @@ namespace Storage {
namespace Mime {
// Database directory
extern const std::string kDatabaseDir;
extern const std::string kApplicationDatabaseDir;
const std::string get_database_directory();
const std::string get_application_database_directory();
// Attribute Prefixes
extern const char *kMiniIconAttrPrefix;
+35 -24
View File
@@ -38,15 +38,6 @@ namespace BPrivate {
namespace Storage {
namespace Mime {
static const char *get_user_settings_dir(BPath &path);
static BPath sSettingsDirPath;
static const std::string sSettingsDir = get_user_settings_dir(sSettingsDirPath);
static const char *sHaikuDBDirName = "beos_mime";
// when running natively under Haiku
const std::string kDatabaseDir = sSettingsDir + "/" + sHaikuDBDirName;
const std::string kApplicationDatabaseDir = kDatabaseDir + "/application";
#define ATTR_PREFIX "META:"
#define MINI_ICON_ATTR_PREFIX ATTR_PREFIX "M:"
@@ -103,27 +94,47 @@ const char *kMetaMimeType = "application/x-vnd.Be-meta-mime";
// Error codes
const status_t kMimeGuessFailureError = B_ERRORS_END+1;
// get_settings_dir
/*! \brief Sets the supplied BPath to the user settings directory and returns
it as C string.
\param path BPath to be set to the user settings path.
\return the user settings path as C string (\code path.Path() \endcode).
*/
static
const char*
get_user_settings_dir(BPath &path)
static pthread_once_t sDatabaseDirectoryInitOnce = PTHREAD_ONCE_INIT;
static std::string sDatabaseDirectory;
static std::string sApplicationDatabaseDirectory;
static void
init_database_directories()
{
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
path.SetTo("/boot/home/config/settings");
return path.Path();
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK)
sDatabaseDirectory = path.Path();
else
sDatabaseDirectory = "/boot/home/config/settings";
sDatabaseDirectory += "/beos_mime";
sApplicationDatabaseDirectory = sDatabaseDirectory + "/application";
}
const std::string
get_database_directory()
{
pthread_once(&sDatabaseDirectoryInitOnce, &init_database_directories);
return sDatabaseDirectory;
}
const std::string
get_application_database_directory()
{
pthread_once(&sDatabaseDirectoryInitOnce, &init_database_directories);
return sApplicationDatabaseDirectory;
}
// type_to_filename
//! Converts the given MIME type to an absolute path in the MIME database.
std::string
type_to_filename(const char *type)
{
return kDatabaseDir + "/" + BPrivate::Storage::to_lower(type);
return get_database_directory() + "/" + BPrivate::Storage::to_lower(type);
}
// open_type
@@ -183,7 +194,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
uint32 pos = typeLower.find_first_of('/');
if (pos == std::string::npos) {
// Supertype == directory
BDirectory parent(kDatabaseDir.c_str());
BDirectory parent(get_database_directory().c_str());
err = parent.InitCheck();
if (!err)
err = parent.CreateDirectory(typeLower.c_str(), NULL);
@@ -191,7 +202,7 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
// Non-supertype == file
std::string super(typeLower, 0, pos);
std::string sub(typeLower, pos+1);
BDirectory parent((kDatabaseDir + "/" + super).c_str());
BDirectory parent((get_database_directory() + "/" + super).c_str());
err = parent.InitCheck();
if (!err)
err = parent.CreateFile(sub.c_str(), NULL);
@@ -331,7 +331,7 @@ AssociatedTypes::BuildAssociatedTypesTable()
fAssociatedTypes.clear();
BDirectory root;
status_t err = root.SetTo(kDatabaseDir.c_str());
status_t err = root.SetTo(get_database_directory().c_str());
if (!err) {
root.Rewind();
while (true) {
@@ -393,7 +393,7 @@ AssociatedTypes::BuildAssociatedTypesTable()
} else {
DBG(OUT("Mime::AssociatedTypes::BuildAssociatedTypesTable(): "
"Failed opening mime database directory '%s'\n",
kDatabaseDir.c_str()));
get_database_directory().c_str()));
}
if (!err) {
fHaveDoneFullBuild = true;
@@ -90,7 +90,7 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
path.ToLower();
// Signatures and MIME types are case insensitive, but we want to
// preserve the case wherever possible
path.Prepend(kDatabaseDir.c_str());
path.Prepend(get_database_directory().c_str());
status = typeNode.SetTo(path.String());
if (status < B_OK)
+1 -1
View File
@@ -66,7 +66,7 @@ Database::Database()
fDeferredInstallNotifications()
{
// Do some really minor error checking
BEntry entry(kDatabaseDir.c_str());
BEntry entry(get_database_directory().c_str());
fStatus = entry.Exists() ? B_OK : B_BAD_VALUE;
}
@@ -382,7 +382,7 @@ InstalledTypes::_BuildInstalledTypesList()
BDirectory root;
if (!err)
err = root.SetTo(kDatabaseDir.c_str());
err = root.SetTo(get_database_directory().c_str());
if (!err) {
root.Rewind();
while (true) {
@@ -452,7 +452,7 @@ InstalledTypes::_BuildInstalledTypesList()
} else {
DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): "
"Failed opening mime database directory '%s'\n",
kDatabaseDir.c_str()));
get_database_directory().c_str()));
}
fHaveDoneFullBuild = true;
return err;
+2 -2
View File
@@ -334,7 +334,7 @@ SnifferRules::BuildRuleList()
ssize_t bytesNeeded = 0;
BDirectory root;
status_t err = root.SetTo(kDatabaseDir.c_str());
status_t err = root.SetTo(get_database_directory().c_str());
if (!err) {
root.Rewind();
while (true) {
@@ -400,7 +400,7 @@ SnifferRules::BuildRuleList()
} else {
DBG(OUT("Mime::SnifferRules::BuildRuleList(): "
"Failed opening mime database directory '%s'\n",
kDatabaseDir.c_str()));
get_database_directory().c_str()));
}
if (!err) {
@@ -263,7 +263,7 @@ SupportingApps::BuildSupportingAppsTable()
fStrandedTypes.clear();
BDirectory dir;
status_t status = dir.SetTo(kApplicationDatabaseDir.c_str());
status_t status = dir.SetTo(get_application_database_directory().c_str());
// Build the supporting apps table based on the mime database
if (status == B_OK) {