mirror of
https://github.com/deepseek-ai/3FS
synced 2025-06-26 18:16:45 +00:00
Deprecate usage of boost::filesystem::load_string_file and save_string_file
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
|
|
||||||
#include <boost/filesystem/string_file.hpp>
|
#include <fstream>
|
||||||
|
|
||||||
namespace hf3fs {
|
namespace hf3fs {
|
||||||
Result<std::string> loadFile(const Path &path) {
|
Result<std::string> loadFile(const Path &path) {
|
||||||
try {
|
try {
|
||||||
std::string output;
|
std::ifstream file(path);
|
||||||
boost::filesystem::load_string_file(path, output);
|
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;
|
return output;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return makeError(StatusCode::kIOError, fmt::format("Error when read {}: {}", path, e.what()));
|
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) {
|
Result<Void> storeToFile(const Path &path, const std::string &content) {
|
||||||
try {
|
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{};
|
return Void{};
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
return makeError(StatusCode::kIOError, fmt::format("Error when write to {}: {}", path, e.what()));
|
return makeError(StatusCode::kIOError, fmt::format("Error when write to {}: {}", path, e.what()));
|
||||||
|
|||||||
Reference in New Issue
Block a user