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.

llvm-svn: 121380
This commit is contained in:
Michael J. Spencer 2010-12-09 17:37:02 +00:00
parent 15483143ec
commit 1d95a8f9bc
2 changed files with 61 additions and 31 deletions

View File

@ -231,11 +231,9 @@ error_code set_execute(const Twine &path, bool value);
/// @brief Does file exist? /// @brief Does file exist?
/// ///
/// @param status A file_status previously returned from stat. /// @param status A file_status previously returned from stat.
/// @param result Set to true if the file represented by status exists, false if /// @results True if the file represented by status exists, false if it does
/// it does not. Undefined otherwise. /// not.
/// @results errc::success if result has been successfully set, otherwise a bool exists(file_status status);
/// platform specific error_code.
error_code exists(file_status status, bool &result);
/// @brief Does file exist? /// @brief Does file exist?
/// ///
@ -246,6 +244,17 @@ error_code exists(file_status status, bool &result);
/// platform specific error_code. /// platform specific error_code.
error_code exists(const Twine &path, bool &result); 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? /// @brief Do paths represent the same thing?
/// ///
/// @param A Input path A. /// @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? /// @brief Does status represent a directory?
/// ///
/// @param status A file_status previously returned from stat. /// @param status A file_status previously returned from status.
/// @param result Set to true if the file represented by status is a directory, /// @results status.type() == file_type::directory_file.
/// false if it is not. Undefined otherwise. bool is_directory(file_status status);
/// @results errc::success if result has been successfully set, otherwise a
/// platform specific error_code.
error_code is_directory(file_status status, bool &result);
/// @brief Is path a directory? /// @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? /// @brief Does status represent a regular file?
/// ///
/// @param status A file_status previously returned from stat. /// @param status A file_status previously returned from status.
/// @param result Set to true if the file represented by status is a regular /// @results status_known(status) && status.type() == file_type::regular_file.
/// file, false if it is not. Undefined otherwise. bool is_regular_file(file_status status);
/// @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);
/// @brief Is path a regular file? /// @brief Is path a regular file?
/// ///
@ -309,16 +312,13 @@ error_code is_regular_file(file_status status, bool &result);
/// platform specific error_code. /// platform specific error_code.
error_code is_regular_file(const Twine &path, bool &result); error_code is_regular_file(const Twine &path, bool &result);
/// @brief Does status represent something that exists but is not a directory, /// @brief Does this status represent something that exists but is not a
/// regular file, or symlink? /// directory, regular file, or symlink?
/// ///
/// @param status A file_status previously returned from stat. /// @param status A file_status previously returned from status.
/// @param result Set to true if the file represented by status exists, but is /// @results exists(s) && !is_regular_file(s) && !is_directory(s) &&
/// not a directory, regular file, or a symlink, false if it does /// !is_symlink(s)
/// not. Undefined otherwise. bool is_other(file_status status);
/// @results errc::success if result has been successfully set, otherwise a
/// platform specific error_code.
error_code is_other(file_status status, bool &result);
/// @brief Is path something that exists but is not a directory, /// @brief Is path something that exists but is not a directory,
/// regular file, or symlink? /// regular file, or symlink?
@ -333,11 +333,8 @@ error_code is_other(const Twine &path, bool &result);
/// @brief Does status represent a symlink? /// @brief Does status represent a symlink?
/// ///
/// @param status A file_status previously returned from stat. /// @param status A file_status previously returned from stat.
/// @param result Set to true if the file represented by status is a symlink, /// @param result status.type() == symlink_file.
/// false if it is not. Undefined otherwise. bool is_symlink(file_status status);
/// @results errc::success if result has been successfully set, otherwise a
/// platform specific error_code.
error_code is_symlink(file_status status, bool &result);
/// @brief Is path a symlink? /// @brief Is path a symlink?
/// ///
@ -390,6 +387,12 @@ error_code disk_space(const Twine &path, space_info &result);
/// platform specific error_code. /// platform specific error_code.
error_code status(const Twine &path, file_status &result); 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? /// @brief Is status available?
/// ///
/// @param path Input path. /// @param path Input path.

View File

@ -625,6 +625,33 @@ error_code create_directories(const Twine &path, bool &existed) {
return create_directory(p, 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, void directory_entry::replace_filename(const Twine &filename, file_status st,
file_status symlink_st) { file_status symlink_st) {
SmallString<128> path(Path.begin(), Path.end()); SmallString<128> path(Path.begin(), Path.end());