mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-08-10 00:52:16 +00:00
tests: add httpcommon tests and add new file_handler methods (#2712)
Co-authored-by: Mariotaku <mariotaku.lee@gmail.com>
This commit is contained in:
@@ -12,6 +12,37 @@
|
||||
#include "logging.h"
|
||||
|
||||
namespace file_handler {
|
||||
/**
|
||||
* @breif Get the parent directory of a file or directory.
|
||||
* @param path The path of the file or directory.
|
||||
* @return `std::string` : The parent directory.
|
||||
*/
|
||||
std::string
|
||||
get_parent_directory(const std::string &path) {
|
||||
// remove any trailing path separators
|
||||
std::string trimmed_path = path;
|
||||
while (!trimmed_path.empty() && trimmed_path.back() == '/') {
|
||||
trimmed_path.pop_back();
|
||||
}
|
||||
|
||||
std::filesystem::path p(trimmed_path);
|
||||
return p.parent_path().string();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make a directory.
|
||||
* @param path The path of the directory.
|
||||
* @return `bool` : `true` on success, `false` on failure.
|
||||
*/
|
||||
bool
|
||||
make_directory(const std::string &path) {
|
||||
// first, check if the directory already exists
|
||||
if (std::filesystem::exists(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return std::filesystem::create_directories(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read a file to string.
|
||||
|
||||
Reference in New Issue
Block a user