Skip to content

Commit

Permalink
Use access(2) to determine if a file/directory exists
Browse files Browse the repository at this point in the history
access(2) does not need to validate and fill in the buffer passed to the
kernel, so it's slightly faster.


Commit migrated from dotnet/core-setup@7d70bbe
  • Loading branch information
lpereira committed Jul 19, 2019
1 parent b513f34 commit 73cbea1
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/installer/corehost/common/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,7 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging)

bool pal::file_exists(const pal::string_t& path)
{
if (path.empty())
{
return false;
}
struct stat buffer;
return (::stat(path.c_str(), &buffer) == 0);
return (::access(path.c_str(), F_OK) == 0);
}

static void readdir(const pal::string_t& path, const pal::string_t& pattern, bool onlydirectories, std::vector<pal::string_t>* list)
Expand Down

0 comments on commit 73cbea1

Please sign in to comment.