aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Archive/Archive.cpp6
-rw-r--r--lib/Archive/ArchiveWriter.cpp4
-rw-r--r--lib/Bytecode/Archive/Archive.cpp6
-rw-r--r--lib/Bytecode/Archive/ArchiveWriter.cpp4
-rw-r--r--lib/Debugger/ProgramInfo.cpp5
-rw-r--r--lib/Support/FileUtilities.cpp28
-rw-r--r--lib/System/Unix/Path.inc30
7 files changed, 48 insertions, 35 deletions
diff --git a/lib/Archive/Archive.cpp b/lib/Archive/Archive.cpp
index 66b9d703a0..3bb9a05508 100644
--- a/lib/Archive/Archive.cpp
+++ b/lib/Archive/Archive.cpp
@@ -104,12 +104,14 @@ void ArchiveMember::replaceWith(const sys::Path& newFile) {
flags &= ~HasLongFilenameFlag;
// Get the signature and status info
- std::string magic;
const char* signature = (const char*) data;
+ std::string magic;
if (!signature) {
path.getMagicNumber(magic,4);
signature = magic.c_str();
- path.getStatusInfo(info);
+ std::string err;
+ if (path.getFileStatus(info, &err))
+ throw err;
}
// Determine what kind of file it is
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index 390fd12851..52ba99e805 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -159,7 +159,9 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where) {
mbr->data = 0;
mbr->path = filePath;
- mbr->path.getStatusInfo(mbr->info);
+ std::string err;
+ if (mbr->path.getFileStatus(mbr->info, &err))
+ throw err;
unsigned flags = 0;
bool hasSlash = filePath.toString().find('/') != std::string::npos;
diff --git a/lib/Bytecode/Archive/Archive.cpp b/lib/Bytecode/Archive/Archive.cpp
index 66b9d703a0..3bb9a05508 100644
--- a/lib/Bytecode/Archive/Archive.cpp
+++ b/lib/Bytecode/Archive/Archive.cpp
@@ -104,12 +104,14 @@ void ArchiveMember::replaceWith(const sys::Path& newFile) {
flags &= ~HasLongFilenameFlag;
// Get the signature and status info
- std::string magic;
const char* signature = (const char*) data;
+ std::string magic;
if (!signature) {
path.getMagicNumber(magic,4);
signature = magic.c_str();
- path.getStatusInfo(info);
+ std::string err;
+ if (path.getFileStatus(info, &err))
+ throw err;
}
// Determine what kind of file it is
diff --git a/lib/Bytecode/Archive/ArchiveWriter.cpp b/lib/Bytecode/Archive/ArchiveWriter.cpp
index 390fd12851..52ba99e805 100644
--- a/lib/Bytecode/Archive/ArchiveWriter.cpp
+++ b/lib/Bytecode/Archive/ArchiveWriter.cpp
@@ -159,7 +159,9 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where) {
mbr->data = 0;
mbr->path = filePath;
- mbr->path.getStatusInfo(mbr->info);
+ std::string err;
+ if (mbr->path.getFileStatus(mbr->info, &err))
+ throw err;
unsigned flags = 0;
bool hasSlash = filePath.toString().find('/') != std::string::npos;
diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp
index 66d38f73ca..b60f5fc4bc 100644
--- a/lib/Debugger/ProgramInfo.cpp
+++ b/lib/Debugger/ProgramInfo.cpp
@@ -196,8 +196,9 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo,
ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) {
assert(M && "Cannot create program information with a null module!");
- sys::Path modulePath(M->getModuleIdentifier());
- ProgramTimeStamp = modulePath.getTimestamp();
+ sys::FileStatus Stat;
+ if (!sys::Path(M->getModuleIdentifier()).getFileStatus(Stat))
+ ProgramTimeStamp = Stat.getTimestamp();
SourceFilesIsComplete = false;
SourceFunctionsIsComplete = false;
diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp
index a7f42ddebf..d4608ccb65 100644
--- a/lib/Support/FileUtilities.cpp
+++ b/lib/Support/FileUtilities.cpp
@@ -146,19 +146,23 @@ int llvm::DiffFilesWithTolerance(const sys::Path &FileA,
const sys::Path &FileB,
double AbsTol, double RelTol,
std::string *Error) {
- try {
- // Check for zero length files because some systems croak when you try to
- // mmap an empty file.
- size_t A_size = FileA.getSize();
- size_t B_size = FileB.getSize();
-
- // If they are both zero sized then they're the same
- if (A_size == 0 && B_size == 0)
- return 0;
- // If only one of them is zero sized then they can't be the same
- if ((A_size == 0 || B_size == 0))
- return 1;
+ sys::FileStatus FileAStat, FileBStat;
+ if (FileA.getFileStatus(FileAStat, Error) ||
+ FileB.getFileStatus(FileBStat, Error))
+ return 2;
+ // Check for zero length files because some systems croak when you try to
+ // mmap an empty file.
+ size_t A_size = FileAStat.getSize();
+ size_t B_size = FileBStat.getSize();
+
+ // If they are both zero sized then they're the same
+ if (A_size == 0 && B_size == 0)
+ return 0;
+ // If only one of them is zero sized then they can't be the same
+ if ((A_size == 0 || B_size == 0))
+ return 1;
+ try {
// Now its safe to mmap the files into memory becasue both files
// have a non-zero size.
sys::MappedFile F1(FileA);
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 4ca4753962..a0d76b032b 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;