Omit frequent mkdir and writable checks at startup

This means that using file attributes to control permissions
is not supported anymore.
This commit is contained in:
Christian Dywan 2009-11-18 19:13:07 +01:00
parent 77897bc173
commit 6faa15412d

View file

@ -29,12 +29,8 @@
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#define is_writable(_cfg_filename) \
!g_access (_cfg_filename, W_OK) || \
!g_file_test (_cfg_filename, G_FILE_TEST_EXISTS)
#else
#define is_writable(_cfg_filename) 1
#endif #endif
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -67,7 +63,6 @@ static gchar*
build_config_filename (const gchar* filename) build_config_filename (const gchar* filename)
{ {
const gchar* path = sokoke_set_config_dir (NULL); const gchar* path = sokoke_set_config_dir (NULL);
katze_mkdir_with_parents (path, 0700);
return g_build_filename (path, filename, NULL); return g_build_filename (path, filename, NULL);
} }
@ -1309,7 +1304,6 @@ midori_load_extensions (gpointer data)
{ {
const gchar* filename; const gchar* filename;
gchar* config_file = build_config_filename ("config"); gchar* config_file = build_config_filename ("config");
gboolean is_writable = is_writable (config_file);
while ((filename = g_dir_read_name (extension_dir))) while ((filename = g_dir_read_name (extension_dir)))
{ {
@ -1353,13 +1347,10 @@ midori_load_extensions (gpointer data)
if (!g_strcmp0 (filename, name)) if (!g_strcmp0 (filename, name))
g_signal_emit_by_name (extension, "activate", app); g_signal_emit_by_name (extension, "activate", app);
} }
if (is_writable)
{
g_signal_connect_after (extension, "activate", g_signal_connect_after (extension, "activate",
G_CALLBACK (extension_activate_cb), app); G_CALLBACK (extension_activate_cb), app);
g_signal_connect_after (extension, "deactivate", g_signal_connect_after (extension, "deactivate",
G_CALLBACK (extension_activate_cb), app); G_CALLBACK (extension_activate_cb), app);
}
g_object_unref (extension); g_object_unref (extension);
} }
g_dir_close (extension_dir); g_dir_close (extension_dir);
@ -1426,7 +1417,6 @@ midori_load_session (gpointer data)
gtk_widget_show (GTK_WIDGET (browser)); gtk_widget_show (GTK_WIDGET (browser));
katze_assign (config_file, build_config_filename ("accels")); katze_assign (config_file, build_config_filename ("accels"));
if (is_writable (config_file))
g_signal_connect_after (gtk_accel_map_get (), "changed", g_signal_connect_after (gtk_accel_map_get (), "changed",
G_CALLBACK (accel_map_changed_cb), NULL); G_CALLBACK (accel_map_changed_cb), NULL);
@ -1466,8 +1456,6 @@ midori_load_session (gpointer data)
g_object_unref (_session); g_object_unref (_session);
katze_assign (config_file, build_config_filename ("session.xbel")); katze_assign (config_file, build_config_filename ("session.xbel"));
if (is_writable (config_file))
{
g_signal_connect_after (browser, "notify::uri", g_signal_connect_after (browser, "notify::uri",
G_CALLBACK (midori_browser_session_cb), session); G_CALLBACK (midori_browser_session_cb), session);
g_signal_connect_after (browser, "add-tab", g_signal_connect_after (browser, "add-tab",
@ -1476,7 +1464,6 @@ midori_load_session (gpointer data)
G_CALLBACK (midori_browser_session_cb), session); G_CALLBACK (midori_browser_session_cb), session);
g_object_weak_ref (G_OBJECT (session), g_object_weak_ref (G_OBJECT (session),
(GWeakNotify)(midori_browser_weak_notify_cb), browser); (GWeakNotify)(midori_browser_weak_notify_cb), browser);
}
if (command) if (command)
midori_app_send_command (app, command); midori_app_send_command (app, command);
@ -1570,7 +1557,6 @@ midori_remove_config_file (gint clear_prefs,
if ((clear_prefs & flag) == flag) if ((clear_prefs & flag) == flag)
{ {
gchar* config_file = build_config_filename (filename); gchar* config_file = build_config_filename (filename);
if (is_writable (config_file))
g_unlink (config_file); g_unlink (config_file);
g_free (config_file); g_free (config_file);
} }
@ -1833,6 +1819,8 @@ main (int argc,
return 1; return 1;
} }
katze_mkdir_with_parents (sokoke_set_config_dir (NULL), 0700);
/* Load configuration files */ /* Load configuration files */
error_messages = g_string_new (NULL); error_messages = g_string_new (NULL);
config_file = build_config_filename ("config"); config_file = build_config_filename ("config");
@ -2010,12 +1998,11 @@ main (int argc,
} }
katze_assign (config_file, build_config_filename ("config")); katze_assign (config_file, build_config_filename ("config"));
if (is_writable (config_file))
g_signal_connect_after (settings, "notify", g_signal_connect_after (settings, "notify",
G_CALLBACK (settings_notify_cb), app); G_CALLBACK (settings_notify_cb), app);
katze_assign (config_file, build_config_filename ("search")); katze_assign (config_file, build_config_filename ("search"));
if (is_writable (config_file)) if (1)
{ {
g_signal_connect_after (search_engines, "add-item", g_signal_connect_after (search_engines, "add-item",
G_CALLBACK (midori_search_engines_modify_cb), search_engines); G_CALLBACK (midori_search_engines_modify_cb), search_engines);
@ -2030,7 +2017,7 @@ main (int argc,
} }
} }
katze_assign (config_file, build_config_filename ("bookmarks.xbel")); katze_assign (config_file, build_config_filename ("bookmarks.xbel"));
if (is_writable (config_file)) if (1)
{ {
g_signal_connect_after (bookmarks, "add-item", g_signal_connect_after (bookmarks, "add-item",
G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks); G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
@ -2054,22 +2041,16 @@ main (int argc,
} }
} }
katze_assign (config_file, build_config_filename ("tabtrash.xbel")); katze_assign (config_file, build_config_filename ("tabtrash.xbel"));
if (is_writable (config_file))
{
g_signal_connect_after (trash, "add-item", g_signal_connect_after (trash, "add-item",
G_CALLBACK (midori_trash_add_item_cb), NULL); G_CALLBACK (midori_trash_add_item_cb), NULL);
g_signal_connect_after (trash, "remove-item", g_signal_connect_after (trash, "remove-item",
G_CALLBACK (midori_trash_remove_item_cb), NULL); G_CALLBACK (midori_trash_remove_item_cb), NULL);
}
#if HAVE_SQLITE #if HAVE_SQLITE
katze_assign (config_file, build_config_filename ("history.db")); katze_assign (config_file, build_config_filename ("history.db"));
if (is_writable (config_file))
{
g_signal_connect_after (history, "add-item", g_signal_connect_after (history, "add-item",
G_CALLBACK (midori_history_add_item_cb), db); G_CALLBACK (midori_history_add_item_cb), db);
g_signal_connect_after (history, "clear", g_signal_connect_after (history, "clear",
G_CALLBACK (midori_history_clear_cb), db); G_CALLBACK (midori_history_clear_cb), db);
}
#endif #endif
katze_item_set_parent (KATZE_ITEM (_session), app); katze_item_set_parent (KATZE_ITEM (_session), app);
@ -2146,7 +2127,6 @@ main (int argc,
!= MIDORI_STARTUP_LAST_OPEN_PAGES) != MIDORI_STARTUP_LAST_OPEN_PAGES)
{ {
katze_assign (config_file, build_config_filename ("session.xbel")); katze_assign (config_file, build_config_filename ("session.xbel"));
if (is_writable (config_file))
g_unlink (config_file); g_unlink (config_file);
} }