@@ -125,46 +125,33 @@ bool IsDirDelimiter(char c)
125
125
126
126
bool RecursiveDelete (const std::string &path)
127
127
{
128
- infostream<<" Recursively deleting \" " <<path<<" \" " <<std::endl;
129
-
130
- DWORD attr = GetFileAttributes (path.c_str ());
131
- bool is_directory = (attr != INVALID_FILE_ATTRIBUTES &&
132
- (attr & FILE_ATTRIBUTE_DIRECTORY));
133
- if (!is_directory)
134
- {
135
- infostream<<" RecursiveDelete: Deleting file " <<path<<std::endl;
136
- // bool did = DeleteFile(path.c_str());
137
- bool did = true ;
138
- if (!did){
139
- errorstream<<" RecursiveDelete: Failed to delete file "
140
- <<path<<std::endl;
128
+ infostream << " Recursively deleting \" " << path << " \" " << std::endl;
129
+ if (!IsDir (path)) {
130
+ infostream << " RecursiveDelete: Deleting file " << path << std::endl;
131
+ if (!DeleteFile (path.c_str ())) {
132
+ errorstream << " RecursiveDelete: Failed to delete file "
133
+ << path << std::endl;
141
134
return false ;
142
135
}
136
+ return true ;
143
137
}
144
- else
145
- {
146
- infostream<<" RecursiveDelete: Deleting content of directory "
147
- <<path<<std::endl;
148
- std::vector<DirListNode> content = GetDirListing (path);
149
- for (size_t i=0 ; i<content.size (); i++){
150
- const DirListNode &n = content[i];
151
- std::string fullpath = path + DIR_DELIM + n.name ;
152
- bool did = RecursiveDelete (fullpath);
153
- if (!did){
154
- errorstream<<" RecursiveDelete: Failed to recurse to "
155
- <<fullpath<<std::endl;
156
- return false ;
157
- }
158
- }
159
- infostream<<" RecursiveDelete: Deleting directory " <<path<<std::endl;
160
- // bool did = RemoveDirectory(path.c_str();
161
- bool did = true ;
162
- if (!did){
163
- errorstream<<" Failed to recursively delete directory "
164
- <<path<<std::endl;
138
+ infostream << " RecursiveDelete: Deleting content of directory "
139
+ << path << std::endl;
140
+ std::vector<DirListNode> content = GetDirListing (path);
141
+ for (const DirListNode &n: content) {
142
+ std::string fullpath = path + DIR_DELIM + n.name ;
143
+ if (!RecursiveDelete (fullpath)) {
144
+ errorstream << " RecursiveDelete: Failed to recurse to "
145
+ << fullpath << std::endl;
165
146
return false ;
166
147
}
167
148
}
149
+ infostream << " RecursiveDelete: Deleting directory " << path << std::endl;
150
+ if (!RemoveDirectory (path.c_str ())) {
151
+ errorstream << " Failed to recursively delete directory "
152
+ << path << std::endl;
153
+ return false ;
154
+ }
168
155
return true ;
169
156
}
170
157
0 commit comments