while(1) {
struct dirent *d;
+ int isdir = 0;
errno = 0;
if (!(d = readdir(dir))) {
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
-
- if (d->d_type == DT_DIR) {
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (d->d_type == DT_DIR || d->d_type == DT_UNKNOWN)
+#endif
+ {
struct stat sb;
if (fstatat(dfd, d->d_name, &sb, AT_SYMLINK_NOFOLLOW)) {
}
/* remove subdirectories if device is same as dir */
- if (sb.st_dev == rb.st_dev) {
+ if (S_ISDIR(sb.st_mode) && sb.st_dev == rb.st_dev) {
int cfd;
cfd = openat(dfd, d->d_name, O_RDONLY);
recursiveRemove(cfd);
close(cfd);
}
+ isdir = 1;
} else
continue;
}
- if (unlinkat(dfd, d->d_name,
- d->d_type == DT_DIR ? AT_REMOVEDIR : 0))
+ if (unlinkat(dfd, d->d_name, isdir ? AT_REMOVEDIR : 0))
warn(_("failed to unlink %s"), d->d_name);
}