diff options
Diffstat (limited to 'src/common/file_util.h')
| -rw-r--r-- | src/common/file_util.h | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index 3d617f573..a85121aa6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -98,19 +98,24 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename); | |||
| 98 | bool CreateEmptyFile(const std::string &filename); | 98 | bool CreateEmptyFile(const std::string &filename); |
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | * Scans the directory tree, calling the callback for each file/directory found. | 101 | * @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null |
| 102 | * The callback must return the number of files and directories which the provided path contains. | 102 | * @param directory the path to the enclosing directory |
| 103 | * If the callback's return value is -1, the callback loop is broken immediately. | 103 | * @param virtual_name the entry name, without any preceding directory info |
| 104 | * If the callback's return value is otherwise negative, the callback loop is broken immediately | 104 | * @return whether handling the entry succeeded |
| 105 | * and the callback's return value is returned from this function (to allow for error handling). | 105 | */ |
| 106 | * @param directory the parent directory to start scanning from | 106 | using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out, |
| 107 | * @param callback The callback which will be called for each file/directory. It is called | 107 | const std::string& directory, |
| 108 | * with the arguments (const std::string& directory, const std::string& virtual_name). | 108 | const std::string& virtual_name)>; |
| 109 | * The `directory `parameter is the path to the directory which contains the file/directory. | 109 | |
| 110 | * The `virtual_name` parameter is the incomplete file path, without any directory info. | 110 | /** |
| 111 | * @return the total number of files/directories found | 111 | * Scans a directory, calling the callback for each file/directory contained within. |
| 112 | * If the callback returns failure, scanning halts and this function returns failure as well | ||
| 113 | * @param num_entries_out assigned by the function with the number of iterated directory entries, can be null | ||
| 114 | * @param directory the directory to scan | ||
| 115 | * @param callback The callback which will be called for each entry | ||
| 116 | * @return whether scanning the directory succeeded | ||
| 112 | */ | 117 | */ |
| 113 | int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int(const std::string&, const std::string&)> callback); | 118 | bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback); |
| 114 | 119 | ||
| 115 | /** | 120 | /** |
| 116 | * Scans the directory tree, storing the results. | 121 | * Scans the directory tree, storing the results. |
| @@ -118,7 +123,7 @@ int ScanDirectoryTreeAndCallback(const std::string &directory, std::function<int | |||
| 118 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. | 123 | * @param parent_entry FSTEntry where the filesystem tree results will be stored. |
| 119 | * @return the total number of files/directories found | 124 | * @return the total number of files/directories found |
| 120 | */ | 125 | */ |
| 121 | int ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); | 126 | unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry); |
| 122 | 127 | ||
| 123 | // deletes the given directory and anything under it. Returns true on success. | 128 | // deletes the given directory and anything under it. Returns true on success. |
| 124 | bool DeleteDirRecursively(const std::string &directory); | 129 | bool DeleteDirRecursively(const std::string &directory); |