diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2005-07-08 03:08:58 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2005-07-08 03:08:58 +0000 |
commit | a229c5cce75209047db32c6039aa0b0fd481f049 (patch) | |
tree | 7e69ee21a80ed018e52af9071602c3db887b8326 /lib | |
parent | edb9d6bc720bb2328bb49f4400bf8d6b3b04ef50 (diff) |
Final Changes For PR495:
This chagne just renames some sys::Path methods to ensure they are not
misused. The Path documentation now divides methods into two dimensions:
Path/Disk and accessor/mutator. Path accessors and mutators only operate
on the Path object itself without making any disk accesses. Disk accessors
and mutators will also access or modify the file system. Because of the
potentially destructive nature of disk mutators, it was decided that all
such methods should end in the work "Disk" to ensure the user recognizes
that the change will occur on the file system. This patch makes that
change. The method name changes are:
makeReadable -> makeReadableOnDisk
makeWriteable -> makeWriteableOnDisk
makeExecutable -> makeExecutableOnDisk
setStatusInfo -> setStatusInfoOnDisk
createDirectory -> createDirectoryOnDisk
createFile -> createFileOnDisk
createTemporaryFile -> createTemporaryFileOnDisk
destroy -> eraseFromDisk
rename -> renamePathOnDisk
These changes pass the Linux Deja Gnu tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Archive/ArchiveWriter.cpp | 8 | ||||
-rw-r--r-- | lib/Bytecode/Archive/ArchiveWriter.cpp | 8 | ||||
-rw-r--r-- | lib/Support/ToolRunner.cpp | 6 | ||||
-rw-r--r-- | lib/System/Unix/Path.inc | 27 | ||||
-rw-r--r-- | lib/System/Unix/Signals.inc | 2 | ||||
-rw-r--r-- | lib/System/Win32/Path.inc | 31 |
6 files changed, 49 insertions, 33 deletions
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp index 1318471530..3517dc7453 100644 --- a/lib/Archive/ArchiveWriter.cpp +++ b/lib/Archive/ArchiveWriter.cpp @@ -374,7 +374,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){ // Create a temporary file to store the archive in sys::Path TmpArchive = archPath; - TmpArchive.createTemporaryFile(); + TmpArchive.createTemporaryFileOnDisk(); // Make sure the temporary gets removed if we crash sys::RemoveFileOnSignal(TmpArchive); @@ -450,17 +450,17 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){ // Close up shop FinalFile.close(); arch.close(); - TmpArchive.destroy(); + TmpArchive.eraseFromDisk(); } else { // We don't have to insert the symbol table, so just renaming the temp // file to the correct name will suffice. - TmpArchive.rename(archPath); + TmpArchive.renamePathOnDisk(archPath); } } catch (...) { // Make sure we clean up. if (TmpArchive.exists()) - TmpArchive.destroy(); + TmpArchive.eraseFromDisk(); throw; } } diff --git a/lib/Bytecode/Archive/ArchiveWriter.cpp b/lib/Bytecode/Archive/ArchiveWriter.cpp index 1318471530..3517dc7453 100644 --- a/lib/Bytecode/Archive/ArchiveWriter.cpp +++ b/lib/Bytecode/Archive/ArchiveWriter.cpp @@ -374,7 +374,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){ // Create a temporary file to store the archive in sys::Path TmpArchive = archPath; - TmpArchive.createTemporaryFile(); + TmpArchive.createTemporaryFileOnDisk(); // Make sure the temporary gets removed if we crash sys::RemoveFileOnSignal(TmpArchive); @@ -450,17 +450,17 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){ // Close up shop FinalFile.close(); arch.close(); - TmpArchive.destroy(); + TmpArchive.eraseFromDisk(); } else { // We don't have to insert the symbol table, so just renaming the temp // file to the correct name will suffice. - TmpArchive.rename(archPath); + TmpArchive.renamePathOnDisk(archPath); } } catch (...) { // Make sure we clean up. if (TmpArchive.exists()) - TmpArchive.destroy(); + TmpArchive.eraseFromDisk(); throw; } } diff --git a/lib/Support/ToolRunner.cpp b/lib/Support/ToolRunner.cpp index 3cea3386db..f516986f13 100644 --- a/lib/Support/ToolRunner.cpp +++ b/lib/Support/ToolRunner.cpp @@ -65,7 +65,7 @@ static void ProcessFailure(sys::Path ProgPath, const char** Args) { ErrorFile.close(); } - ErrorFilename.destroy(); + ErrorFilename.eraseFromDisk(); throw ToolExecutionError(OS.str()); } @@ -176,7 +176,7 @@ void LLC::OutputAsm(const std::string &Bytecode, sys::Path &OutputAsmFile) { void LLC::compileProgram(const std::string &Bytecode) { sys::Path OutputAsmFile; OutputAsm(Bytecode, OutputAsmFile); - OutputAsmFile.destroy(); + OutputAsmFile.eraseFromDisk(); } int LLC::ExecuteProgram(const std::string &Bytecode, @@ -321,7 +321,7 @@ void CBE::OutputC(const std::string &Bytecode, sys::Path& OutputCFile) { void CBE::compileProgram(const std::string &Bytecode) { sys::Path OutputCFile; OutputC(Bytecode, OutputCFile); - OutputCFile.destroy(); + OutputCFile.eraseFromDisk(); } int CBE::ExecuteProgram(const std::string &Bytecode, diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index ffcd6949b5..7ced25ab8d 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -246,6 +246,15 @@ Path::isDirectory() const { return S_ISDIR(buf.st_mode); } +bool +Path::isHidden() const { + size_t slash = path.rfind('/'); + return (slash != std::string::npos && + slash < path.length()-1 && + path[slash+1] == '.') || + (!path.empty() && slash == std::string::npos && path[0] == '.'); +} + std::string Path::getBasename() const { // Find the last slash @@ -388,17 +397,17 @@ static bool AddPermissionBits(const std::string& Filename, int bits) { return true; } -void Path::makeReadable() { +void Path::makeReadableOnDisk() { if (!AddPermissionBits(path,0444)) ThrowErrno(path + ": can't make file readable"); } -void Path::makeWriteable() { +void Path::makeWriteableOnDisk() { if (!AddPermissionBits(path,0222)) ThrowErrno(path + ": can't make file writable"); } -void Path::makeExecutable() { +void Path::makeExecutableOnDisk() { if (!AddPermissionBits(path,0111)) ThrowErrno(path + ": can't make file executable"); } @@ -511,7 +520,7 @@ Path::eraseSuffix() { } bool -Path::createDirectory( bool create_parents) { +Path::createDirectoryOnDisk( bool create_parents) { // Get a writeable copy of the path name char pathname[MAXPATHLEN]; path.copy(pathname,MAXPATHLEN); @@ -549,7 +558,7 @@ Path::createDirectory( bool create_parents) { } bool -Path::createFile() { +Path::createFileOnDisk() { // Create the file int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR); if (fd < 0) @@ -560,7 +569,7 @@ Path::createFile() { } bool -Path::createTemporaryFile(bool reuse_current) { +Path::createTemporaryFileOnDisk(bool reuse_current) { // Make this into a unique file name makeUnique( reuse_current ); @@ -574,7 +583,7 @@ Path::createTemporaryFile(bool reuse_current) { } bool -Path::destroy(bool remove_contents) const { +Path::eraseFromDisk(bool remove_contents) const { // Make sure we're dealing with a directory if (isFile()) { if (0 != unlink(path.c_str())) @@ -604,7 +613,7 @@ Path::destroy(bool remove_contents) const { } bool -Path::rename(const Path& newName) { +Path::renamePathOnDisk(const Path& newName) { if (0 != ::rename(path.c_str(), newName.c_str())) ThrowErrno(std::string("can't rename '") + path + "' as '" + newName.toString() + "' "); @@ -612,7 +621,7 @@ Path::rename(const Path& newName) { } bool -Path::setStatusInfo(const StatusInfo& si) const { +Path::setStatusInfoOnDisk(const StatusInfo& si) const { struct utimbuf utb; utb.actime = si.modTime.toPosixTime(); utb.modtime = utb.actime; diff --git a/lib/System/Unix/Signals.inc b/lib/System/Unix/Signals.inc index ce5b94b947..a9af969d5b 100644 --- a/lib/System/Unix/Signals.inc +++ b/lib/System/Unix/Signals.inc @@ -112,7 +112,7 @@ RETSIGTYPE SignalHandler(int Sig) { if (DirectoriesToRemove != 0) while (!DirectoriesToRemove->empty()) { - DirectoriesToRemove->back().destroy(true); + DirectoriesToRemove->back().eraseFromDisk(true); DirectoriesToRemove->pop_back(); } diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 9e7010a439..252347e087 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -103,10 +103,10 @@ Path::GetTemporaryDirectory() { // If there's a directory left over from a previous LLVM execution that // happened to have the same process id, get rid of it. - result.destroy(true); + result.eraseFromDisk(true); // And finally (re-)create the empty directory. - result.createDirectory(false); + result.createDirectoryOnDisk(false); TempDirectory = new Path(result); return *TempDirectory; } @@ -206,6 +206,13 @@ Path::isDirectory() const { return fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; } +bool +Path::isHidden() const { + // FIXME: implement this correctly for Win32. It should check the hidden file + // attribute. + return false; +} + std::string Path::getBasename() const { // Find the last slash @@ -322,11 +329,11 @@ static bool AddPermissionBits(const std::string& Filename, int bits) { return true; } -void Path::makeReadable() { +void Path::makeReadableOnDisk() { // All files are readable on Windows (ignoring security attributes). } -void Path::makeWriteable() { +void Path::makeWriteableOnDisk() { DWORD attr = GetFileAttributes(path.c_str()); // If it doesn't exist, we're done. @@ -339,7 +346,7 @@ void Path::makeWriteable() { } } -void Path::makeExecutable() { +void Path::makeExecutableOnDisk() { // All files are executable on Windows (ignoring security attributes). } @@ -447,7 +454,7 @@ Path::eraseSuffix() { } bool -Path::createDirectory( bool create_parents) { +Path::createDirectoryOnDisk( bool create_parents) { // Get a writeable copy of the path name char *pathname = reinterpret_cast<char *>(_alloca(path.length()+1)); path.copy(pathname,path.length()); @@ -495,7 +502,7 @@ Path::createDirectory( bool create_parents) { } bool -Path::createFile() { +Path::createFileOnDisk() { // Create the file HANDLE h = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); @@ -507,7 +514,7 @@ Path::createFile() { } bool -Path::destroy(bool remove_contents) const { +Path::eraseFromDisk(bool remove_contents) const { if (isFile()) { DWORD attr = GetFileAttributes(path.c_str()); @@ -571,7 +578,7 @@ Path::destroy(bool remove_contents) const { for (std::vector<Path>::iterator I = list.begin(); I != list.end(); ++I) { Path &aPath = *I; - aPath.destroy(true); + aPath.eraseFromDisk(true); } } else { if (GetLastError() != ERROR_FILE_NOT_FOUND) @@ -615,7 +622,7 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const { } bool -Path::rename(const Path& newName) { +Path::renamePathOnDisk(const Path& newName) { // FIXME: This should rename a directory too. if (!isFile()) return false; if (!MoveFile(path.c_str(), newName.c_str())) @@ -625,7 +632,7 @@ Path::rename(const Path& newName) { } bool -Path::setStatusInfo(const StatusInfo& si) const { +Path::setStatusInfoOnDisk(const StatusInfo& si) const { if (!isFile()) return false; HANDLE h = CreateFile(path.c_str(), @@ -705,7 +712,7 @@ Path::makeUnique(bool reuse_current) { } bool -Path::createTemporaryFile(bool reuse_current) { +Path::createTemporaryFileOnDisk(bool reuse_current) { // Make this into a unique file name makeUnique( reuse_current ); |