2021-03-08 09:25:23 +03:00
|
|
|
#include "mold.h"
|
|
|
|
|
2021-12-30 01:47:55 +03:00
|
|
|
#include <filesystem>
|
2021-11-30 09:23:00 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2021-09-08 13:49:51 +03:00
|
|
|
namespace mold {
|
2021-09-02 12:19:43 +03:00
|
|
|
|
2021-11-27 13:57:38 +03:00
|
|
|
std::string get_realpath(std::string_view path) {
|
2021-12-30 14:32:06 +03:00
|
|
|
std::error_code ec;
|
|
|
|
std::string ret = std::filesystem::canonical(path, ec);
|
2021-12-31 10:21:52 +03:00
|
|
|
return ec ? std::string(path) : ret;
|
2021-04-09 10:05:52 +03:00
|
|
|
}
|
|
|
|
|
2021-04-18 07:30:55 +03:00
|
|
|
// Removes redundant '/..' or '/.' from a given path.
|
|
|
|
// The transformation is done purely by lexical processing.
|
|
|
|
// This function does not access file system.
|
2021-03-16 18:26:28 +03:00
|
|
|
std::string path_clean(std::string_view path) {
|
2021-12-31 10:21:52 +03:00
|
|
|
return filepath(path).lexically_normal();
|
|
|
|
}
|
2021-12-30 16:14:52 +03:00
|
|
|
|
2021-12-31 10:21:52 +03:00
|
|
|
std::filesystem::path to_abs_path(std::filesystem::path path) {
|
|
|
|
if (path.is_absolute())
|
|
|
|
return path;
|
|
|
|
return (std::filesystem::current_path() / path).lexically_normal();
|
2021-03-16 18:26:28 +03:00
|
|
|
}
|
2021-09-02 12:19:43 +03:00
|
|
|
|
2021-09-08 13:49:51 +03:00
|
|
|
} // namespace mold
|