From d5f8e3fbec437bb038b49d9ee094c74d93a4df6d Mon Sep 17 00:00:00 2001 From: jun7 Date: Wed, 6 Jun 2018 16:40:52 +0900 Subject: [PATCH] Add Checking system data dirs for list file --- ab.c | 29 +++++++++++++++++------------ makefile | 3 ++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ab.c b/ab.c index e41742f..47efa64 100644 --- a/ab.c +++ b/ab.c @@ -121,7 +121,7 @@ G_MODULE_EXPORT void webkit_web_extension_initialize_with_user_data( static EphyUriTester *tester = NULL; static GThread *initt = NULL; -static gpointer inittcb(gpointer data) +static gpointer inittcb(gpointer p) { ephy_uri_tester_load(tester); return NULL; @@ -134,11 +134,9 @@ static void monitorcb( e == G_FILE_MONITOR_EVENT_DELETED) exit(0); } -static void init() +static bool tryload(const char *parent) { - DD(wyebad init) - char *path = g_build_filename( - g_get_user_config_dir(), DIRNAME, "easylist.txt", NULL); + char *path = g_build_filename(parent, DIRNAME, LISTNAME, NULL); GFile *gf = g_file_new_for_path(path); GFileMonitor *gm = g_file_monitor_file(gf, @@ -150,16 +148,23 @@ static void init() { filter_file = g_file_new_for_path(path); tester = ephy_uri_tester_new("/foo/bar"); - initt = g_thread_new("init", inittcb, NULL); - } else { - char *dir = g_path_get_dirname(path); - if (!g_file_test(dir, G_FILE_TEST_EXISTS)) - g_mkdir_with_parents(dir, 0700); - g_free(dir); } - g_free(path); + return tester; +} +static void init() +{ + DD(wyebad init) + if (tryload(g_get_user_config_dir())) return; + + for (const gchar * const *d = g_get_system_data_dirs(); *d; d++) + if (tryload(*d)) return; + + char *dir = g_build_filename(g_get_user_config_dir(), DIRNAME, NULL); + if (!g_file_test(dir, G_FILE_TEST_EXISTS)) + g_mkdir_with_parents(dir, 0700); + g_free(dir); } static char *datafunc(char *req) diff --git a/makefile b/makefile index d47225a..3a4d58d 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,4 @@ +LISTNAME=easylist.txt EXTENSION_DIR=$(DESTDIR)/usr/lib/wyebrowser ifeq ($(DEBUG), 1) CFLAGS += -Wall @@ -17,7 +18,7 @@ adblock.so: ab.c ephy-uri-tester.c ephy-uri-tester.h librun.o makefile wyebab: ab.c ephy-uri-tester.c ephy-uri-tester.h librun.o makefile $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< librun.o \ `pkg-config --cflags --libs glib-2.0 gio-2.0` \ - $(DDEBUG) -DDIRNAME=\"wyebadblock\" + $(DDEBUG) -DDIRNAME=\"wyebadblock\" -DLISTNAME=\"$(LISTNAME)\" librun.o: wyebrun.c wyebrun.h makefile $(CC) $(CFLAGS) $(LDFLAGS) -c -o $@ $< -fPIC\