Deprecate usage of boost::filesystem::load_string_file and save_string_file

This commit is contained in:
Symious 2025-03-08 20:02:53 +08:00
parent 923bdd7c66
commit 7b0fd141d6

View File

@ -1,12 +1,15 @@
#include "FileUtils.h"
#include <boost/filesystem/string_file.hpp>
#include <fstream>
namespace hf3fs {
Result<std::string> loadFile(const Path &path) {
try {
std::string output;
boost::filesystem::load_string_file(path, output);
std::ifstream file(path);
if (!file) {
return makeError(StatusCode::kIOError, fmt::format("Error opening file: {}", path));
}
std::string output((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
return output;
} catch (const std::exception &e) {
return makeError(StatusCode::kIOError, fmt::format("Error when read {}: {}", path, e.what()));
@ -15,7 +18,15 @@ Result<std::string> loadFile(const Path &path) {
Result<Void> storeToFile(const Path &path, const std::string &content) {
try {
boost::filesystem::save_string_file(path, content);
std::ofstream file(path);
if (!file) {
return makeError(StatusCode::kIOError, fmt::format("Error opening file for writing: {}", path));
}
file << content;
if (!file) {
return makeError(StatusCode::kIOError, fmt::format("Error writing to file: {}", path));
}
return Void{};
} catch (const std::exception &e) {
return makeError(StatusCode::kIOError, fmt::format("Error when write to {}: {}", path, e.what()));