#include <util/file.hpp>
#include <util/filesystem.hpp>
#include <util/fmtmacros.hpp>
-#include <util/path.hpp>
#include <util/string.hpp>
#include <util/wincompat.hpp>
Config dummy_config;
dummy_config.set_item(key, value, std::nullopt, false, "");
- const auto resolved_path = util::real_path(path);
- if (!DirEntry(resolved_path).is_regular_file()) {
- core::ensure_dir_exists(Util::dir_name(resolved_path));
+ const fs::path resolved_path = fs::canonical(path).value_or(path);
+ if (!fs::is_regular_file(resolved_path)) {
+ core::ensure_dir_exists(resolved_path.parent_path());
util::throw_on_error<core::Error>(
util::write_file(resolved_path, ""),
FMT("failed to write to {}: ", resolved_path));
-// Copyright (C) 2019-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
dir_entry = DirEntry(path);
}
const auto path_suffix = std::string(original_path.substr(path.length()));
- const auto real_path = util::real_path(path);
+ const std::string real_path = fs::canonical(path).value_or(path).string();
const auto add_relpath_candidates = [&](auto p) {
const std::string normalized_path =
if (!ctx.args_info.profile_path.empty()) {
dir = ctx.args_info.profile_path;
} else {
- dir = util::real_path(Util::dir_name(ctx.args_info.output_obj));
+ const auto output_dir = fs::path(ctx.args_info.output_obj).parent_path();
+ dir = fs::canonical(output_dir).value_or(output_dir).string();
}
std::string_view stem = Util::remove_extension(
fs::path(ctx.args_info.output_obj).filename().string());
-// Copyright (C) 2023 Joel Rosdahl and other contributors
+// Copyright (C) 2023-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
if (path_end == std::string_view::npos) {
result.append(line.data(), line.length());
} else {
- std::string path(line.substr(0, path_end));
- if (util::DirEntry(path)) {
- result += util::real_path(path);
- auto tail = line.substr(path_end);
- result.append(tail.data(), tail.length());
- } else {
- result.append(line.data(), line.length());
- }
+ fs::path path(line.substr(0, path_end));
+ result += fs::canonical(path).value_or(path).string();
+ auto tail = line.substr(path_end);
+ result.append(tail.data(), tail.length());
}
}
return result;
return true;
}
-std::string
-real_path(std::string_view path)
-{
- auto real_path = fs::canonical(path);
- return real_path ? real_path->string() : std::string(path);
-}
-
} // namespace util
#include <util/string.hpp>
+#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
// Windows
bool path_starts_with(std::string_view path, std::string_view prefix);
-// Return a normalized absolute path of `path`. On error (e.g. if the `path`
-// doesn't exist) path is returned unmodified.
-std::string real_path(std::string_view path);
-
// --- Inline implementations ---
inline bool