Skip to content

Commit e7c7a30

Browse files
committed
refactor: replace Boost libraries with C++ standard features
replace uses of boost::filesystem with std::filesystem, and BOOST_FOREACH macro with range-based-for statement.
1 parent 158df5b commit e7c7a30

File tree

4 files changed

+38
-50
lines changed

4 files changed

+38
-50
lines changed

src/concurrency_control/include/lpwal.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
#pragma once
1313

1414
#include <atomic>
15+
#include <filesystem>
1516
#include <mutex>
1617
#include <string_view>
1718
#include <thread>
1819

19-
#include <boost/filesystem.hpp>
20-
2120
#include "concurrency_control/include/epoch.h"
2221

2322
#include "shirakami/log_record.h"
@@ -299,11 +298,10 @@ class handler {
299298
}
300299

301300
[[maybe_unused]] static void remove_under_log_dir() {
302-
std::string ld{get_log_dir()};
303-
const boost::filesystem::path path(ld);
301+
const std::filesystem::path path(get_log_dir());
304302
try {
305-
boost::filesystem::remove_all(path);
306-
} catch (boost::filesystem::filesystem_error& ex) {
303+
std::filesystem::remove_all(path);
304+
} catch (std::filesystem::filesystem_error& ex) {
307305
LOG_FIRST_N(ERROR, 1)
308306
<< log_location_prefix << "file system error: " << ex.what()
309307
<< " : " << path;

src/concurrency_control/interface/start_up.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22

3+
#include <filesystem>
34
#include <sstream>
45
#include <string_view>
56

@@ -39,8 +40,6 @@
3940

4041
#include "shirakami/interface.h"
4142

42-
#include "boost/filesystem/path.hpp"
43-
4443
#include "glog/logging.h"
4544

4645
namespace shirakami {
@@ -76,9 +75,8 @@ static Status create_datastore(database_options options) { // NOLINT
7675
lpwal::set_log_dir(log_dir);
7776
lpwal::set_log_dir_pointed(true);
7877
// check exist
79-
boost::filesystem::path ldp{std::string(options.get_log_directory_path())}; // NOLINT
80-
boost::system::error_code error;
81-
const bool result = boost::filesystem::exists(ldp, error);
78+
std::error_code error;
79+
const bool result = std::filesystem::exists(options.get_log_directory_path(), error);
8280
if (!result || error) {
8381
// exists
8482
if (options.get_open_mode() == database_options::open_mode::CREATE) {

test/datastore/li_logging_filesize_test.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <array>
55
#include <atomic>
6+
#include <filesystem>
67
#include <mutex>
78
#include <string_view>
89
#include <thread>
@@ -26,9 +27,6 @@
2627

2728
#include "glog/logging.h"
2829

29-
#include "boost/filesystem.hpp"
30-
#include "boost/foreach.hpp"
31-
3230
namespace shirakami::testing {
3331

3432
using namespace shirakami;
@@ -49,13 +47,11 @@ class li_logging_test : public ::testing::Test { // NOLINT
4947
static inline std::once_flag init_google; // NOLINT
5048
};
5149

52-
std::size_t dir_size(boost::filesystem::path& path) {
50+
std::size_t dir_size(std::filesystem::path& path) {
5351
std::size_t total_file_size{0};
54-
BOOST_FOREACH (const boost::filesystem::path& p, // NOLINT
55-
std::make_pair(boost::filesystem::directory_iterator(path),
56-
boost::filesystem::directory_iterator())) {
57-
if (!boost::filesystem::is_directory(p)) {
58-
total_file_size += boost::filesystem::file_size(p);
52+
for (const std::filesystem::path& p : std::filesystem::directory_iterator(path)) {
53+
if (!std::filesystem::is_directory(p)) {
54+
total_file_size += std::filesystem::file_size(p);
5955
}
6056
}
6157

@@ -73,7 +69,7 @@ TEST_F(li_logging_test, // NOLINT
7369
// prepare test
7470
std::string log_dir{};
7571
log_dir = create_log_dir_name();
76-
boost::filesystem::path data_location(log_dir);
72+
std::filesystem::path data_location(log_dir);
7773
init({database_options::open_mode::CREATE, log_dir}); // NOLINT
7874
Storage st{};
7975
ASSERT_EQ(Status::OK, create_storage("", st));

test/datastore/limestone_unit_test.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <array>
55
#include <atomic>
6+
#include <filesystem>
67
#include <mutex>
78
#include <string_view>
89
#include <thread>
@@ -25,9 +26,6 @@
2526

2627
#include "glog/logging.h"
2728

28-
#include "boost/filesystem.hpp"
29-
#include "boost/foreach.hpp"
30-
3129
#include "limestone/api/datastore.h"
3230

3331
namespace shirakami::testing {
@@ -62,13 +60,11 @@ class limestone_unit_test : public ::testing::Test { // NOLINT
6260
static inline std::string metadata_log_dir_; // NOLINT
6361
};
6462

65-
std::size_t dir_size(boost::filesystem::path& path) {
63+
std::size_t dir_size(std::filesystem::path& path) {
6664
std::size_t total_file_size{0};
67-
BOOST_FOREACH (const boost::filesystem::path& p, // NOLINT
68-
std::make_pair(boost::filesystem::directory_iterator(path),
69-
boost::filesystem::directory_iterator())) {
70-
if (!boost::filesystem::is_directory(p)) {
71-
total_file_size += boost::filesystem::file_size(p);
65+
for (const std::filesystem::path& p : std::filesystem::directory_iterator(path)) {
66+
if (!std::filesystem::is_directory(p)) {
67+
total_file_size += std::filesystem::file_size(p);
7268
}
7369
}
7470

@@ -92,8 +88,8 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
9288
std::string data_dir =
9389
"/tmp/shirakami" + std::to_string(tid) + "-" + std::to_string(tsc);
9490
std::string metadata_dir = data_dir + "m";
95-
boost::filesystem::path data_location(data_dir);
96-
boost::filesystem::path metadata_path(metadata_dir);
91+
std::filesystem::path data_location(data_dir);
92+
std::filesystem::path metadata_path(metadata_dir);
9793

9894
// prepare durable epoch
9995
std::atomic<size_t> limestone_durable_epoch{0};
@@ -106,14 +102,14 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
106102
};
107103

108104
// prepare data / metadata directory
109-
if (boost::filesystem::exists(data_location)) {
110-
boost::filesystem::remove_all(data_location);
105+
if (std::filesystem::exists(data_location)) {
106+
std::filesystem::remove_all(data_location);
111107
}
112-
ASSERT_TRUE(boost::filesystem::create_directory(data_location));
113-
if (boost::filesystem::exists(metadata_dir)) {
114-
boost::filesystem::remove_all(metadata_dir);
108+
ASSERT_TRUE(std::filesystem::create_directory(data_location));
109+
if (std::filesystem::exists(metadata_dir)) {
110+
std::filesystem::remove_all(metadata_dir);
115111
}
116-
ASSERT_TRUE(boost::filesystem::create_directory(metadata_dir));
112+
ASSERT_TRUE(std::filesystem::create_directory(metadata_dir));
117113

118114
// allocate datastore
119115
std::unique_ptr<limestone::api::datastore> datastore;
@@ -127,7 +123,7 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
127123
#ifdef HAVE_LIMESTONE_DATASTORE_CREATE_CHANNEL_NONE
128124
limestone::api::log_channel* lc{&d_ptr->create_channel()};
129125
#else
130-
limestone::api::log_channel* lc{&d_ptr->create_channel(data_location)};
126+
limestone::api::log_channel* lc{&d_ptr->create_channel(data_dir)};
131127
#endif
132128

133129
// start datastore
@@ -157,10 +153,10 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
157153
}
158154

159155
// check existence of log file about (*1)
160-
ASSERT_TRUE(boost::filesystem::exists(data_location));
156+
ASSERT_TRUE(std::filesystem::exists(data_location));
161157

162158
// log file size after flushing log (*1)
163-
boost::uintmax_t size1 = dir_size(data_location);
159+
auto size1 = dir_size(data_location);
164160

165161
// flush logs
166162
lc->begin_session();
@@ -180,7 +176,7 @@ TEST_F(limestone_unit_test, logging_and_recover) { // NOLINT
180176
}
181177

182178
// log file size after flushing log (*2)
183-
boost::uintmax_t size2 = dir_size(data_location);
179+
auto size2 = dir_size(data_location);
184180

185181
// verify size1 != size2
186182
ASSERT_NE(size1, size2);
@@ -219,8 +215,8 @@ TEST_F(limestone_unit_test, persistent_callback) { // NOLINT
219215
std::string data_dir =
220216
"/tmp/shirakami" + std::to_string(tid) + "-" + std::to_string(tsc);
221217
std::string metadata_dir = data_dir + "m";
222-
boost::filesystem::path data_location(data_dir);
223-
boost::filesystem::path metadata_path(metadata_dir);
218+
std::filesystem::path data_location(data_dir);
219+
std::filesystem::path metadata_path(metadata_dir);
224220

225221
// prepare durable epoch
226222
std::atomic<size_t> limestone_durable_epoch{0};
@@ -233,14 +229,14 @@ TEST_F(limestone_unit_test, persistent_callback) { // NOLINT
233229
};
234230

235231
// prepare data / metadata directory
236-
if (boost::filesystem::exists(data_location)) {
237-
boost::filesystem::remove_all(data_location);
232+
if (std::filesystem::exists(data_location)) {
233+
std::filesystem::remove_all(data_location);
238234
}
239-
ASSERT_TRUE(boost::filesystem::create_directory(data_location));
240-
if (boost::filesystem::exists(metadata_dir)) {
241-
boost::filesystem::remove_all(metadata_dir);
235+
ASSERT_TRUE(std::filesystem::create_directory(data_location));
236+
if (std::filesystem::exists(metadata_dir)) {
237+
std::filesystem::remove_all(metadata_dir);
242238
}
243-
ASSERT_TRUE(boost::filesystem::create_directory(metadata_dir));
239+
ASSERT_TRUE(std::filesystem::create_directory(metadata_dir));
244240

245241
// allocate datastore
246242
std::unique_ptr<limestone::api::datastore> datastore;

0 commit comments

Comments
 (0)