Skip to content

Commit 71435b8

Browse files
authored
refactor: always use fs logic (#1037)
1 parent 0127894 commit 71435b8

6 files changed

Lines changed: 17 additions & 65 deletions

File tree

app/src/cli/cli.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <cli/cli.hpp>
22

33
#include <algorithm>
4+
#include <filesystem>
45
#include <sstream>
56
#include <string_view>
67
#include <type_traits>
78

89
#include <cli/cli_args.hpp>
910
#include <cli/sanitize.hpp>
10-
#include <core/filesystem/file_system.hpp>
1111
#include <core/logger/logger.hpp>
1212
#include <core/rand.hpp>
1313
#include <matchmaking/output/output_factory.hpp>
@@ -123,7 +123,7 @@ TimeControl::Limits parseTc(const std::string& tcString) {
123123
if (has_minutes) {
124124
const auto clock_vector = str_utils::splitString(remainingStringVector, ':');
125125
tc.time = static_cast<int64_t>(std::stod(clock_vector[0]) * 1000 * 60) +
126-
static_cast<int64_t>(std::stod(clock_vector[1]) * 1000);
126+
static_cast<int64_t>(std::stod(clock_vector[1]) * 1000);
127127
} else {
128128
tc.time = static_cast<int64_t>(std::stod(remainingStringVector) * 1000);
129129
}
@@ -259,11 +259,9 @@ void parseOpening(const KeyValuePairs& params, ArgumentData& argument_data) {
259259
argument_data.tournament_config.opening.format = FormatType::PGN;
260260
}
261261

262-
#ifndef NO_STD_FILESYSTEM
263262
if (!std::filesystem::exists(value)) {
264263
throw fastchess_exception("Opening file does not exist: " + value);
265264
}
266-
#endif
267265
} else if (key == "format") {
268266
if (value == "epd") {
269267
argument_data.tournament_config.opening.format = FormatType::EPD;

app/src/cli/sanitize.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <vector>
88

99
#include <core/filesystem/fd_limit.hpp>
10-
#include <core/filesystem/file_system.hpp>
1110
#include <core/logger/logger.hpp>
1211
#include <matchmaking/sprt/sprt.hpp>
1312
#include <types/exception.hpp>
@@ -124,11 +123,7 @@ void validateEngine(EngineConfiguration& config) {
124123
throw fastchess_exception("Error; cannot use tc and st together!");
125124
}
126125

127-
#ifndef NO_STD_FILESYSTEM
128-
std::filesystem::path enginePath = config.cmd;
129-
if (!config.dir.empty()) {
130-
enginePath = (std::filesystem::path(config.dir) / config.cmd);
131-
}
126+
auto enginePath = config.getEnginePath();
132127

133128
if (!config.dir.empty() || enginePath.is_absolute()) {
134129
if (!std::filesystem::is_regular_file(enginePath)) {
@@ -141,8 +136,7 @@ void validateEngine(EngineConfiguration& config) {
141136
std::filesystem::path p(config.cmd);
142137
config.name = p.stem().string();
143138
}
144-
#endif
145-
139+
146140
if (config.name.empty()) {
147141
throw fastchess_exception("Error; please specify a name for each engine!");
148142
}
@@ -169,7 +163,7 @@ void sanitize(std::vector<EngineConfiguration>& configs) {
169163
std::unordered_map<std::string, int> seen;
170164
for (auto& config : configs) {
171165
int& n = seen[config.name];
172-
166+
173167
if (n++ > 0) {
174168
config.name += "_" + std::to_string(n);
175169
}

app/src/core/filesystem/file_system.hpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/src/engine/process/iprocess.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma once
22

33
#include <chrono>
4+
#include <filesystem>
45
#include <functional>
56
#include <string>
67
#include <string_view>
78
#include <vector>
89

9-
#include <core/filesystem/file_system.hpp>
10-
1110
namespace fastchess::engine::process {
1211

1312
enum class Standard { INPUT, OUTPUT, ERR };
@@ -71,13 +70,9 @@ class IProcess {
7170

7271
protected:
7372
[[nodiscard]] std::string getPath(const std::string& dir, const std::string& cmd) const {
74-
std::string path = (dir == "." ? "" : dir) + cmd;
75-
#ifndef NO_STD_FILESYSTEM
7673
// convert path to a filesystem path
7774
auto p = std::filesystem::path(dir) / std::filesystem::path(cmd);
78-
path = p.string();
79-
#endif
80-
return path;
75+
return p.string();
8176
}
8277

8378
bool realtime_logging_ = true;

app/src/matchmaking/syzygy.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include <matchmaking/syzygy.hpp>
22

3-
#include <core/filesystem/file_system.hpp>
4-
53
#include <pyrrhic/tbprobe.h>
64

75
#include <cassert>

app/src/types/engine_config.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <filesystem>
45
#include <optional>
56
#include <string>
67
#include <vector>
8+
#include <filesystem>
79

810
#include <core/helper.hpp>
911
#include <game/timecontrol/timecontrol.hpp>
@@ -57,6 +59,14 @@ struct EngineConfiguration {
5759

5860
return std::nullopt;
5961
}
62+
63+
std::filesystem::path getEnginePath() const {
64+
if (!dir.empty()) {
65+
return std::filesystem::path(dir) / cmd;
66+
}
67+
68+
return std::filesystem::path(cmd);
69+
}
6070
};
6171
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(EngineConfiguration, name, dir, cmd, args, restart, options, limit, variant)
6272

0 commit comments

Comments
 (0)