diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-09 17:37:02 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-09 17:37:02 +0000 |
commit | 61187dd0ad3d8574f655074e3e7948193d90bb1e (patch) | |
tree | 079e0acc8c744b6498369fc0ce5bd3d14027a6d0 | |
parent | 333fb04506233255f10d8095c9e2de5e5f0fdc6f (diff) |
Support/FileSystem: Change file_status predicate functions that cannot fail to
return their result instead of an error_code. Also add some missing predicate
functions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121380 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Support/FileSystem.h | 65 | ||||
-rw-r--r-- | lib/Support/PathV2.cpp | 27 |
2 files changed, 61 insertions, 31 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h index 121e77066e..5263d32153 100644 --- a/include/llvm/Support/FileSystem.h +++ b/include/llvm/Support/FileSystem.h @@ -231,11 +231,9 @@ error_code set_execute(const Twine &path, bool value); /// @brief Does file exist? /// /// @param status A file_status previously returned from stat. -/// @param result Set to true if the file represented by status exists, false if -/// it does not. Undefined otherwise. -/// @results errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -error_code exists(file_status status, bool &result); +/// @results True if the file represented by status exists, false if it does +/// not. +bool exists(file_status status); /// @brief Does file exist? /// @@ -246,6 +244,17 @@ error_code exists(file_status status, bool &result); /// platform specific error_code. error_code exists(const Twine &path, bool &result); +/// @brief Do file_status's represent the same thing? +/// +/// @param A Input file_status. +/// @param B Input file_status. +/// +/// assert(status_known(A) || status_known(B)); +/// +/// @results True if A and B both represent the same file system entity, false +/// otherwise. +bool equivalent(file_status A, file_status B); + /// @brief Do paths represent the same thing? /// /// @param A Input path A. @@ -266,12 +275,9 @@ error_code file_size(const Twine &path, uint64_t &result); /// @brief Does status represent a directory? /// -/// @param status A file_status previously returned from stat. -/// @param result Set to true if the file represented by status is a directory, -/// false if it is not. Undefined otherwise. -/// @results errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -error_code is_directory(file_status status, bool &result); +/// @param status A file_status previously returned from status. +/// @results status.type() == file_type::directory_file. +bool is_directory(file_status status); /// @brief Is path a directory? /// @@ -293,12 +299,9 @@ error_code is_empty(const Twine &path, bool &result); /// @brief Does status represent a regular file? /// -/// @param status A file_status previously returned from stat. -/// @param result Set to true if the file represented by status is a regular -/// file, false if it is not. Undefined otherwise. -/// @results errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -error_code is_regular_file(file_status status, bool &result); +/// @param status A file_status previously returned from status. +/// @results status_known(status) && status.type() == file_type::regular_file. +bool is_regular_file(file_status status); /// @brief Is path a regular file? /// @@ -309,16 +312,13 @@ error_code is_regular_file(file_status status, bool &result); /// platform specific error_code. error_code is_regular_file(const Twine &path, bool &result); -/// @brief Does status represent something that exists but is not a directory, -/// regular file, or symlink? +/// @brief Does this status represent something that exists but is not a +/// directory, regular file, or symlink? /// -/// @param status A file_status previously returned from stat. -/// @param result Set to true if the file represented by status exists, but is -/// not a directory, regular file, or a symlink, false if it does -/// not. Undefined otherwise. -/// @results errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -error_code is_other(file_status status, bool &result); +/// @param status A file_status previously returned from status. +/// @results exists(s) && !is_regular_file(s) && !is_directory(s) && +/// !is_symlink(s) +bool is_other(file_status status); /// @brief Is path something that exists but is not a directory, /// regular file, or symlink? @@ -333,11 +333,8 @@ error_code is_other(const Twine &path, bool &result); /// @brief Does status represent a symlink? /// /// @param status A file_status previously returned from stat. -/// @param result Set to true if the file represented by status is a symlink, -/// false if it is not. Undefined otherwise. -/// @results errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -error_code is_symlink(file_status status, bool &result); +/// @param result status.type() == symlink_file. +bool is_symlink(file_status status); /// @brief Is path a symlink? /// @@ -393,6 +390,12 @@ error_code status(const Twine &path, file_status &result); /// @brief Is status available? /// /// @param path Input path. +/// @results True if status() != status_error. +bool status_known(file_status s); + +/// @brief Is status available? +/// +/// @param path Input path. /// @param result Set to true if status() != status_error. /// @results errc::success if result has been successfully set, otherwise a /// platform specific error_code. diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 60e03e05f5..54522702d1 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -625,6 +625,33 @@ error_code create_directories(const Twine &path, bool &existed) { return create_directory(p, existed); } +bool exists(file_status status) { + return status_known(status) && status.type() != file_type::file_not_found; +} + +bool status_known(file_status s) { + return s.type() != file_type::status_error; +} + +bool is_directory(file_status status) { + return status.type() == file_type::directory_file; +} + +bool is_regular_file(file_status status) { + return status.type() == file_type::regular_file; +} + +bool is_symlink(file_status status) { + return status.type() == file_type::symlink_file; +} + +bool is_other(file_status status) { + return exists(status) && + !is_regular_file(status) && + !is_directory(status) && + !is_symlink(status); +} + void directory_entry::replace_filename(const Twine &filename, file_status st, file_status symlink_st) { SmallString<128> path(Path.begin(), Path.end()); |