also replace opendir() by our get_dir(), you get eye cancer when looking at the c...
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Wed, 16 Dec 2015 23:04:39 +0000 (00:04 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Wed, 16 Dec 2015 23:04:39 +0000 (00:04 +0100)
src/filefunc.cpp

index a19d760..575be4d 100644 (file)
@@ -755,24 +755,15 @@ bool recursive_delete(const std::string &path,
 
         if (sp.is_directory())
         {
-            DIR *dir = opendir(path.c_str());
-            if (!dir)
-                throw runtime_error("can't open directory " + path);
-
-            struct dirent store, *entry = NULL;
-            while (readdir_r(dir, &store, &entry) == 0 && entry != NULL)
+            std::vector<std::string> dirents = get_dir(path, false);
+            BOOST_FOREACH(const std::string &filename, dirents)
             {
-                string filename = entry->d_name;
-                if (filename == "." || filename == "..")
-                    continue;
-
                 // Delete subdir or file.
                 rtn = recursive_delete(path + "/" + filename, false, error);
                 if (rtn == false)
                     break;
             }
 
-            closedir(dir);
             if (keep_parent_dir == false && !rmdir(path))
                 throw runtime_error("can't remove directory " + path);
         }