Merge lp:~xnox/libnih/fix-672643 into lp:libnih

Proposed by Dimitri John Ledkov
Status: Work in progress
Proposed branch: lp:~xnox/libnih/fix-672643
Merge into: lp:libnih
Diff against target: 124 lines (+82/-1)
3 files modified
ChangeLog (+10/-0)
nih/file.c (+11/-1)
nih/tests/test_file.c (+61/-0)
To merge this branch: bzr merge lp:~xnox/libnih/fix-672643
Reviewer Review Type Date Requested Status
Dimitri John Ledkov (community) Disapprove
Scott James Remnant Pending
Review via email: mp+140158@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

libnih development has moved on to github.

review: Disapprove

Unmerged revisions

1055. By Dimitri John Ledkov

nih/file.c (nih_dir_walk_scan): Fallback to lstat, if the
non-portable dirent.d_type is not available.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2011-09-01 18:41:03 +0000
3+++ ChangeLog 2012-12-17 10:15:23 +0000
4@@ -1,3 +1,13 @@
5+2012-12-11 Dmitrijs Ledkovs <dmitrijs.ledkovs@canonical.com>
6+
7+ * nih/file.c (nih_dir_walk_scan): Fallback to lstat, if the
8+ non-portable dirent.d_type is not available (LP: #672643) (Closes:
9+ #695604).
10+
11+2012-12-10 Petr Lautrbach <plautrba@redhat.com>
12+
13+ * nih/tests/test_file.c: don't use dirent.d_type (not portable)
14+
15 2011-08-31 James Hunt <james.hunt@ubuntu.com>
16
17 * nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c
18
19=== modified file 'nih/file.c'
20--- nih/file.c 2009-10-03 09:37:58 +0000
21+++ nih/file.c 2012-12-17 10:15:23 +0000
22@@ -619,6 +619,8 @@
23 struct dirent *ent;
24 char **paths;
25 size_t npaths;
26+ int isdir;
27+ struct stat statbuf;
28
29 nih_assert (path != NULL);
30
31@@ -640,7 +642,15 @@
32 subpath = NIH_MUST (nih_sprintf (NULL, "%s/%s",
33 path, ent->d_name));
34
35- if (filter && filter (data, subpath, ent->d_type == DT_DIR))
36+ if (ent->d_type == DT_UNKNOWN) {
37+ if ( lstat (subpath, &statbuf))
38+ isdir = 0;
39+ else
40+ isdir = S_ISDIR(statbuf.st_mode);
41+ } else
42+ isdir = ent->d_type == DT_DIR;
43+
44+ if (filter && filter (data, subpath, isdir))
45 continue;
46
47 NIH_MUST (nih_str_array_addp (&paths, NULL, &npaths, subpath));
48
49=== modified file 'nih/tests/test_file.c'
50--- nih/tests/test_file.c 2009-07-08 20:40:57 +0000
51+++ nih/tests/test_file.c 2012-12-17 10:15:23 +0000
52@@ -724,6 +724,25 @@
53 return FALSE;
54 }
55
56+/* find only frodo files */
57+static int
58+my_filter_frodo_file (void *data,
59+ const char *path,
60+ int is_dir)
61+{
62+ char *slash;
63+
64+ if (is_dir)
65+ return FALSE;
66+
67+ slash = strrchr (path, '/');
68+ if (strcmp (slash, "/frodo"))
69+ return TRUE;
70+
71+ return FALSE;
72+}
73+
74+
75 static int logger_called = 0;
76
77 static int
78@@ -905,6 +924,48 @@
79 TEST_EQ_STR (v->path, filename);
80
81 nih_free (visited);
82+
83+ /* Try also inverse filter */
84+ TEST_ALLOC_SAFE {
85+ visitor_called = 0;
86+ visited = nih_list_new (NULL);
87+ }
88+
89+ ret = nih_dir_walk (dirname, my_filter_frodo_file,
90+ my_visitor, NULL, &ret);
91+
92+ TEST_EQ (ret, 0);
93+ TEST_EQ (visitor_called, 4);
94+
95+ v = (Visited *)visited->next;
96+ TEST_EQ (v->data, &ret);
97+ TEST_EQ_STR (v->dirname, dirname);
98+ strcpy (filename, dirname);
99+ strcat (filename, "/bar");
100+ TEST_EQ_STR (v->path, filename);
101+
102+ v = (Visited *)v->entry.next;
103+ TEST_EQ (v->data, &ret);
104+ TEST_EQ_STR (v->dirname, dirname);
105+ strcpy (filename, dirname);
106+ strcat (filename, "/bar/frodo");
107+ TEST_EQ_STR (v->path, filename);
108+
109+ v = (Visited *)v->entry.next;
110+ TEST_EQ (v->data, &ret);
111+ TEST_EQ_STR (v->dirname, dirname);
112+ strcpy (filename, dirname);
113+ strcat (filename, "/baz");
114+ TEST_EQ_STR (v->path, filename);
115+
116+ v = (Visited *)v->entry.next;
117+ TEST_EQ (v->data, &ret);
118+ TEST_EQ_STR (v->dirname, dirname);
119+ strcpy (filename, dirname);
120+ strcat (filename, "/frodo");
121+ TEST_EQ_STR (v->path, filename);
122+
123+ nih_free (visited);
124 }
125
126

Subscribers

People subscribed via source and target branches