diff --git a/cmdline/scan.c b/cmdline/scan.c index 14a8819a..da027511 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -1563,7 +1563,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa struct dirent_sorted* dd = node->data; const char* name = dd->d_name; struct stat* st; - int type; + int d_type; #if !HAVE_STRUCT_DIRENT_D_STAT struct stat st_buf; #endif @@ -1571,23 +1571,17 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa pathcatl(path_next, path_len, PATH_MAX, name); pathcatl(sub_next, sub_len, PATH_MAX, name); - /* start with an unknown type */ - type = -1; st = 0; /* if dirent has the type, use it */ #if HAVE_STRUCT_DIRENT_D_TYPE - switch (dd->d_type) { - case DT_UNKNOWN : break; - case DT_REG : type = 0; break; - case DT_LNK : type = 1; break; - case DT_DIR : type = 2; break; - default : type = 3; break; - } + d_type = dd->d_type; +#else + d_type = DT_UNKNOWN; #endif /* if type is still unknown */ - if (type < 0) { + if (d_type == DT_UNKNOWN) { /* get the type from stat */ st = DSTAT(path_next, dd, &st_buf); @@ -1611,16 +1605,14 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa #endif if (S_ISREG(st->st_mode)) - type = 0; + d_type = DT_REG; else if (S_ISLNK(st->st_mode)) - type = 1; + d_type = DT_LNK; else if (S_ISDIR(st->st_mode)) - type = 2; - else - type = 3; + d_type = DT_DIR; } - if (type == 0) { /* REG */ + if (d_type == DT_REG) { /* * Note that .snapraidignore is an exception from filtering because it * is a control file that must be preserved as array data. @@ -1661,7 +1653,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa } else { msg_verbose("Excluding file '%s' for rule '%s'\n", path_next, filter_type(reason, tmp, PATH_MAX)); } - } else if (type == 1) { /* LNK */ + } else if (d_type == DT_LNK) { /* * Note that .snapraidignore is an exception from filtering because it * is a control file that must be preserved as array data. @@ -1698,7 +1690,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa } else { msg_verbose("Excluding link '%s' for rule '%s'\n", path_next, filter_type(reason, tmp, PATH_MAX)); } - } else if (type == 2) { /* DIR */ + } else if (d_type == DT_DIR) { if (filter_subdir(&state->filterlist, &reason, disk->name, sub_next) == 0 && filter_subdir(&scan->local_filter_list, &reason, disk->name, sub_next) == 0) { #ifndef _WIN32 diff --git a/os/mingw.h b/os/mingw.h index 11d3a072..13474359 100644 --- a/os/mingw.h +++ b/os/mingw.h @@ -134,6 +134,14 @@ wchar_t* u8tou16_mayfail(wchar_t* conv_buf, size_t number_of_wchar, const char* #define rmdir windows_rmdir #undef dirent #define dirent windows_dirent +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 #undef DIR #define DIR windows_dir #undef opendir diff --git a/os/unix.h b/os/unix.h index 5b615f34..91775d54 100644 --- a/os/unix.h +++ b/os/unix.h @@ -19,6 +19,22 @@ #define OS_LVL_INFO LOG_INFO #define OS_LVL_DEBUG LOG_DEBUG +#if !HAVE_STRUCT_DIRENT_D_TYPE +/* without d_type these values are internal markers populated from lstat(). */ +#ifndef DT_UNKNOWN +#define DT_UNKNOWN 0 +#endif +#ifndef DT_DIR +#define DT_DIR 4 +#endif +#ifndef DT_REG +#define DT_REG 8 +#endif +#ifndef DT_LNK +#define DT_LNK 10 +#endif +#endif + /* implement close_range for glibc 2.33 or earlier */ #if defined(__linux__) && !defined(HAVE_CLOSE_RANGE) #ifndef __NR_close_range