From 2bfd3c4edcff500f3cf07957518d1311b0a5b2c1 Mon Sep 17 00:00:00 2001 From: Alex Pankhurst Date: Tue, 10 Sep 2019 10:16:01 -0700 Subject: [PATCH] [POSIX] stop logging on ENOENT This change stops IsRegularFile and IsDirectory from logging an error in the instance that a file or directory cannot be found. Change-Id: I9f3c409933245708db775f566a27f5e49b2c71f3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1795924 Commit-Queue: Francois Rousseau Reviewed-by: Scott Graham --- util/file/filesystem.h | 6 +++++- util/file/filesystem_posix.cc | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/util/file/filesystem.h b/util/file/filesystem.h index 27a4d1de..e12f1271 100644 --- a/util/file/filesystem.h +++ b/util/file/filesystem.h @@ -73,7 +73,8 @@ bool MoveFileOrDirectory(const base::FilePath& source, //! failure. //! //! On POSIX, this function returns `true` if \a path refers to a file that is -//! not a symbolic link, directory, or other kind of special file. +//! not a symbolic link, directory, or other kind of special file. If this +//! function fails because \a path does not exist, then no message is logged. //! //! On Windows, this function returns `true` if \a path refers to a file that //! is not a symbolic link or directory. @@ -85,6 +86,9 @@ bool IsRegularFile(const base::FilePath& path); //! \brief Determines if a path refers to a directory, logging a message on //! failure. //! +//! On POSIX, if this function fails because \a path does not exist, then no +//! message is logged. +//! //! \param[in] path The path to check. //! \param[in] allow_symlinks Whether to allow the final component in the path //! to be a symbolic link to a directory. diff --git a/util/file/filesystem_posix.cc b/util/file/filesystem_posix.cc index b1f19f62..bb51a9c1 100644 --- a/util/file/filesystem_posix.cc +++ b/util/file/filesystem_posix.cc @@ -76,7 +76,7 @@ bool MoveFileOrDirectory(const base::FilePath& source, bool IsRegularFile(const base::FilePath& path) { struct stat st; if (lstat(path.value().c_str(), &st) != 0) { - PLOG(ERROR) << "stat " << path.value(); + PLOG_IF(ERROR, errno != ENOENT) << "stat " << path.value(); return false; } return S_ISREG(st.st_mode); @@ -86,11 +86,11 @@ bool IsDirectory(const base::FilePath& path, bool allow_symlinks) { struct stat st; if (allow_symlinks) { if (stat(path.value().c_str(), &st) != 0) { - PLOG(ERROR) << "stat " << path.value(); + PLOG_IF(ERROR, errno != ENOENT) << "stat " << path.value(); return false; } } else if (lstat(path.value().c_str(), &st) != 0) { - PLOG(ERROR) << "lstat " << path.value(); + PLOG_IF(ERROR, errno != ENOENT) << "lstat " << path.value(); return false; } return S_ISDIR(st.st_mode);