Resort to lstat for FS not supporting dirent.d_type

According to POSIX.1 only d_name and d_ino fields of struct
dirent are standardized. d_type isn't always correctly set on file
systems like XFS. In such cases it makes sense to resort to
lstat(). Otherwise a user has hard time figuring out what's
wrong with her setup.

Also remove redundant populate_file_struct() as it's called
again in parallel threads.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
This commit is contained in:
Dmitry Rozhkov
2016-06-10 11:17:15 +03:00
committed by tmarcu
parent 5420a1ea1b
commit 983b17d68d
+14 -5
View File
@@ -321,7 +321,6 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
while (dir) {
struct file *file;
char *sub_filename;
char *fullname;
entry = readdir(dir);
if (!entry) {
@@ -349,12 +348,22 @@ static void iterate_directory(struct manifest *manifest, char *pathprefix,
file->last_change = manifest->version;
file->filename = sub_filename;
string_or_die(&fullname, "%s/%s", fullpath, entry->d_name);
populate_file_struct(file, fullname);
free(fullname);
if (entry->d_type == DT_DIR) {
iterate_directory(manifest, pathprefix, file->filename, do_hash);
} else if (entry->d_type == DT_UNKNOWN) { /* fall back to lstat() */
struct stat sb;
char *fullname;
string_or_die(&fullname, "%s/%s", fullpath, entry->d_name);
if (lstat(fullname, &sb) == -1) {
perror("lstat");
assert(0);
}
free(fullname);
if (S_ISDIR(sb.st_mode)) {
iterate_directory(manifest, pathprefix, file->filename, do_hash);
}
}
/* if for some reason there is a file in the official build