diff options
author | Dave Davenport <qball@gmpclient.org> | 2023-08-15 19:28:33 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2023-08-15 19:28:33 +0200 |
commit | 6caaf36df6b53341c7aef69a843dbb5b0ad869ec (patch) | |
tree | 3fe5e9bb6c5deddacdb5ccaade36c86001381cca | |
parent | a7aa8224cb20784ede3c542f829f497261b7452c (diff) |
[Theme] Fix opening abs path if no/wrong extension (backward comp.)
-rw-r--r-- | source/helper.c | 12 | ||||
-rw-r--r-- | test/theme-parser-test.c | 18 |
2 files changed, 14 insertions, 16 deletions
diff --git a/source/helper.c b/source/helper.c index 19f5da89..34d6bc01 100644 --- a/source/helper.c +++ b/source/helper.c @@ -1067,6 +1067,14 @@ gboolean helper_execute_command(const char *wd, const char *cmd, char *helper_get_theme_path(const char *file, const char **ext, const char *parent_file) { + char *filename = rofi_expand_path(file); + g_debug("Opening theme, testing: %s\n", filename); + if (g_path_is_absolute(filename)) { + g_debug("Opening theme, path is absolute: %s", filename); + if (g_file_test(filename, G_FILE_TEST_EXISTS)) { + return filename; + } + } gboolean ext_found = FALSE; for (const char **i = ext; *i != NULL; i++) { if (g_str_has_suffix(file, *i)) { @@ -1074,17 +1082,15 @@ char *helper_get_theme_path(const char *file, const char **ext, break; } } - char *filename = NULL; if (ext_found) { filename = rofi_expand_path(file); } else { g_assert_nonnull(ext[0]); - char *temp = rofi_expand_path(file); + char *temp = filename; // TODO: Pick the first extension. needs fixing. filename = g_strconcat(temp, ext[0], NULL); g_free(temp); } - g_debug("Opening theme, testing: %s\n", filename); if (g_path_is_absolute(filename)) { g_debug("Opening theme, path is absolute: %s", filename); if (g_file_test(filename, G_FILE_TEST_EXISTS)) { diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 0aadbf53..7eeb4508 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -1698,7 +1698,8 @@ START_TEST(test_prepare_environment_media_f) { wid.name = "window"; wid.state = ""; setenv("QER_TEST", "true", 1); - rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}"); + rofi_theme_parse_string("window { width: 32; } @media( enabled: " + "env(QER_TEST,false)){ window {width:64; }}"); rofi_theme_parse_process_conditionals(); ck_assert_ptr_nonnull(rofi_theme); // ck_assert_ptr_null ( rofi_theme->widgets ); @@ -1716,7 +1717,8 @@ START_TEST(test_prepare_environment_media_nf) { widget wid; wid.name = "window"; wid.state = ""; - rofi_theme_parse_string("window { width: 32; } @media( enabled: env(QER_TEST,false)){ window {width:64; }}"); + rofi_theme_parse_string("window { width: 32; } @media( enabled: " + "env(QER_TEST,false)){ window {width:64; }}"); ck_assert_ptr_nonnull(rofi_theme); // ck_assert_ptr_null ( rofi_theme->widgets ); ck_assert_ptr_null(rofi_theme->properties); @@ -1731,23 +1733,13 @@ END_TEST START_TEST(test_prepare_path) { char *current_dir = g_get_current_dir(); ck_assert_ptr_nonnull(current_dir); - char *f = rofi_theme_parse_prepare_file("../", NULL); + char *f = rofi_theme_parse_prepare_file("../"); ck_assert_ptr_nonnull(f); ck_assert_int_eq(*f, '/'); ck_assert_str_ne(f, current_dir); ck_assert(g_str_has_prefix(current_dir, f) == TRUE); g_free(f); - f = rofi_theme_parse_prepare_file("../", "/tmp/"); - ck_assert_ptr_nonnull(f); - ck_assert_str_eq(f, "/"); - g_free(f); - - f = rofi_theme_parse_prepare_file("/tmp/test.rasi", "/random/"); - ck_assert_ptr_nonnull(f); - ck_assert_str_eq(f, "/tmp/test.rasi"); - g_free(f); - g_free(current_dir); } END_TEST |