From 0b87be5f18fd812287cd6180133f615aefa0a50c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 4 Dec 2010 19:14:31 +0200 Subject: [PATCH] * fix mu_util_dir_expand for non-existant dirs, add unit test --- src/mu-util.c | 6 +++++- src/tests/test-mu-util.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/mu-util.c b/src/mu-util.c index 92ca0ad0..5c854bd6 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -93,7 +93,11 @@ mu_util_dir_expand (const char *path) dir = do_wordexp (path); if (!dir) return NULL; /* error */ - + + /* don't try realpath if the dir does not exist */ + if (access (dir, F_OK) != 0) + return dir; + /* now resolve any symlinks, .. etc. */ if (realpath (dir, resolved) == NULL) { g_debug ("%s: could not get realpath for '%s': %s", diff --git a/src/tests/test-mu-util.c b/src/tests/test-mu-util.c index b93a9959..a9fb2c8e 100644 --- a/src/tests/test-mu-util.c +++ b/src/tests/test-mu-util.c @@ -30,6 +30,22 @@ #include "test-mu-common.h" #include "src/mu-util.h" +static void +test_mu_util_dir_expand_00 (void) +{ + gchar *got, *expected; + + got = mu_util_dir_expand ("~/IProbablyDoNotExist"); + expected = g_strdup_printf ("%s%cIProbablyDoNotExist", + getenv("HOME"), G_DIR_SEPARATOR); + + g_assert_cmpstr (got,==,expected); + + g_free (got); + g_free (expected); + +} + static void test_mu_util_dir_expand_01 (void) { @@ -46,6 +62,7 @@ test_mu_util_dir_expand_01 (void) } + static void test_mu_util_dir_expand_02 (void) { @@ -203,6 +220,7 @@ main (int argc, char *argv[]) g_test_init (&argc, &argv, NULL); /* mu_util_dir_expand */ + g_test_add_func ("/mu-util/mu-util-dir-expand-00", test_mu_util_dir_expand_00); g_test_add_func ("/mu-util/mu-util-dir-expand-01", test_mu_util_dir_expand_01); g_test_add_func ("/mu-util/mu-util-dir-expand-02", test_mu_util_dir_expand_02); g_test_add_func ("/mu-util/mu-util-dir-expand-03", test_mu_util_dir_expand_03);