Here is the cherry-pick of the fix applied in ubuntu, ready to be uploaded as NMU.
It's a git-am patch against current master, also pushed as nmu-685604 head. -- Regards, Dmitrijs.
From a7b0fd700367bce815169f3475677707714db957 Mon Sep 17 00:00:00 2001 From: Dmitrijs Ledkovs <x...@debian.org> Date: Mon, 17 Dec 2012 22:12:57 +0000 Subject: [PATCH] Fallback to lstat, if dirent.d_type is not available (not portable) --- debian/changelog | 9 ++++++++ nih/file.c | 12 +++++++++- nih/tests/test_file.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 23f8543..e961c97 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +libnih (1.0.3-4.1) raring; urgency=low + + [ Petr Lautrbach <plaut...@redhat.com>, Dmitrijs Ledkovs ] + * NMU + * Fallback to lstat, if dirent.d_type is not available (not portable) + (LP: #672643) (Closes: #695604) + + -- Dmitrijs Ledkovs <x...@debian.org> Mon, 17 Dec 2012 22:11:27 +0000 + libnih (1.0.3-4) unstable; urgency=low * Rebuild for new libc to update versioned dependency; this comes from diff --git a/nih/file.c b/nih/file.c index eda3f7b..e32f949 100644 --- a/nih/file.c +++ b/nih/file.c @@ -619,6 +619,8 @@ nih_dir_walk_scan (const char *path, struct dirent *ent; char **paths; size_t npaths; + int isdir; + struct stat statbuf; nih_assert (path != NULL); @@ -640,7 +642,15 @@ nih_dir_walk_scan (const char *path, subpath = NIH_MUST (nih_sprintf (NULL, "%s/%s", path, ent->d_name)); - if (filter && filter (data, subpath, ent->d_type == DT_DIR)) + if (ent->d_type == DT_UNKNOWN) { + if ( lstat (subpath, &statbuf)) + isdir = 0; + else + isdir = S_ISDIR(statbuf.st_mode); + } else + isdir = ent->d_type == DT_DIR; + + if (filter && filter (data, subpath, isdir)) continue; NIH_MUST (nih_str_array_addp (&paths, NULL, &npaths, subpath)); diff --git a/nih/tests/test_file.c b/nih/tests/test_file.c index a40eca3..b62dbae 100644 --- a/nih/tests/test_file.c +++ b/nih/tests/test_file.c @@ -724,6 +724,25 @@ my_filter (void *data, return FALSE; } +/* find only frodo files */ +static int +my_filter_frodo_file (void *data, + const char *path, + int is_dir) +{ + char *slash; + + if (is_dir) + return FALSE; + + slash = strrchr (path, '/'); + if (strcmp (slash, "/frodo")) + return TRUE; + + return FALSE; +} + + static int logger_called = 0; static int @@ -905,6 +924,48 @@ test_dir_walk (void) TEST_EQ_STR (v->path, filename); nih_free (visited); + + /* Try also inverse filter */ + TEST_ALLOC_SAFE { + visitor_called = 0; + visited = nih_list_new (NULL); + } + + ret = nih_dir_walk (dirname, my_filter_frodo_file, + my_visitor, NULL, &ret); + + TEST_EQ (ret, 0); + TEST_EQ (visitor_called, 4); + + v = (Visited *)visited->next; + TEST_EQ (v->data, &ret); + TEST_EQ_STR (v->dirname, dirname); + strcpy (filename, dirname); + strcat (filename, "/bar"); + TEST_EQ_STR (v->path, filename); + + v = (Visited *)v->entry.next; + TEST_EQ (v->data, &ret); + TEST_EQ_STR (v->dirname, dirname); + strcpy (filename, dirname); + strcat (filename, "/bar/frodo"); + TEST_EQ_STR (v->path, filename); + + v = (Visited *)v->entry.next; + TEST_EQ (v->data, &ret); + TEST_EQ_STR (v->dirname, dirname); + strcpy (filename, dirname); + strcat (filename, "/baz"); + TEST_EQ_STR (v->path, filename); + + v = (Visited *)v->entry.next; + TEST_EQ (v->data, &ret); + TEST_EQ_STR (v->dirname, dirname); + strcpy (filename, dirname); + strcat (filename, "/frodo"); + TEST_EQ_STR (v->path, filename); + + nih_free (visited); } -- 1.8.0
signature.asc
Description: OpenPGP digital signature