summaryrefslogtreecommitdiff
path: root/linker/linker_utils.cpp
diff options
context:
space:
mode:
authorSteven Laver <lavers@google.com>2019-08-07 15:49:43 -0700
committerSteven Laver <lavers@google.com>2019-08-07 15:49:43 -0700
commitbfda022dd6fbbcea60e9f52496d90ece514b32da (patch)
tree97c69d2bdd0e0ff59d55a0d2a8596ed678cded3e /linker/linker_utils.cpp
parent70ebd716b3e81d304cda14d2bd77996cc2840962 (diff)
parent848e1d8a30a3465040edc27085927309fe6cbcff (diff)
Merge RP1A.190528.001
Change-Id: If6e905407e26a19e0266185af46b4ff461c4d45e
Diffstat (limited to 'linker/linker_utils.cpp')
-rw-r--r--linker/linker_utils.cpp77
1 files changed, 42 insertions, 35 deletions
diff --git a/linker/linker_utils.cpp b/linker/linker_utils.cpp
index e92667157..29110ed56 100644
--- a/linker/linker_utils.cpp
+++ b/linker/linker_utils.cpp
@@ -204,47 +204,54 @@ void resolve_paths(std::vector<std::string>& paths,
if (path.empty()) {
continue;
}
+ std::string resolved = resolve_path(path);
+ if (!resolved.empty()) {
+ resolved_paths->push_back(std::move(resolved));
+ }
+ }
+}
- char resolved_path[PATH_MAX];
- const char* original_path = path.c_str();
- if (realpath(original_path, resolved_path) != nullptr) {
- struct stat s;
- if (stat(resolved_path, &s) == -1) {
- DL_WARN("Warning: cannot stat file \"%s\": %s (ignoring)", resolved_path, strerror(errno));
- continue;
- }
- if (!S_ISDIR(s.st_mode)) {
- DL_WARN("Warning: \"%s\" is not a directory (ignoring)", resolved_path);
- continue;
- }
- resolved_paths->push_back(resolved_path);
- } else {
- std::string normalized_path;
- if (!normalize_path(original_path, &normalized_path)) {
- DL_WARN("Warning: unable to normalize \"%s\" (ignoring)", original_path);
- continue;
- }
+std::string resolve_path(const std::string& path) {
+ char resolved_path[PATH_MAX];
+ const char* original_path = path.c_str();
+ if (realpath(original_path, resolved_path) != nullptr) {
+ struct stat s;
+ if (stat(resolved_path, &s) == -1) {
+ DL_WARN("Warning: cannot stat file \"%s\": %s (ignoring)", resolved_path, strerror(errno));
+ return "";
+ }
+ if (!S_ISDIR(s.st_mode)) {
+ DL_WARN("Warning: \"%s\" is not a directory (ignoring)", resolved_path);
+ return "";
+ }
+ return resolved_path;
+ } else {
+ std::string normalized_path;
+ if (!normalize_path(original_path, &normalized_path)) {
+ DL_WARN("Warning: unable to normalize \"%s\" (ignoring)", original_path);
+ return "";
+ }
- std::string zip_path;
- std::string entry_path;
- if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
- if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
- DL_WARN("Warning: unable to resolve \"%s\": %s (ignoring)",
- zip_path.c_str(), strerror(errno));
- continue;
- }
+ std::string zip_path;
+ std::string entry_path;
+ if (parse_zip_path(normalized_path.c_str(), &zip_path, &entry_path)) {
+ if (realpath(zip_path.c_str(), resolved_path) == nullptr) {
+ DL_WARN("Warning: unable to resolve \"%s\": %s (ignoring)",
+ zip_path.c_str(), strerror(errno));
+ return "";
+ }
- resolved_paths->push_back(std::string(resolved_path) + kZipFileSeparator + entry_path);
- } else {
- struct stat s;
- if (stat(normalized_path.c_str(), &s) == 0 && S_ISDIR(s.st_mode)) {
- // Path is not a zip path, but an existing directory. Then add it
- // although we failed to resolve it. b/119656753
- resolved_paths->push_back(normalized_path);
- }
+ return std::string(resolved_path) + kZipFileSeparator + entry_path;
+ } else {
+ struct stat s;
+ if (stat(normalized_path.c_str(), &s) == 0 && S_ISDIR(s.st_mode)) {
+ // Path is not a zip path, but an existing directory. Then add it
+ // although we failed to resolve it. b/119656753
+ return normalized_path;
}
}
}
+ return "";
}
bool is_first_stage_init() {