From 83656ff6566bbded6304f69a9f49cc11847dfb09 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 14 Jun 2018 21:29:01 +0200 Subject: [PATCH] Replace fts/dirent with boost::filesystem functionality --- src/core/appdir.cpp | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index b746f77..720c834 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include // local headers @@ -471,47 +469,16 @@ namespace linuxdeploy { static std::vector listFilesInDirectory(const bf::path& path, const bool recursive = true) { std::vector foundPaths; - std::vector pathBuf(path.string().size() + 1, '\0'); - strcpy(pathBuf.data(), path.string().c_str()); - - std::vector searchPaths = {pathBuf.data(), nullptr}; - if (recursive) { - // reset errno - errno = 0; - - auto* fts = fts_open(searchPaths.data(), FTS_NOCHDIR | FTS_NOSTAT, nullptr); - - int error = errno; - if (fts == nullptr || error != 0) { - ldLog() << LD_ERROR << "fts() failed:" << strerror(error) << std::endl; - return {}; - } - - FTSENT* ent; - while ((ent = fts_read(fts)) != nullptr) { - // FIXME: use ent's fts_info member instead of boost::filesystem - if (bf::is_regular_file(ent->fts_path)) { - foundPaths.push_back(ent->fts_path); + for (bf::recursive_directory_iterator i(path); i != bf::recursive_directory_iterator(); ++i) { + if (bf::is_regular_file(*i)) { + foundPaths.push_back((*i).path()); } - }; - error = errno; - if (error != 0) { - ldLog() << LD_ERROR << "fts_read() failed:" << strerror(error) << std::endl; - return {}; } } else { - DIR* dir; - if ((dir = opendir(path.string().c_str())) == NULL) { - auto error = errno; - ldLog() << LD_ERROR << "opendir() failed:" << strerror(error); - } - - struct dirent* ent; - while ((ent = readdir(dir)) != NULL) { - auto fullPath = path / bf::path(ent->d_name); - if (bf::is_regular_file(fullPath)) { - foundPaths.push_back(fullPath); + for (bf::directory_iterator i(path); i != bf::directory_iterator(); ++i) { + if (bf::is_regular_file(*i)) { + foundPaths.push_back((*i).path()); } } }