* fix mu_util_dir_expand for non-existant dirs, add unit test

This commit is contained in:
Dirk-Jan C. Binnema 2010-12-04 19:14:31 +02:00
parent 6a3decdc7c
commit 0b87be5f18
2 changed files with 23 additions and 1 deletions

View File

@ -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",

View File

@ -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);