aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Unix
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-28 22:03:44 +0000
committerChris Lattner <sabre@nondot.org>2006-07-28 22:03:44 +0000
commit252ad03d7db0add504fdcc6bd67c1bc1e28bdd57 (patch)
treeb53953cdbf21813671a66e76191e4bd39c4bf6e7 /lib/System/Unix
parent3236ced25f152ca3035b335008056cd91af5f8bf (diff)
downloadexternal_llvm-252ad03d7db0add504fdcc6bd67c1bc1e28bdd57.zip
external_llvm-252ad03d7db0add504fdcc6bd67c1bc1e28bdd57.tar.gz
external_llvm-252ad03d7db0add504fdcc6bd67c1bc1e28bdd57.tar.bz2
Change Path::getStatusInfo to return a boolean and error string on an error
instead of throwing an exception. This reduces the amount of code that is exposed to exceptions (e.g. FileUtilities), though it is clearly only one step along the way. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29395 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r--lib/System/Unix/Path.inc30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 4ca4753..a0d76b0 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -386,21 +386,22 @@ Path::getLast() const {
return path.substr(pos+1);
}
-void
-Path::getStatusInfo(StatusInfo& info) const {
+bool
+Path::getFileStatus(FileStatus &info, std::string *ErrStr) const {
struct stat buf;
- if (0 != stat(path.c_str(), &buf)) {
- ThrowErrno(path + ": can't determine type of path object: ");
- }
+ if (0 != stat(path.c_str(), &buf))
+ return GetErrno(path + ": can't determine type of path object: ", ErrStr);
info.fileSize = buf.st_size;
info.modTime.fromEpochTime(buf.st_mtime);
info.mode = buf.st_mode;
info.user = buf.st_uid;
info.group = buf.st_gid;
- info.isDir = S_ISDIR(buf.st_mode);
+ info.isDir = S_ISDIR(buf.st_mode);
+ info.isFile = S_ISREG(buf.st_mode);
+ return false;
}
-static bool AddPermissionBits(const std::string& Filename, int bits) {
+static bool AddPermissionBits(const Path &File, int bits) {
// Get the umask value from the operating system. We want to use it
// when changing the file's permissions. Since calling umask() sets
// the umask and returns its old value, we must call it a second
@@ -409,30 +410,29 @@ static bool AddPermissionBits(const std::string& Filename, int bits) {
umask(mask); // Restore the umask.
// Get the file's current mode.
- struct stat st;
- if ((stat(Filename.c_str(), &st)) == -1)
- return false;
+ FileStatus Stat;
+ if (File.getFileStatus(Stat)) return false;
// Change the file to have whichever permissions bits from 'bits'
// that the umask would not disable.
- if ((chmod(Filename.c_str(), (st.st_mode | (bits & ~mask)))) == -1)
+ if ((chmod(File.c_str(), (Stat.getMode() | (bits & ~mask)))) == -1)
return false;
return true;
}
void Path::makeReadableOnDisk() {
- if (!AddPermissionBits(path,0444))
+ if (!AddPermissionBits(*this, 0444))
ThrowErrno(path + ": can't make file readable");
}
void Path::makeWriteableOnDisk() {
- if (!AddPermissionBits(path,0222))
+ if (!AddPermissionBits(*this, 0222))
ThrowErrno(path + ": can't make file writable");
}
void Path::makeExecutableOnDisk() {
- if (!AddPermissionBits(path,0111))
+ if (!AddPermissionBits(*this, 0111))
ThrowErrno(path + ": can't make file executable");
}
@@ -642,7 +642,7 @@ Path::renamePathOnDisk(const Path& newName) {
}
bool
-Path::setStatusInfoOnDisk(const StatusInfo& si) const {
+Path::setStatusInfoOnDisk(const FileStatus &si) const {
struct utimbuf utb;
utb.actime = si.modTime.toPosixTime();
utb.modtime = utb.actime;