MCPcopy Create free account
hub / github.com/FastLED/FastLED / forceRemoveDirectory

Function forceRemoveDirectory

src/platforms/stub/fs_stub.hpp:181–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179 }
180
181 static void forceRemoveDirectory(const fl::string& path) FL_NOEXCEPT {
182 // Synchronously and recursively remove directory and all contents
183 // This ensures cleanup completes before proceeding
184#ifdef FL_IS_WIN
185 // Windows implementation using _findfirst/_findnext (avoids windows.h conflicts)
186 fl::string search_path = path;
187 search_path.append("\\*");
188
189 struct _finddata_t find_data;
190 intptr_t find_handle = _findfirst(search_path.c_str(), &find_data);
191
192 if (find_handle != -1) {
193 do {
194 fl::string entry_name = find_data.name;
195 if (entry_name != "." && entry_name != "..") {
196 fl::string full_path = path;
197 full_path.append("\\");
198 full_path.append(entry_name);
199
200 if (find_data.attrib & _A_SUBDIR) {
201 // Recursively remove subdirectory
202 forceRemoveDirectory(full_path);
203 } else {
204 // Remove file
205 ::remove(full_path.c_str());
206 }
207 }
208 } while (_findnext(find_handle, &find_data) == 0);
209 _findclose(find_handle);
210 }
211
212 // Finally remove the directory itself
213 _rmdir(path.c_str());
214#else
215 // Unix implementation using opendir/readdir
216 DIR* dir = ::opendir(path.c_str());
217 if (dir) {
218 struct dirent* entry;
219 while ((entry = ::readdir(dir)) != nullptr) {
220 fl::string entry_name = entry->d_name;
221 if (entry_name != "." && entry_name != "..") {
222 fl::string full_path = path;
223 full_path.append("/");
224 full_path.append(entry_name);
225
226 struct stat st;
227 if (::stat(full_path.c_str(), &st) == 0) {
228 if (S_ISDIR(st.st_mode)) {
229 // Recursively remove subdirectory
230 forceRemoveDirectory(full_path);
231 } else {
232 // Remove file
233 ::remove(full_path.c_str());
234 }
235 }
236 }
237 }
238 ::closedir(dir);

Callers 3

FilebufTestGuardMethod · 0.85
~FilebufTestGuardMethod · 0.85
cleanupMethod · 0.85

Calls 4

statClass · 0.85
removeFunction · 0.50
appendMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected