-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPath.cpp
More file actions
45 lines (37 loc) · 1.11 KB
/
Path.cpp
File metadata and controls
45 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "swift/extractor/infra/file/Path.h"
#include <iostream>
#include <unistd.h>
#include "swift/extractor/infra/file/FsLogger.h"
using namespace std::string_view_literals;
namespace codeql {
using namespace fs_logger;
static bool shouldCanonicalize() {
for (auto var : {"CODEQL_PRESERVE_SYMLINKS", "SEMMLE_PRESERVE_SYMLINKS"}) {
if (auto preserve = getenv(var); preserve && preserve == "true"sv) {
return false;
}
}
return true;
}
std::filesystem::path resolvePath(const std::filesystem::path& path) {
std::error_code ec;
std::filesystem::path ret = {};
static const auto canonicalize = shouldCanonicalize();
if (canonicalize) {
ret = std::filesystem::weakly_canonical(path, ec);
} else {
ret = std::filesystem::absolute(path, ec);
}
if (ec) {
if (ec.value() == ENOENT) {
// this is pretty normal, nothing to spam about
LOG_DEBUG("resolving non-existing {}", path);
} else {
LOG_WARNING("cannot get {} path for {} ({})", canonicalize ? "canonical" : "absolute", path,
ec);
}
return path;
}
return ret;
}
} // namespace codeql