Skip to content

Commit 3b273a6

Browse files
authored
Deprecate usage of some functions in boost (#130)
* Deprecate usage of boost::filesystem::load_string_file and save_string_file * some other deperated functions * remove complete() * normal, save, load
1 parent 923bdd7 commit 3b273a6

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

benchmarks/storage_bench/StorageBench.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <random>
1313
#include <vector>
14+
#include <fstream>
1415

1516
#include "common/logging/LogInit.h"
1617
#include "common/net/ib/IBDevice.h"
@@ -398,12 +399,21 @@ class StorageBench : public test::UnitTestFabric {
398399

399400
if (!boost::filesystem::exists(outFilePath) || boost::filesystem::is_empty(outFilePath)) {
400401
XLOGF(INFO, "Create a file for perfermance stats at {}", outFilePath);
401-
boost::filesystem::save_string_file(
402-
outFilePath,
403-
"test name,#storages,#chains,#replicas,concurrency,batch size,"
404-
"io size (bytes),effective batch size (batch size / #replicas),elapsed time (us),"
405-
"QPS,IOPS,bandwidth (MB/s),latency samples,min latency (us),max latency (us),avg latency (us),"
406-
"latency P50 (us),latency P75 (us),latency P90 (us),latency P95 (us),latency P99 (us)\n");
402+
std::ofstream outFile(outFilePath);
403+
if (!outFile) {
404+
throw std::runtime_error("Failed to open file: " + outFilePath.string());
405+
}
406+
407+
outFile << "test name,#storages,#chains,#replicas,concurrency,batch size,"
408+
"io size (bytes),effective batch size (batch size / #replicas),elapsed time (us),"
409+
"QPS,IOPS,bandwidth (MB/s),latency samples,min latency (us),max latency (us),avg latency (us),"
410+
"latency P50 (us),latency P75 (us),latency P90 (us),latency P95 (us),latency P99 (us)\n";
411+
412+
if (!outFile) {
413+
throw std::runtime_error("Failed to write to file: " + outFilePath.string());
414+
}
415+
416+
outFile.close();
407417
}
408418

409419
auto elapsedMicro = std::chrono::duration_cast<std::chrono::microseconds>(elapsedTime);

src/common/utils/FileUtils.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include "FileUtils.h"
22

3-
#include <boost/filesystem/string_file.hpp>
3+
#include <fstream>
44

55
namespace hf3fs {
66
Result<std::string> loadFile(const Path &path) {
77
try {
8-
std::string output;
9-
boost::filesystem::load_string_file(path, output);
8+
std::ifstream file(path);
9+
if (!file) {
10+
return makeError(StatusCode::kIOError, fmt::format("Error opening file: {}", path));
11+
}
12+
std::string output((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
1013
return output;
1114
} catch (const std::exception &e) {
1215
return makeError(StatusCode::kIOError, fmt::format("Error when read {}: {}", path, e.what()));
@@ -15,7 +18,15 @@ Result<std::string> loadFile(const Path &path) {
1518

1619
Result<Void> storeToFile(const Path &path, const std::string &content) {
1720
try {
18-
boost::filesystem::save_string_file(path, content);
21+
std::ofstream file(path);
22+
if (!file) {
23+
return makeError(StatusCode::kIOError, fmt::format("Error opening file for writing: {}", path));
24+
}
25+
26+
file << content;
27+
if (!file) {
28+
return makeError(StatusCode::kIOError, fmt::format("Error writing to file: {}", path));
29+
}
1930
return Void{};
2031
} catch (const std::exception &e) {
2132
return makeError(StatusCode::kIOError, fmt::format("Error when write to {}: {}", path, e.what()));

src/fuse/FuseOps.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ void hf3fs_ioctl(fuse_req_t req,
21502150
fuse_reply_err(req, EINVAL);
21512151
return;
21522152
}
2153-
if (name.has_branch_path()) {
2153+
if (name.has_parent_path()) {
21542154
fuse_reply_err(req, EINVAL);
21552155
return;
21562156
}

tests/meta/TestCommon.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ using hf3fs::meta::InodeId;
3535

3636
static void print(const Path &path) {
3737
fmt::print("path {}\n", path);
38-
fmt::print("abs {}, complete {}, relative {}\n", path.is_absolute(), path.is_complete(), path.is_relative());
38+
fmt::print("abs {}, relative {}\n", path.is_absolute(), path.is_relative());
3939
fmt::print("has root {}, {}\n", path.has_root_path(), path.root_path());
4040
fmt::print("has relative {}, {}\n", path.has_relative_path(), path.relative_path());
41-
fmt::print("has branch {}, {}\n", path.has_parent_path(), path.branch_path());
41+
fmt::print("has branch {}, {}\n", path.has_parent_path(), path.parent_path());
4242
fmt::print("has stem {}, {}\n", path.has_stem(), path.stem());
4343
fmt::print("has filename {}, {}, is dot {}, is dot dot {}\n",
4444
path.has_filename(),
4545
path.filename(),
4646
path.filename_is_dot(),
4747
path.filename_is_dot_dot());
48-
fmt::print("has leaf {}, {}", path.has_leaf(), path.leaf());
48+
fmt::print("has leaf {}, {}", !path.empty(), path.filename());
4949
fmt::print("size {}, components {}, first {}, last {}\n",
5050
path.size(),
5151
std::distance(path.begin(), path.end()),

tests/meta/store/ops/TestResolve.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ TYPED_TEST(TestResolve, pathRange) {
196196
auto path = PathAt("/a/b/c/d");
197197
Path trace;
198198
auto result = co_await PathResolveOp(*txn, aclCache, SUPER_USER, &trace).pathRange(path);
199-
std::cout << "resolve " << *path.path << " -> " << trace << " " << trace.normalize() << std::endl;
199+
std::cout << "resolve " << *path.path << " -> " << trace << " " << trace.lexically_normal() << std::endl;
200200
CO_ASSERT_OK(result);
201201
CO_ASSERT_TRUE(result->missing.empty()) << result->missing;
202202
CO_ASSERT_EQ(result->getParentId(), c.id);
@@ -208,7 +208,7 @@ TYPED_TEST(TestResolve, pathRange) {
208208
auto path = Path("/a/b/c/e");
209209
Path trace;
210210
auto result = co_await PathResolveOp(*txn, aclCache, SUPER_USER, &trace).pathRange(path);
211-
std::cout << "resolve " << path << " -> " << trace << " " << trace.normalize() << std::endl;
211+
std::cout << "resolve " << path << " -> " << trace << " " << trace.lexically_normal() << std::endl;
212212
CO_ASSERT_OK(result);
213213
CO_ASSERT_TRUE(result->missing.empty()) << result->missing;
214214
CO_ASSERT_EQ(result->getParentId(), c.id);
@@ -221,7 +221,7 @@ TYPED_TEST(TestResolve, pathRange) {
221221
Path trace;
222222
auto result = co_await PathResolveOp(*txn, aclCache, SUPER_USER, &trace).pathRange(path);
223223
CO_ASSERT_OK(result);
224-
std::cout << "resolve " << *path.path << " -> " << trace << " " << trace.normalize() << std::endl;
224+
std::cout << "resolve " << *path.path << " -> " << trace << " " << trace.lexically_normal() << std::endl;
225225
CO_ASSERT_TRUE(result->missing.empty()) << result->missing;
226226
CO_ASSERT_EQ(result->getParentId(), c.id);
227227
CO_ASSERT_EQ(result->dirEntry.value(), dEntry);

0 commit comments

Comments
 (0)