From 852a4218ba60770e6effa149a3ccfecd997bd2f0 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 5 Mar 2017 23:19:00 -0800 Subject: [PATCH] fix file finding --- .vscode/settings.json | 4 ++-- command_line.cc | 2 -- utils.cc | 33 +++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7d005628..04336656 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,7 +12,7 @@ "**/.git": true, "**/.svn": true, "**/.hg": true, - "**/.DS_Store": true, - "third_party/": true + "**/.DS_Store": true + // "third_party/": true } } \ No newline at end of file diff --git a/command_line.cc b/command_line.cc index 3d07f3d9..a892ed51 100644 --- a/command_line.cc +++ b/command_line.cc @@ -613,8 +613,6 @@ int main(int argc, char** argv) { _setmode(_fileno(stdin), O_BINARY); #endif - - IpcRegistry::instance()->Register(); IpcRegistry::instance()->Register(); diff --git a/utils.cc b/utils.cc index 903b4318..a30284ee 100644 --- a/utils.cc +++ b/utils.cc @@ -1,11 +1,12 @@ #include "utils.h" +#include #include #include #include "tinydir.h" -std::vector GetFilesInFolder(std::string folder, bool add_folder_to_path) { +static std::vector GetFilesInFolderHelper(std::string folder, std::string output_prefix) { std::vector result; tinydir_dir dir; @@ -21,21 +22,17 @@ std::vector GetFilesInFolder(std::string folder, bool add_folder_to goto bail; } - std::string full_path; - if (add_folder_to_path) - full_path = folder + "/"; - full_path += file.name; - if (file.is_dir) { - // Ignore all dot directories. - // Note that we must always ignore the '.' and '..' directories, otherwise - // this will loop infinitely. - if (file.name[0] != '.') { - for (std::string nested_file : GetFilesInFolder(full_path, true /*add_folder_to_path*/)) + // Skip all dot files. + if (file.name[0] != '.') { + if (file.is_dir) { + // Note that we must always ignore the '.' and '..' directories, otherwise + // this will loop infinitely. The above check handles that for us. + for (std::string nested_file : GetFilesInFolderHelper(file.path, output_prefix + file.name + "/")) result.push_back(nested_file); } - } - else { - result.push_back(full_path); + else { + result.push_back(output_prefix + file.name); + } } if (tinydir_next(&dir) == -1) { @@ -49,6 +46,14 @@ bail: return result; } +std::vector GetFilesInFolder(std::string folder, bool add_folder_to_path) { + assert(folder.size() > 0); + if (folder[folder.size() - 1] != '/') + folder += '/'; + + return GetFilesInFolderHelper(folder, add_folder_to_path ? folder : ""); +} + std::vector ReadLines(std::string filename) { std::vector result;