X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=libfstools%2Foverlay.c;h=d7dd74b1c06aaa134f970b9a0f6862e0a11ce14a;hb=95c07d52c82245fa1f0e5739daf08940a62227c9;hp=602458693ea32320e231a8ae3fa612866f2501c6;hpb=37762ff488752c1686b359816aec75831b49c55f;p=project%2Ffstools.git diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 6024586..d7dd74b 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -91,15 +91,25 @@ foreachdir(const char *dir, int (*cb)(const char*)) else sprintf(globdir, "%s/*", dir); + /* Include GLOB_MARK as callbacks expect a trailing slash */ if (!glob(globdir, GLOB_NOESCAPE | GLOB_MARK | GLOB_ONLYDIR, NULL, &gl)) for (j = 0; j < gl.gl_pathc; j++) { char *dir = gl.gl_pathv[j]; int len = strlen(gl.gl_pathv[j]); + int err; - if (len > 1 && dir[len - 1] == '/') + /* Quick way of skipping files */ + if (dir[len - 1] != '/') + continue; + + /* lstat needs path without a trailing slash */ + if (len > 1) dir[len - 1] = '\0'; + err = lstat(gl.gl_pathv[j], &s); + if (len > 1) + dir[len - 1] = '/'; - if (!lstat(gl.gl_pathv[j], &s) && !S_ISLNK(s.st_mode)) + if (!err && !S_ISLNK(s.st_mode)) foreachdir(gl.gl_pathv[j], cb); } cb(dir);