Modify setStatusInfoOnDisk to not throw an exception.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29402 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-07-28 22:36:17 +00:00
parent 7dea1019c1
commit 1bebfb5ae4
3 changed files with 15 additions and 14 deletions

View File

@ -461,9 +461,10 @@ namespace sys {
/// This method allows the last modified time stamp and permission bits /// This method allows the last modified time stamp and permission bits
/// to be set on the disk object referenced by the Path. /// to be set on the disk object referenced by the Path.
/// @throws std::string if an error occurs. /// @throws std::string if an error occurs.
/// @returns true /// @returns true on error.
/// @brief Set the status information. /// @brief Set the status information.
bool setStatusInfoOnDisk(const FileStatus &SI) const; bool setStatusInfoOnDisk(const FileStatus &SI,
std::string *ErrStr = 0) const;
/// This method attempts to create a directory in the file system with the /// This method attempts to create a directory in the file system with the
/// same name as the Path object. The \p create_parents parameter controls /// same name as the Path object. The \p create_parents parameter controls

View File

@ -647,15 +647,15 @@ Path::renamePathOnDisk(const Path& newName) {
} }
bool bool
Path::setStatusInfoOnDisk(const FileStatus &si) const { Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrStr) const {
struct utimbuf utb; struct utimbuf utb;
utb.actime = si.modTime.toPosixTime(); utb.actime = si.modTime.toPosixTime();
utb.modtime = utb.actime; utb.modtime = utb.actime;
if (0 != ::utime(path.c_str(),&utb)) if (0 != ::utime(path.c_str(),&utb))
ThrowErrno(path + ": can't set file modification time"); return GetErrno(path + ": can't set file modification time", ErrStr);
if (0 != ::chmod(path.c_str(),si.mode)) if (0 != ::chmod(path.c_str(),si.mode))
ThrowErrno(path + ": can't set mode"); return GetErrno(path + ": can't set mode", ErrStr);
return true; return false;
} }
void void

View File

@ -693,9 +693,9 @@ Path::renamePathOnDisk(const Path& newName) {
} }
bool bool
Path::setStatusInfoOnDisk(const FileStatus &si) const { Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrStr) const {
// FIXME: should work on directories also. // FIXME: should work on directories also.
if (!isFile()) return false; if (!isFile()) return true;
HANDLE h = CreateFile(path.c_str(), HANDLE h = CreateFile(path.c_str(),
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
@ -705,14 +705,14 @@ Path::setStatusInfoOnDisk(const FileStatus &si) const {
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
return false; return true;
BY_HANDLE_FILE_INFORMATION bhfi; BY_HANDLE_FILE_INFORMATION bhfi;
if (!GetFileInformationByHandle(h, &bhfi)) { if (!GetFileInformationByHandle(h, &bhfi)) {
DWORD err = GetLastError(); DWORD err = GetLastError();
CloseHandle(h); CloseHandle(h);
SetLastError(err); SetLastError(err);
ThrowError(path + ": GetFileInformationByHandle: "); return GetError(path + ": GetFileInformationByHandle: ", ErrStr);
} }
FILETIME ft; FILETIME ft;
@ -722,7 +722,7 @@ Path::setStatusInfoOnDisk(const FileStatus &si) const {
CloseHandle(h); CloseHandle(h);
if (!ret) { if (!ret) {
SetLastError(err); SetLastError(err);
ThrowError(path + ": SetFileTime: "); return GetError(path + ": SetFileTime: ", ErrStr);
} }
// Best we can do with Unix permission bits is to interpret the owner // Best we can do with Unix permission bits is to interpret the owner
@ -731,17 +731,17 @@ Path::setStatusInfoOnDisk(const FileStatus &si) const {
if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
if (!SetFileAttributes(path.c_str(), if (!SetFileAttributes(path.c_str(),
bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
ThrowError(path + ": SetFileAttributes: "); return GetError(path + ": SetFileAttributes: ", ErrStr);
} }
} else { } else {
if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) { if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
if (!SetFileAttributes(path.c_str(), if (!SetFileAttributes(path.c_str(),
bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY)) bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY))
ThrowError(path + ": SetFileAttributes: "); return GetError(path + ": SetFileAttributes: ", ErrStr);
} }
} }
return true; return false;
} }
void void