Skip to content

Commit

Permalink
Use fstat instead of stat
Browse files Browse the repository at this point in the history
  • Loading branch information
riversand963 committed Apr 17, 2020
1 parent 2ee5214 commit 3815457
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,18 @@ class PosixFileSystem : public FileSystem {

IOStatus IsDirectory(const std::string& path, const IOOptions& /*opts*/,
bool* is_dir, IODebugContext* /*dbg*/) override {
// First open
int fd = -1;
int flags = cloexec_flags(O_RDONLY, nullptr);
{
IOSTATS_TIMER_GUARD(open_nanos);
fd = open(path.c_str(), flags);
}
if (fd < 0) {
return IOError("While open for IsDirectory()", path, errno);
}
struct stat sbuf;
if (stat(path.c_str(), &sbuf) < 0) {
if (fstat(fd, &sbuf) < 0) {
return IOError("While doing stat for IsDirectory()", path, errno);
}
if (nullptr != is_dir) {
Expand Down

0 comments on commit 3815457

Please sign in to comment.