Skip to content

Commit 3f5afb3

Browse files
authored
Fix path creation (#739)
The is_directory call does not seem to work as expected, so only actual directory paths must be passed to create_path.
1 parent 151356c commit 3f5afb3

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

io/include/detray/io/csv/intersection2D.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
// System include(s).
2020
#include <cstdint>
21+
#include <filesystem>
2122

2223
namespace detray::io::csv {
2324

@@ -120,7 +121,7 @@ inline void write_intersection2D(
120121
inters_file_name = io::alt_file_name(file_name);
121122
} else {
122123
// Make sure the output directories exit
123-
io::create_path(inters_file_name);
124+
io::create_path(std::filesystem::path{inters_file_name}.parent_path());
124125
}
125126

126127
dfe::NamedTupleCsvWriter<io::csv::intersection2D> inters_writer(

io/include/detray/io/csv/track_parameters.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <dfe/dfe_io_dsv.hpp>
1717
#include <dfe/dfe_namedtuple.hpp>
1818

19+
// System include(s)
20+
#include <filesystem>
21+
1922
namespace detray::io::csv {
2023

2124
/// Type to read the data of free track parameters
@@ -110,7 +113,7 @@ inline void write_free_track_params(
110113
trk_file_name = io::alt_file_name(file_name);
111114
} else {
112115
// Make sure the output directories exit
113-
io::create_path(trk_file_name);
116+
io::create_path(std::filesystem::path{trk_file_name}.parent_path());
114117
}
115118

116119
dfe::NamedTupleCsvWriter<io::csv::free_track_parameters> track_param_writer(

io/include/detray/io/utils/create_path.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ inline std::string alt_file_name(const std::string& name) {
7171
inline auto create_path(const std::string& outdir) {
7272

7373
auto path = std::filesystem::path(outdir);
74-
path = std::filesystem::is_directory(path) ? path : path.parent_path();
7574

76-
if (!std::filesystem::exists(path)) {
75+
if (!path.empty() && !std::filesystem::exists(path)) {
7776
if (std::error_code err;
7877
!std::filesystem::create_directories(path, err)) {
7978
throw std::runtime_error(err.message());

0 commit comments

Comments
 (0)