Skip to content

Commit aec4bce

Browse files
committed
runtime: Replace boost::filesystem with std::filesystem
BREAKING CHANGES: - xdg_ functions take and return std::filesystem::path instead of boost::filesystem::path. - Command takes a std::filesystem::path instead of boost::filesystem::path. For the most part, all you need to do is change the namespace to migrate.
1 parent 8b0acb2 commit aec4bce

File tree

4 files changed

+72
-83
lines changed

4 files changed

+72
-83
lines changed

runtime/include/cloe/utility/command.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222

2323
#pragma once
2424

25-
#include <string> // for string
26-
#include <vector> // for vector<>
25+
#include <filesystem> // for filesystem::path
26+
#include <string> // for string
27+
#include <vector> // for vector<>
2728

28-
#include <boost/filesystem/path.hpp> // for path
29-
#include <fable/schema.hpp> // for Schema, Struct, Variant
30-
#include <fable/schema/boost_path.hpp> // for make_schema, Path
29+
#include <fable/schema.hpp> // for Schema, Struct, Variant
3130

3231
#include <cloe/core.hpp> // for Confable, Schema
3332

@@ -77,7 +76,7 @@ class Command : public Confable {
7776
});
7877
}
7978

80-
Command(boost::filesystem::path executable, std::initializer_list<std::string> args) {
79+
Command(const std::filesystem::path& executable, std::initializer_list<std::string> args) {
8180
from_conf(Json{
8281
{"executable", executable.native()},
8382
{"args", args},
@@ -88,7 +87,7 @@ class Command : public Confable {
8887
/**
8988
* Return the executable.
9089
*/
91-
boost::filesystem::path executable() const { return executable_; }
90+
std::filesystem::path executable() const { return executable_; }
9291

9392
/**
9493
* Return the executable arguments.
@@ -159,7 +158,7 @@ class Command : public Confable {
159158
void from_conf(const Conf& c) override;
160159

161160
private:
162-
boost::filesystem::path executable_;
161+
std::filesystem::path executable_;
163162
std::vector<std::string> args_;
164163
std::string command_;
165164
Mode mode_ = Mode::Sync;

runtime/include/cloe/utility/xdg.hpp

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727

2828
#pragma once
2929

30+
#include <filesystem> // for path
3031
#include <functional> // for function
3132
#include <string> // for string
3233
#include <vector> // for vector<>
3334

34-
#include <boost/filesystem/path.hpp> // for path, operator/
35-
36-
namespace cloe {
37-
namespace utility {
35+
namespace cloe::utility {
3836

3937
/**
4038
* This enum class contains all the exceptions that can be thrown.
@@ -69,30 +67,28 @@ enum class XdgError {
6967
// The following xdg_* functions are implementation functions, and aren't meant
7068
// to be used directly.
7169
#ifdef __linux__
72-
boost::filesystem::path xdg_temp_dir();
70+
std::filesystem::path xdg_temp_dir();
7371
#endif
7472

75-
boost::filesystem::path xdg_getenv_path(const std::string& env);
76-
boost::filesystem::path xdg_path(const std::string& env,
77-
const boost::filesystem::path& default_path);
78-
std::vector<boost::filesystem::path> xdg_paths(const std::string& env,
79-
const std::string& default_paths);
73+
std::filesystem::path xdg_getenv_path(const std::string& env);
74+
std::filesystem::path xdg_path(const std::string& env, const std::filesystem::path& default_path);
75+
std::vector<std::filesystem::path> xdg_paths(const std::string& env,
76+
const std::string& default_paths);
8077

8178
/*
8279
* Make sure to ask `is_empty()` on the result.
8380
*/
84-
boost::filesystem::path xdg_find(const boost::filesystem::path& file,
85-
const std::vector<boost::filesystem::path>& dirs);
81+
std::filesystem::path xdg_find(const std::filesystem::path& file,
82+
const std::vector<std::filesystem::path>& dirs);
8683

87-
std::vector<boost::filesystem::path> xdg_findall(const boost::filesystem::path& file,
88-
const std::vector<boost::filesystem::path>& dirs);
84+
std::vector<std::filesystem::path> xdg_findall(const std::filesystem::path& file,
85+
const std::vector<std::filesystem::path>& dirs);
8986

90-
void xdg_merge(const boost::filesystem::path& file,
91-
const std::vector<boost::filesystem::path>& dirs, bool reverse,
92-
std::function<bool(const boost::filesystem::path&)> mergefn);
87+
void xdg_merge(const std::filesystem::path& file, const std::vector<std::filesystem::path>& dirs,
88+
bool reverse, const std::function<bool(const std::filesystem::path&)>& mergefn);
9389

9490
/// User configuration base directory, e.g., `~./config`.
95-
inline boost::filesystem::path config_home() {
91+
inline std::filesystem::path config_home() {
9692
#ifdef __linux__
9793
return xdg_path("XDG_CONFIG_HOME", "~/.config");
9894
#elif WIN32
@@ -101,7 +97,7 @@ inline boost::filesystem::path config_home() {
10197
}
10298

10399
/// User data files base directory, e.g., `~/.local/share`.
104-
inline boost::filesystem::path data_home() {
100+
inline std::filesystem::path data_home() {
105101
#ifdef __linux__
106102
return xdg_path("XDG_DATA_HOME", "~/.local/share");
107103
#elif WIN32
@@ -110,7 +106,7 @@ inline boost::filesystem::path data_home() {
110106
}
111107

112108
/// User cache files base directory, e.g., `~/.cache`.
113-
inline boost::filesystem::path cache_home() {
109+
inline std::filesystem::path cache_home() {
114110
#ifdef __linux__
115111
return xdg_path("XDG_CACHE_HOME", "~/.cache");
116112
#elif WIN32
@@ -119,7 +115,7 @@ inline boost::filesystem::path cache_home() {
119115
}
120116

121117
/// User runtime files base directory, e.g., `/run/user/1000`
122-
inline boost::filesystem::path runtime_dir() {
118+
inline std::filesystem::path runtime_dir() {
123119
#ifdef __linux__
124120
return xdg_path("XDG_RUNTIME_DIR", xdg_temp_dir());
125121
#elif WIN32
@@ -128,7 +124,7 @@ inline boost::filesystem::path runtime_dir() {
128124
}
129125

130126
/// Global configuration directories, e.g., `/etc/xdg`.
131-
inline std::vector<boost::filesystem::path> config_dirs() {
127+
inline std::vector<std::filesystem::path> config_dirs() {
132128
#ifdef __linux__
133129
return xdg_paths("XDG_CONFIG_DIRS", "/etc/xdg");
134130
#elif WIN32
@@ -137,7 +133,7 @@ inline std::vector<boost::filesystem::path> config_dirs() {
137133
}
138134

139135
/// Global data files directories, e.g., `/usr/local/share`.
140-
inline std::vector<boost::filesystem::path> data_dirs() {
136+
inline std::vector<std::filesystem::path> data_dirs() {
141137
#ifdef __linux__
142138
return xdg_paths("XDG_DATA_DIRS", "/usr/local/share:/usr/share");
143139
#elif WIN32
@@ -146,14 +142,14 @@ inline std::vector<boost::filesystem::path> data_dirs() {
146142
}
147143

148144
/// User and global configuration directories
149-
inline std::vector<boost::filesystem::path> all_config_dirs() {
145+
inline std::vector<std::filesystem::path> all_config_dirs() {
150146
auto xs = config_dirs();
151147
xs.insert(xs.begin(), config_home());
152148
return xs;
153149
}
154150

155151
/// User and global data directories
156-
inline std::vector<boost::filesystem::path> all_data_dirs() {
152+
inline std::vector<std::filesystem::path> all_data_dirs() {
157153
auto xs = data_dirs();
158154
xs.insert(xs.begin(), data_home());
159155
return xs;
@@ -164,16 +160,16 @@ inline std::vector<boost::filesystem::path> all_data_dirs() {
164160
*
165161
* This is useful if you want to create a file.
166162
*/
167-
inline boost::filesystem::path user_config(const boost::filesystem::path& file) {
163+
inline std::filesystem::path user_config(const std::filesystem::path& file) {
168164
return config_home() / file;
169165
}
170-
inline boost::filesystem::path user_data(const boost::filesystem::path& file) {
166+
inline std::filesystem::path user_data(const std::filesystem::path& file) {
171167
return data_home() / file;
172168
}
173-
inline boost::filesystem::path user_cache(const boost::filesystem::path& file) {
169+
inline std::filesystem::path user_cache(const std::filesystem::path& file) {
174170
return cache_home() / file;
175171
}
176-
inline boost::filesystem::path user_runtime(const boost::filesystem::path& file) {
172+
inline std::filesystem::path user_runtime(const std::filesystem::path& file) {
177173
return runtime_dir() / file;
178174
}
179175

@@ -183,17 +179,17 @@ inline boost::filesystem::path user_runtime(const boost::filesystem::path& file)
183179
*
184180
* This is useful if you want to read a file.
185181
*/
186-
inline boost::filesystem::path find_config(const boost::filesystem::path& file) {
182+
inline std::filesystem::path find_config(const std::filesystem::path& file) {
187183
return xdg_find(file, all_config_dirs());
188184
}
189-
inline boost::filesystem::path find_data(const boost::filesystem::path& file) {
185+
inline std::filesystem::path find_data(const std::filesystem::path& file) {
190186
return xdg_find(file, all_data_dirs());
191187
}
192-
inline boost::filesystem::path find_cache(const boost::filesystem::path& file) {
193-
return xdg_find(file, std::vector<boost::filesystem::path>{cache_home()});
188+
inline std::filesystem::path find_cache(const std::filesystem::path& file) {
189+
return xdg_find(file, std::vector<std::filesystem::path>{cache_home()});
194190
}
195-
inline boost::filesystem::path find_runtime(const boost::filesystem::path& file) {
196-
return xdg_find(file, std::vector<boost::filesystem::path>{runtime_dir()});
191+
inline std::filesystem::path find_runtime(const std::filesystem::path& file) {
192+
return xdg_find(file, std::vector<std::filesystem::path>{runtime_dir()});
197193
}
198194

199195
/*
@@ -202,10 +198,10 @@ inline boost::filesystem::path find_runtime(const boost::filesystem::path& file)
202198
*
203199
* This is useful if you can read multiple instances of the config or data.
204200
*/
205-
inline std::vector<boost::filesystem::path> find_all_config(const boost::filesystem::path& file) {
201+
inline std::vector<std::filesystem::path> find_all_config(const std::filesystem::path& file) {
206202
return xdg_findall(file, all_config_dirs());
207203
}
208-
inline std::vector<boost::filesystem::path> find_all_data(const boost::filesystem::path& file) {
204+
inline std::vector<std::filesystem::path> find_all_data(const std::filesystem::path& file) {
209205
return xdg_findall(file, all_data_dirs());
210206
}
211207

@@ -217,19 +213,16 @@ inline std::vector<boost::filesystem::path> find_all_data(const boost::filesyste
217213
* Because in merging, the most important file should be loaded last, there
218214
* is a reverse option. If the function returns false, the merging is aborted.
219215
*/
220-
inline void merge_config(const boost::filesystem::path& file,
221-
std::function<bool(const boost::filesystem::path&)>
222-
mergefn,
216+
inline void merge_config(const std::filesystem::path& file,
217+
const std::function<bool(const std::filesystem::path&)>& mergefn,
223218
bool reverse = false) {
224219
xdg_merge(file, all_config_dirs(), reverse, mergefn);
225220
}
226221

227-
inline void merge_data(const boost::filesystem::path& file,
228-
std::function<bool(const boost::filesystem::path&)>
229-
mergefn,
222+
inline void merge_data(const std::filesystem::path& file,
223+
const std::function<bool(const std::filesystem::path&)>& mergefn,
230224
bool reverse = false) {
231225
xdg_merge(file, all_data_dirs(), reverse, mergefn);
232226
}
233227

234-
} // namespace utility
235-
} // namespace cloe
228+
} // namespace cloe::utility

runtime/src/cloe/utility/command.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
#include <cloe/utility/command.hpp>
2424

25-
#include <cstdlib> // for getenv
26-
#include <string> // for string
25+
#include <cstdlib> // for getenv
26+
#include <filesystem> // for path
27+
#include <optional> // for optional<>
28+
#include <string> // for string
2729

28-
#include <boost/filesystem/path.hpp> // for path
29-
#include <boost/process/search_path.hpp> // for search_path
30+
#include <fable/utility/path.hpp> // for search_path
3031

3132
namespace cloe {
3233
namespace {
@@ -39,22 +40,22 @@ namespace {
3940
* quickly lead to errors if the user starting Cloe makes use of an alternative
4041
* shell.
4142
*/
42-
boost::filesystem::path shell_executable() {
43-
for (auto shell : {"bash", "dash", "sh", "zsh"}) {
44-
auto result = boost::process::search_path(shell);
45-
if (!result.empty()) {
46-
return result;
43+
std::filesystem::path shell_executable() {
44+
for (const auto* shell : {"sh", "bash", "dash", "zsh"}) {
45+
auto result = fable::search_path(shell);
46+
if (result) {
47+
return *result;
4748
}
4849
}
4950

5051
if (std::getenv("SHELL") != nullptr) {
51-
auto result = boost::process::search_path(std::getenv("SHELL"));
52-
if (!result.empty()) {
53-
return result;
52+
auto result = fable::search_path(std::getenv("SHELL"));
53+
if (result) {
54+
return *result;
5455
}
5556
}
5657

57-
return boost::filesystem::path{};
58+
return {""};
5859
}
5960

6061
} // namespace

runtime/src/cloe/utility/xdg.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@
2222

2323
#include <cloe/utility/xdg.hpp>
2424

25-
#include <sstream> // for stringstream
26-
#include <string> // for string
27-
#include <vector> // for vector<>
28-
29-
#include <boost/filesystem/operations.hpp> // for temp_directory_path
30-
#include <boost/filesystem/path.hpp> // for path
25+
#include <filesystem> // for path, temp_directory_path
26+
#include <sstream> // for stringstream
27+
#include <string> // for string
28+
#include <vector> // for vector<>
3129

3230
#ifdef __linux__
3331
#include <unistd.h> // for getuid
3432
#endif
3533

36-
namespace cloe {
37-
namespace utility {
34+
namespace cloe::utility {
3835

39-
using boost::filesystem::path; // NOLINT
36+
using std::filesystem::path; // NOLINT
4037

4138
namespace {
4239

@@ -72,7 +69,7 @@ std::vector<path> split(const std::string& paths, char delim = '/') {
7269

7370
#ifdef __linux__
7471
path xdg_temp_dir() {
75-
path tmpdir = boost::filesystem::temp_directory_path();
72+
path tmpdir = std::filesystem::temp_directory_path();
7673
return tmpdir / path("xdg-" + std::to_string(getuid()));
7774
}
7875
#endif
@@ -126,8 +123,8 @@ std::vector<path> xdg_paths(const std::string& env, const std::string& default_p
126123
}
127124

128125
path xdg_find(const path& file, const std::vector<path>& dirs) {
129-
for (auto& dir : dirs) {
130-
if (boost::filesystem::exists(dir / file)) {
126+
for (const auto& dir : dirs) {
127+
if (std::filesystem::exists(dir / file)) {
131128
return dir / file;
132129
}
133130
}
@@ -136,16 +133,16 @@ path xdg_find(const path& file, const std::vector<path>& dirs) {
136133

137134
std::vector<path> xdg_findall(const path& file, const std::vector<path>& dirs) {
138135
std::vector<path> out;
139-
for (auto& dir : dirs) {
140-
if (boost::filesystem::exists(dir / file)) {
136+
for (const auto& dir : dirs) {
137+
if (std::filesystem::exists(dir / file)) {
141138
out.push_back(dir / file);
142139
}
143140
}
144141
return out;
145142
}
146143

147144
void xdg_merge(const path& file, const std::vector<path>& dirs, bool rev,
148-
std::function<bool(const path&)> mergefn) {
145+
const std::function<bool(const path&)>& mergefn) {
149146
auto files = xdg_findall(file, dirs);
150147
if (rev) {
151148
for (auto it = files.rbegin(); it != files.rend(); it++) {
@@ -162,5 +159,4 @@ void xdg_merge(const path& file, const std::vector<path>& dirs, bool rev,
162159
}
163160
}
164161

165-
} // namespace utility
166-
} // namespace cloe
162+
} // namespace cloe::utility

0 commit comments

Comments
 (0)