From 9da91a0e03af28eab74be172cd601c5149ae5d0e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 16 Jul 2013 02:55:33 +0000 Subject: [PATCH] Instead friending status, provide windows and posix constructors to file_status. This opens the way of having static helpers in the .inc files that can construct a file_status. llvm-svn: 186376 --- llvm/include/llvm/Support/FileSystem.h | 53 ++++++++++++++++++++++------------ llvm/lib/Support/Unix/Path.inc | 28 ++++++++---------- llvm/lib/Support/Windows/Path.inc | 15 ++++------ 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 0f135e6..8b63015 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -164,14 +164,29 @@ class file_status uint32_t FileIndexLow; #endif friend bool equivalent(file_status A, file_status B); - friend error_code status(const Twine &path, file_status &result); friend error_code getUniqueID(const Twine Path, uint64_t &Result); file_type Type; perms Perms; public: - explicit file_status(file_type v=file_type::status_error, - perms prms=perms_not_known) - : Type(v), Perms(prms) {} + file_status() : Type(file_type::status_error) {} + file_status(file_type Type) : Type(Type) {} + + #if defined(LLVM_ON_UNIX) + file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t MTime, + uid_t UID, gid_t GID, off_t Size) + : fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID), + fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {} + #elif defined(LLVM_ON_WIN32) + file_status(file_type Type, uint32_t LastWriteTimeHigh, + uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber, + uint32_t FileSizeHigh, uint32_t FileSizeLow, + uint32_t FileIndexHigh, uint32_t FileIndexLow) + : LastWriteTimeHigh(LastWriteTimeHigh), + LastWriteTimeLow(LastWriteTimeLow), + VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh), + FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh), + FileIndexLow(FileIndexLow), Type(Type), Perms(perms_not_known) {} + #endif // getters file_type type() const { return Type; } @@ -434,21 +449,6 @@ inline bool equivalent(const Twine &A, const Twine &B) { return !equivalent(A, B, result) && result; } -/// @brief Get file size. -/// -/// @param Path Input path. -/// @param Result Set to the size of the file in \a Path. -/// @returns errc::success if result has been successfully set, otherwise a -/// platform specific error_code. -inline error_code file_size(const Twine &Path, uint64_t &Result) { - file_status Status; - error_code EC = status(Path, Status); - if (EC) - return EC; - Result = Status.getSize(); - return error_code::success(); -} - /// @brief Does status represent a directory? /// /// @param status A file_status previously returned from status. @@ -529,6 +529,21 @@ error_code is_symlink(const Twine &path, bool &result); /// platform specific error_code. error_code status(const Twine &path, file_status &result); +/// @brief Get file size. +/// +/// @param Path Input path. +/// @param Result Set to the size of the file in \a Path. +/// @returns errc::success if result has been successfully set, otherwise a +/// platform specific error_code. +inline error_code file_size(const Twine &Path, uint64_t &Result) { + file_status Status; + error_code EC = status(Path, Status); + if (EC) + return EC; + Result = Status.getSize(); + return error_code::success(); +} + error_code setLastModificationAndAccessTime(int FD, TimeValue Time); /// @brief Is status available? diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 83879ff..484296c 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -556,28 +556,24 @@ error_code status(const Twine &path, file_status &result) { } perms prms = static_cast(status.st_mode); - + file_type Type = file_type::type_unknown; + if (S_ISDIR(status.st_mode)) - result = file_status(file_type::directory_file, prms); + Type = file_type::directory_file; else if (S_ISREG(status.st_mode)) - result = file_status(file_type::regular_file, prms); + Type = file_type::regular_file; else if (S_ISBLK(status.st_mode)) - result = file_status(file_type::block_file, prms); + Type = file_type::block_file; else if (S_ISCHR(status.st_mode)) - result = file_status(file_type::character_file, prms); + Type = file_type::character_file; else if (S_ISFIFO(status.st_mode)) - result = file_status(file_type::fifo_file, prms); + Type = file_type::fifo_file; else if (S_ISSOCK(status.st_mode)) - result = file_status(file_type::socket_file, prms); - else - result = file_status(file_type::type_unknown, prms); - - result.fs_st_dev = status.st_dev; - result.fs_st_ino = status.st_ino; - result.fs_st_mtime = status.st_mtime; - result.fs_st_uid = status.st_uid; - result.fs_st_gid = status.st_gid; - result.fs_st_size = status.st_size; + Type = file_type::socket_file; + + result = + file_status(Type, prms, status.st_dev, status.st_ino, status.st_mtime, + status.st_uid, status.st_gid, status.st_size); return error_code::success(); } diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index b023593..1ecd803 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -632,7 +632,6 @@ error_code status(const Twine &path, file_status &result) { if (attr & FILE_ATTRIBUTE_DIRECTORY) result = file_status(file_type::directory_file); else { - result = file_status(file_type::regular_file); ScopedFileHandle h( ::CreateFileW(path_utf16.begin(), 0, // Attributes only. @@ -646,15 +645,13 @@ error_code status(const Twine &path, file_status &result) { BY_HANDLE_FILE_INFORMATION Info; if (!::GetFileInformationByHandle(h, &Info)) goto handle_status_error; - result.FileIndexHigh = Info.nFileIndexHigh; - result.FileIndexLow = Info.nFileIndexLow; - result.FileSizeHigh = Info.nFileSizeHigh; - result.FileSizeLow = Info.nFileSizeLow; - result.LastWriteTimeHigh = Info.ftLastWriteTime.dwHighDateTime; - result.LastWriteTimeLow = Info.ftLastWriteTime.dwLowDateTime; - result.VolumeSerialNumber = Info.dwVolumeSerialNumber; - } + result = file_status( + file_type::regular_file, Info.ftLastWriteTime.dwHighDateTime, + Info.ftLastWriteTime.dwLowDateTime, Info.dwVolumeSerialNumber, + Info.nFileSizeHigh, Info.nFileSizeLow, Info.nFileIndexHigh, + Info.nFileIndexLow); + } return error_code::success(); handle_status_error: -- 2.7.4