linker: use stat(2) to check file existence

open(2) can be used to open directories; use stat to
check that the file exists and is a regular file.

Addresses review comments for 5aa67675f8

Bug: http://b/30320104
Change-Id: Ia944db2f2f779a87ea01dd41dcd171e59c9bef01
This commit is contained in:
Dimitry Ivanov 2016-08-11 11:11:52 -07:00
parent cea35d77a2
commit 4cf7024db7
1 changed files with 5 additions and 5 deletions

View File

@ -131,13 +131,13 @@ static bool is_system_library(const std::string& realpath) {
// Checks if the file exists and not a directory.
static bool file_exists(const char* path) {
int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC));
if (fd == -1) {
struct stat s;
if (stat(path, &s) != 0) {
return false;
} else {
close(fd);
return true;
}
return S_ISREG(s.st_mode);
}
// TODO(dimitry): The grey-list is a workaround for http://b/26394120 ---