Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: path creation #739

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion io/include/detray/io/csv/intersection2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// System include(s).
#include <cstdint>
#include <filesystem>

namespace detray::io::csv {

Expand Down Expand Up @@ -120,7 +121,7 @@ inline void write_intersection2D(
inters_file_name = io::alt_file_name(file_name);
} else {
// Make sure the output directories exit
io::create_path(inters_file_name);
io::create_path(std::filesystem::path{inters_file_name}.parent_path());
}

dfe::NamedTupleCsvWriter<io::csv::intersection2D> inters_writer(
Expand Down
5 changes: 4 additions & 1 deletion io/include/detray/io/csv/track_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <dfe/dfe_io_dsv.hpp>
#include <dfe/dfe_namedtuple.hpp>

// System include(s)
#include <filesystem>

namespace detray::io::csv {

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

dfe::NamedTupleCsvWriter<io::csv::free_track_parameters> track_param_writer(
Expand Down
3 changes: 1 addition & 2 deletions io/include/detray/io/utils/create_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ inline std::string alt_file_name(const std::string& name) {
inline auto create_path(const std::string& outdir) {

auto path = std::filesystem::path(outdir);
path = std::filesystem::is_directory(path) ? path : path.parent_path();

if (!std::filesystem::exists(path)) {
if (!path.empty() && !std::filesystem::exists(path)) {
if (std::error_code err;
!std::filesystem::create_directories(path, err)) {
throw std::runtime_error(err.message());
Expand Down
Loading