diff options
author | archshift <gh@archshift.com> | 2015-08-31 18:29:23 -0700 |
---|---|---|
committer | archshift <gh@archshift.com> | 2015-09-30 21:04:47 -0700 |
commit | 7134a17fc6cb7ab8ae46dae04f005bb72e0af88e (patch) | |
tree | a7276d2efdbeae8ea1fd84e81eca3bfa6a34e7df /src/common/file_util.h | |
parent | bba12520c432a5b5975a76f014ed3c80e3411bb6 (diff) |
Split up FileUtil::ScanDirectoryTree to be able to use callbacks for custom behavior
Converted FileUtil::ScanDirectoryTree and FileUtil::DeleteDirRecursively
to use the new ScanDirectoryTreeAndCallback function internally.
Diffstat (limited to 'src/common/file_util.h')
-rw-r--r-- | src/common/file_util.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index e71a9b2fa2..3d617f5730 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -6,6 +6,7 @@ #include <array> #include <fstream> +#include <functional> #include <cstddef> #include <cstdio> #include <string> @@ -96,9 +97,28 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename); // creates an empty file filename, returns true on success bool CreateEmptyFile(const std::string &filename); -// Scans the directory tree gets, starting from _Directory and adds the -// results into parentEntry. Returns the number of files+directories found -u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry); +/** + * Scans the directory tree, calling the callback for each file/directory found. + * The callback must return the number of files and directories which the provided path contains. + * If the callback's return value is -1, the callback loop is broken immediately. + * If the callback's return value is otherwise negative, the callback loop is broken immediately + * and the callback's return value is returned from this function (to allow for error handling). + * @param directory the parent directory to start scanning from + * @param callback The callback which will be called for each file/directory. It is called + * with the arguments (const std::string& directory, const std::string& virtual_name). + * The `directory `parameter is the path to the directory which contains the file/directory. + * The `virtual_name` parameter is the incomplete file path, without any directory info. + * @return the total number of files/directories found + */ +int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback); + +/** + * Scans the directory tree, storing the results. + * @param directory the parent directory to start scanning from + * @param parent_entry FSTEntry where the filesystem tree results will be stored. + * @return the total number of files/directories found + */ +int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); // deletes the given directory and anything under it. Returns true on success. bool DeleteDirRecursively(const std::string &directory); |