Skip to content

Commit 9c12efd

Browse files
author
Daniel Kroening
committed
use stat to determine whether a directory entry is a subdirectory; d_type is not POSIX
1 parent 556352d commit 9c12efd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util/file_util.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: January 2012
1616
defined(__unix__) || \
1717
defined(__CYGWIN__) || \
1818
defined(__MACH__)
19+
#include <sys/stat.h>
1920
#include <unistd.h>
2021
#include <dirent.h>
2122
#include <cstdlib>
@@ -124,8 +125,13 @@ void delete_directory(const std::string &path)
124125
// Needed for Alpine Linux
125126
if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
126127
continue;
128+
127129
std::string sub_path=path+"/"+ent->d_name;
128-
if(ent->d_type==DT_DIR)
130+
131+
struct stat stbuf;
132+
stat(sub_path.c_str(), &stbuf);
133+
134+
if(S_ISDIR(stbuf.st_mode))
129135
delete_directory(sub_path);
130136
else
131137
remove(sub_path.c_str());

0 commit comments

Comments
 (0)