aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-07-07 23:21:43 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-07-07 23:21:43 +0000
commitdd04df0ec33a903ee7fc747701bafde622f77d8b (patch)
tree341d4fd4ba6e81cb79966ef2c379ccbb2d8b5100
parentb3d59701c89a6e03a0e0909543f3e7bd9140900f (diff)
For PR495:
Get rid of the difference between file paths and directory paths. The Path class now simply stores a path that can refer to either a file or a directory. This required various changes in the implementation and interface of the class with the corresponding impact to its users. Doxygen comments were also updated to reflect these changes. Interface changes are: appendDirectory -> appendComponent appendFile -> appendComponent elideDirectory -> eraseComponent elideFile -> eraseComponent elideSuffix -> eraseSuffix renameFile -> rename setDirectory -> set setFile -> set Changes pass Dejagnu and llvm-test/SingleSource tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22349 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/FileUtilities.h2
-rw-r--r--include/llvm/System/Path.h152
-rw-r--r--lib/Archive/ArchiveReader.cpp2
-rw-r--r--lib/Archive/ArchiveWriter.cpp6
-rw-r--r--lib/Bytecode/Archive/ArchiveReader.cpp2
-rw-r--r--lib/Bytecode/Archive/ArchiveWriter.cpp6
-rw-r--r--lib/Debugger/ProgramInfo.cpp4
-rw-r--r--lib/Linker/LinkModules.cpp2
-rw-r--r--lib/Linker/Linker.cpp42
-rw-r--r--lib/Support/SystemUtils.cpp4
-rw-r--r--lib/Support/ToolRunner.cpp6
-rw-r--r--lib/System/Path.cpp6
-rw-r--r--lib/System/Unix/Path.inc209
-rw-r--r--lib/System/Unix/Program.inc6
-rw-r--r--lib/System/Unix/Signals.inc2
-rw-r--r--lib/System/Win32/Path.inc10
-rw-r--r--tools/bugpoint/CrashDebugger.cpp4
-rw-r--r--tools/bugpoint/ExecutionDriver.cpp11
-rw-r--r--tools/bugpoint/Miscompilation.cpp10
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp4
-rw-r--r--tools/bugpoint/ToolRunner.cpp6
-rw-r--r--tools/gccld/GenerateCode.cpp14
-rw-r--r--tools/gccld/gccld.cpp8
-rw-r--r--tools/llvm-ar/llvm-ar.cpp6
-rw-r--r--tools/llvm-ld/llvm-ld.cpp4
-rw-r--r--tools/llvm-link/llvm-link.cpp2
-rw-r--r--tools/llvm-ranlib/llvm-ranlib.cpp2
-rw-r--r--tools/llvmc/CompilerDriver.cpp30
-rw-r--r--tools/llvmc/Configuration.cpp18
29 files changed, 249 insertions, 331 deletions
diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h
index 6712c32576..6e80112478 100644
--- a/include/llvm/Support/FileUtilities.h
+++ b/include/llvm/Support/FileUtilities.h
@@ -45,7 +45,7 @@ namespace llvm {
~FileRemover() {
if (DeleteIt)
try {
- Filename.destroyFile();
+ Filename.destroy();
} catch (...) {} // Ignore problems deleting the file.
}
diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h
index 04c0a2b3d2..e99ad47f1b 100644
--- a/include/llvm/System/Path.h
+++ b/include/llvm/System/Path.h
@@ -219,24 +219,22 @@ namespace sys {
bool isValid() const;
/// This function determines if the contents of the path name are
- /// empty. That is, the path has a zero length.
+ /// empty. That is, the path has a zero length. This does NOT determine if
+ /// if the file is empty. Use the getSize method for that.
/// @returns true iff the path is empty.
/// @brief Determines if the path name is empty (invalid).
bool isEmpty() const { return path.empty(); }
- /// This function determines if the path name in this object is intended
- /// to reference a legal file name (as opposed to a directory name). This
- /// function does not verify anything with the file system, it merely
- /// determines if the syntax of the path represents a file name or not.
+ /// This function determines if the object referenced by this path is
+ /// a file or not. This function accesses the under lying file system to
+ /// determine the type of entity referenced by the path.
/// @returns true if this path name references a file.
/// @brief Determines if the path name references a file.
bool isFile() const;
- /// This function determines if the path name in this object is intended
- /// to reference a legal directory name (as opposed to a file name). This
- /// function does not verify anything with the file system, it merely
- /// determines if the syntax of the path represents a directory name or
- /// not.
+ /// This function determines if the object referenced by this path is a
+ /// directory or not. This function accesses the underlying file system to
+ /// determine the type of entity referenced by the path.
/// @returns true if the path name references a directory
/// @brief Determines if the path name references a directory.
bool isDirectory() const;
@@ -297,35 +295,34 @@ namespace sys {
bool isDynamicLibrary() const;
/// This function determines if the path name references an existing file
- /// or directory in the file system. Unlike isFile and isDirectory, this
- /// function actually checks for the existence of the file or directory.
- /// @returns true if the pathname references an existing file.
+ /// or directory in the file system.
+ /// @returns true if the pathname references an existing file or
+ /// directory.
/// @brief Determines if the path is a file or directory in
/// the file system.
bool exists() const;
/// This function determines if the path name references a readable file
- /// or directory in the file system. Unlike isFile and isDirectory, this
- /// function actually checks for the existence and readability (by the
- /// current program) of the file or directory.
+ /// or directory in the file system. This function checks for
+ /// the existence and readability (by the current program) of the file
+ /// or directory.
/// @returns true if the pathname references a readable file.
/// @brief Determines if the path is a readable file or directory
/// in the file system.
bool canRead() const;
/// This function determines if the path name references a writable file
- /// or directory in the file system. Unlike isFile and isDirectory, this
- /// function actually checks for the existence and writability (by the
- /// current program) of the file or directory.
+ /// or directory in the file system. This function checks for the
+ /// existence and writability (by the current program) of the file or
+ /// directory.
/// @returns true if the pathname references a writable file.
/// @brief Determines if the path is a writable file or directory
/// in the file system.
bool canWrite() const;
/// This function determines if the path name references an executable
- /// file in the file system. Unlike isFile and isDirectory, this
- /// function actually checks for the existence and executability (by
- /// the current program) of the file.
+ /// file in the file system. This function checks for the existence and
+ /// executability (by the current program) of the file.
/// @returns true if the pathname references an executable file.
/// @brief Determines if the path is an executable file in the file
/// system.
@@ -338,17 +335,16 @@ namespace sys {
/// @brief Returns the path as a std::string.
const std::string& toString() const { return path; }
- /// This function returns the last component of the path name. If the
- /// isDirectory() function would return true then this returns the name
- /// of the last directory in the path. If the isFile() function would
- /// return true then this function returns the name of the file without
- /// any of the preceding directories.
+ /// This function returns the last component of the path name. The last
+ /// component is the file or directory name occuring after the last
+ /// directory separator.
/// @returns std::string containing the last component of the path name.
/// @brief Returns the last component of the path name.
std::string getLast() const;
- /// This function strips off the path and suffix of the file name and
- /// returns just the basename.
+ /// This function strips off the path and suffix of the file or directory
+ /// name and returns just the basename. For example /a/foo.bar would cause
+ /// this function to return "foo".
/// @returns std::string containing the basename of the path
/// @throws nothing
/// @brief Get the base name of the path
@@ -361,26 +357,20 @@ namespace sys {
/// @brief Build a list of directory's contents.
bool getDirectoryContents(std::set<Path>& paths) const;
- /// This method attempts to destroy the directory named by the last in
- /// the Path name. If \p remove_contents is false, an attempt will be
- /// made to remove just the directory that this Path object refers to
- /// (the final Path component). If \p remove_contents is true, an attempt
- /// will be made to remove the entire contents of the directory,
- /// recursively.
+ /// This method attempts to destroy the file or directory named by the
+ /// last component of the Path. If the Path refers to a directory and the
+ /// \p destroy_contents is false, an attempt will be made to remove just
+ /// the directory (the final Path component). If \p destroy_contents is
+ /// true, an attempt will be made to remove the entire contents of the
+ /// directory, recursively. If the Path refers to a file, the
+ /// \p destroy_contents parameter is ignored.
/// @param destroy_contents Indicates whether the contents of a destroyed
/// directory should also be destroyed (recursively).
- /// @returns false if the Path does not refer to a directory, true
- /// otherwise.
+ /// @returns true if the file/directory was destroyed, false if the path
+ /// refers to something that is neither a file nor a directory.
/// @throws std::string if there is an error.
/// @brief Removes the file or directory from the filesystem.
- bool destroyDirectory( bool destroy_contents = false ) const;
-
- /// This method attempts to destroy the file named by the last item in the
- /// Path name.
- /// @returns false if the Path does not refer to a file, true otherwise.
- /// @throws std::string if there is an error.
- /// @brief Destroy the file this Path refers to.
- bool destroyFile() const;
+ bool destroy( bool destroy_contents = false ) const;
/// Obtain a 'C' string for the path name.
/// @returns a 'C' string containing the path name.
@@ -437,64 +427,32 @@ namespace sys {
/// @brief Make the file readable;
void makeExecutable();
- /// This method attempts to set the Path object to \p unverified_path
- /// and interpret the name as a directory name. The \p unverified_path
- /// is verified. If verification succeeds then \p unverified_path
- /// is accepted as a directory and true is returned. Otherwise,
- /// the Path object remains unchanged and false is returned.
- /// @returns true if the path was set, false otherwise.
- /// @param unverified_path The path to be set in Path object.
- /// @throws nothing
- /// @brief Set a full path from a std::string
- bool setDirectory(const std::string& unverified_path);
-
- /// This method attempts to set the Path object to \p unverified_path
- /// and interpret the name as a file name. The \p unverified_path
- /// is verified. If verification succeeds then \p unverified_path
- /// is accepted as a file name and true is returned. Otherwise,
- /// the Path object remains unchanged and false is returned.
+ /// This method sets the Path object to \p unverified_path. This can fail
+ /// if the \p unverified_path does not pass the syntactic checks of the
+ /// isValid method. If verification fails, the Path object remains
+ /// unchanged and false is returned. Otherwise true is returned and the
+ /// Path object takes on the path value of \p unverified_path
/// @returns true if the path was set, false otherwise.
/// @param unverified_path The path to be set in Path object.
/// @throws nothing
/// @brief Set a full path from a std::string
- bool setFile(const std::string& unverified_path);
-
- /// The \p dirname is added to the end of the Path if it is a legal
- /// directory name for the operating system. The precondition for this
- /// function is that the Path must reference a directory name (i.e.
- /// isDirectory() returns true).
- /// @param dirname A string providing the directory name to
- /// be added to the end of the path.
- /// @returns false if the directory name could not be added
- /// @throws nothing
- /// @brief Adds the name of a directory to a Path.
- bool appendDirectory( const std::string& dirname );
+ bool set(const std::string& unverified_path);
- /// One directory component is removed from the Path name. The Path must
- /// refer to a non-root directory name (i.e. isDirectory() returns true
- /// but isRootDirectory() returns false). Upon exit, the Path will
- /// refer to the directory above it.
+ /// One path component is removed from the Path. If only one component is
+ /// present in the path, the Path object becomes empty. If the Path object
+ /// is empty, no change is made.
/// @throws nothing
- /// @returns false if the directory name could not be removed.
+ /// @returns false if the path component could not be removed.
/// @brief Removes the last directory component of the Path.
- bool elideDirectory();
-
- /// The \p filename is added to the end of the Path if it is a legal
- /// directory name for the operating system. The precondition for this
- /// function is that the Path reference a directory name (i.e.
- /// isDirectory() returns true).
- /// @throws nothing
- /// @returns false if the file name could not be added.
- /// @brief Appends the name of a file.
- bool appendFile( const std::string& filename );
+ bool eraseComponent();
- /// One file component is removed from the Path name. The Path must
- /// refer to a file (i.e. isFile() returns true). Upon exit,
- /// the Path will refer to the directory above it.
+ /// The \p component is added to the end of the Path if it is a legal
+ /// name for the operating system. A directory separator will be added if
+ /// needed.
/// @throws nothing
- /// @returns false if the file name could not be removed
- /// @brief Removes the last file component of the path.
- bool elideFile();
+ /// @returns false if the path component could not be added.
+ /// @brief Appends one path component to the Path.
+ bool appendComponent( const std::string& component );
/// A period and the \p suffix are appended to the end of the pathname.
/// The precondition for this function is that the Path reference a file
@@ -506,7 +464,7 @@ namespace sys {
/// @brief Adds a period and the \p suffix to the end of the pathname.
bool appendSuffix(const std::string& suffix);
- /// The suffix of the filename is removed. The suffix begins with and
+ /// The suffix of the filename is erased. The suffix begins with and
/// includes the last . character in the filename after the last directory
/// separator and extends until the end of the name. If no . character is
/// after the last directory separator, then the file name is left
@@ -515,7 +473,7 @@ namespace sys {
/// @returns false if there was no suffix to remove, true otherwise.
/// @throws nothing
/// @brief Remove the suffix from a path name.
- bool elideSuffix();
+ bool eraseSuffix();
/// The current Path name is made unique in the file system. Upon return,
/// the Path will have been changed to make a unique file in the file
@@ -566,7 +524,7 @@ namespace sys {
/// @returns false if the Path does not refer to a file, true otherwise.
/// @throws std::string if there is an file system error.
/// @brief Rename one file as another.
- bool renameFile(const Path& newName);
+ bool rename(const Path& newName);
/// This method sets the access time, modification time, and permission
/// mode of the file associated with \p this as given by \p si.
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index 262f170c07..8d87a6777e 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -187,7 +187,7 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
member->next = 0;
member->prev = 0;
member->parent = this;
- member->path.setFile(pathname);
+ member->path.set(pathname);
member->info.fileSize = MemberSize;
member->info.modTime.fromEpochTime(atoi(Hdr->date));
unsigned int mode;
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index be80b973c7..1318471530 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -450,17 +450,17 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
// Close up shop
FinalFile.close();
arch.close();
- TmpArchive.destroyFile();
+ TmpArchive.destroy();
} else {
// We don't have to insert the symbol table, so just renaming the temp
// file to the correct name will suffice.
- TmpArchive.renameFile(archPath);
+ TmpArchive.rename(archPath);
}
} catch (...) {
// Make sure we clean up.
if (TmpArchive.exists())
- TmpArchive.destroyFile();
+ TmpArchive.destroy();
throw;
}
}
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index 262f170c07..8d87a6777e 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -187,7 +187,7 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
member->next = 0;
member->prev = 0;
member->parent = this;
- member->path.setFile(pathname);
+ member->path.set(pathname);
member->info.fileSize = MemberSize;
member->info.modTime.fromEpochTime(atoi(Hdr->date));
unsigned int mode;
diff --git a/lib/Bytecode/Archive/ArchiveWriter.cpp b/lib/Bytecode/Archive/ArchiveWriter.cpp
index be80b973c7..1318471530 100644
--- a/lib/Bytecode/Archive/ArchiveWriter.cpp
+++ b/lib/Bytecode/Archive/ArchiveWriter.cpp
@@ -450,17 +450,17 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
// Close up shop
FinalFile.close();
arch.close();
- TmpArchive.destroyFile();
+ TmpArchive.destroy();
} else {
// We don't have to insert the symbol table, so just renaming the temp
// file to the correct name will suffice.
- TmpArchive.renameFile(archPath);
+ TmpArchive.rename(archPath);
}
} catch (...) {
// Make sure we clean up.
if (TmpArchive.exists())
- TmpArchive.destroyFile();
+ TmpArchive.destroy();
throw;
}
}
diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp
index 144cfeb2b3..b55606bd64 100644
--- a/lib/Debugger/ProgramInfo.cpp
+++ b/lib/Debugger/ProgramInfo.cpp
@@ -172,8 +172,8 @@ SourceFile &SourceFileInfo::getSourceText() const {
if (SourceText == 0) { // Read the file in if we haven't already.
sys::Path tmpPath;
if (!Directory.empty())
- tmpPath.setDirectory(Directory);
- tmpPath.appendFile(BaseName);
+ tmpPath.set(Directory);
+ tmpPath.appendComponent(BaseName);
if (tmpPath.canRead())
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
else
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 23ba6ebf58..d20044fa3c 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -899,7 +899,7 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
// If the source library's module id is in the dependent library list of the
// destination library, remove it since that module is now linked in.
sys::Path modId;
- modId.setFile(Src->getModuleIdentifier());
+ modId.set(Src->getModuleIdentifier());
if (!modId.isEmpty())
Dest->removeLibrary(modId.getBasename());
diff --git a/lib/Linker/Linker.cpp b/lib/Linker/Linker.cpp
index 3371740393..c72f1b5aca 100644
--- a/lib/Linker/Linker.cpp
+++ b/lib/Linker/Linker.cpp
@@ -69,7 +69,6 @@ Linker::verbose(const std::string& message) {
void
Linker::addPath(const sys::Path& path) {
- assert(path.isDirectory() && "Can only insert directories into the path");
LibPaths.push_back(path);
}
@@ -77,7 +76,7 @@ void
Linker::addPaths(const std::vector<std::string>& paths) {
for (unsigned i = 0; i != paths.size(); ++i) {
sys::Path aPath;
- aPath.setDirectory(paths[i]);
+ aPath.set(paths[i]);
LibPaths.push_back(aPath);
}
}
@@ -118,26 +117,35 @@ Linker::LoadObject(const sys::Path &FN) {
static inline sys::Path IsLibrary(const std::string& Name,
const sys::Path& Directory) {
- assert(Directory.isDirectory() && "Need to specify a directory");
sys::Path FullPath(Directory);
- FullPath.appendFile("lib" + Name);
- FullPath.appendSuffix("a");
- if (FullPath.isArchive())
- return FullPath;
+ // Make sure the directory actually is a directory in the file system.
+ if (FullPath.isDirectory())
+ {
+ // Try the libX.a form
+ FullPath.appendComponent("lib" + Name);
+ FullPath.appendSuffix("a");
+ if (FullPath.isArchive())
+ return FullPath;
+
+ // Try the libX.bca form
+ FullPath.eraseSuffix();
+ FullPath.appendSuffix("bca");
+ if (FullPath.isArchive())
+ return FullPath;
- FullPath.elideSuffix();
- FullPath.appendSuffix("bca");
- if (FullPath.isArchive())
- return FullPath;
+ // Try the libX.so form
+ FullPath.eraseSuffix();
+ FullPath.appendSuffix(&(LTDL_SHLIB_EXT[1]));
+ if (FullPath.isDynamicLibrary()) // Native shared library?
+ return FullPath;
+ if (FullPath.isBytecodeFile()) // .so file containing bytecode?
+ return FullPath;
- FullPath.elideSuffix();
- FullPath.appendSuffix(&(LTDL_SHLIB_EXT[1]));
- if (FullPath.isDynamicLibrary()) // Native shared library?
- return FullPath;
- if (FullPath.isBytecodeFile()) // .so file containing bytecode?
- return FullPath;
+ // Not found .. fall through
+ }
+ // Indicate that the library was not found in the directory.
FullPath.clear();
return FullPath;
}
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index 77c97f3111..88c3515920 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -45,9 +45,9 @@ sys::Path llvm::FindExecutable(const std::string &ExeName,
// if ProgramPath contains at least one / character, indicating that it is a
// relative path to bugpoint itself.
sys::Path Result ( ProgramPath );
- Result.elideFile();
+ Result.eraseComponent();
if (!Result.isEmpty()) {
- Result.appendFile(ExeName);
+ Result.appendComponent(ExeName);
if (Result.canExecute())
return Result;
}
diff --git a/lib/Support/ToolRunner.cpp b/lib/Support/ToolRunner.cpp
index 9ef14c5677..4a08e1adc7 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.destroyFile();
+ ErrorFilename.destroy();
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.destroyFile();
+ OutputAsmFile.destroy();
}
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.destroyFile();
+ OutputCFile.destroy();
}
int CBE::ExecuteProgram(const std::string &Bytecode,
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
index d2566fd06a..9ee0a3e852 100644
--- a/lib/System/Path.cpp
+++ b/lib/System/Path.cpp
@@ -27,7 +27,7 @@ Path
Path::GetLLVMConfigDir() {
Path result;
#ifdef LLVM_ETCDIR
- if (result.setDirectory(LLVM_ETCDIR))
+ if (result.set(LLVM_ETCDIR))
return result;
#endif
return GetLLVMDefaultConfigDir();
@@ -80,10 +80,10 @@ Path::FindLibrary(std::string& name) {
GetSystemLibraryPaths(LibPaths);
for (unsigned i = 0; i < LibPaths.size(); ++i) {
sys::Path FullPath(LibPaths[i]);
- FullPath.appendFile("lib" + name + LTDL_SHLIB_EXT);
+ FullPath.appendComponent("lib" + name + LTDL_SHLIB_EXT);
if (FullPath.isDynamicLibrary())
return FullPath;
- FullPath.elideSuffix();
+ FullPath.eraseSuffix();
FullPath.appendSuffix("a");
if (FullPath.isArchive())
return FullPath;
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index f871adb2c7..ffcd6949b5 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -84,7 +84,7 @@ Path::isValid() const {
Path
Path::GetRootDirectory() {
Path result;
- result.setDirectory("/");
+ result.set("/");
return result;
}
@@ -98,7 +98,7 @@ Path::GetTemporaryDirectory() {
if (0 == mkdtemp(pathname))
ThrowErrno(std::string(pathname) + ": can't create temporary directory");
Path result;
- result.setDirectory(pathname);
+ result.set(pathname);
assert(result.isValid() && "mkdtemp didn't create a valid pathname!");
return result;
#elif defined(HAVE_MKSTEMP)
@@ -117,7 +117,7 @@ Path::GetTemporaryDirectory() {
if (-1 == ::mkdir(pathname, S_IRWXU)) // end race condition
ThrowErrno(std::string(pathname) + ": can't create temporary directory");
Path result;
- result.setDirectory(pathname);
+ result.set(pathname);
assert(result.isValid() && "mkstemp didn't create a valid pathname!");
return result;
#elif defined(HAVE_MKTEMP)
@@ -134,7 +134,7 @@ Path::GetTemporaryDirectory() {
if (-1 == ::mkdir(TmpName, S_IRWXU))
ThrowErrno(std::string(TmpName) + ": can't create temporary directory");
Path result;
- result.setDirectory(TmpName);
+ result.set(TmpName);
assert(result.isValid() && "mktemp didn't create a valid pathname!");
return result;
#else
@@ -155,7 +155,7 @@ Path::GetTemporaryDirectory() {
if (-1 == ::mkdir(pathname, S_IRWXU))
ThrowErrno(std::string(pathname) + ": can't create temporary directory");
Path result;
- result.setDirectory(pathname);
+ result.set(pathname);
assert(result.isValid() && "mkstemp didn't create a valid pathname!");
return result;
#endif
@@ -167,14 +167,14 @@ static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
Path tmpPath;
while( delim != 0 ) {
std::string tmp(at, size_t(delim-at));
- if (tmpPath.setDirectory(tmp))
+ if (tmpPath.set(tmp))
if (tmpPath.canRead())
Paths.push_back(tmpPath);
at = delim + 1;
delim = strchr(at, ':');
}
if (*at != 0)
- if (tmpPath.setDirectory(std::string(at)))
+ if (tmpPath.set(std::string(at)))
if (tmpPath.canRead())
Paths.push_back(tmpPath);
@@ -204,7 +204,7 @@ Path::GetBytecodeLibraryPaths(std::vector<sys::Path>& Paths) {
#ifdef LLVM_LIBDIR
{
Path tmpPath;
- if (tmpPath.setDirectory(LLVM_LIBDIR))
+ if (tmpPath.set(LLVM_LIBDIR))
if (tmpPath.canRead())
Paths.push_back(tmpPath);
}
@@ -222,7 +222,7 @@ Path::GetUserHomeDirectory() {
const char* home = getenv("HOME");
if (home) {
Path result;
- if (result.setDirectory(home))
+ if (result.set(home))
return result;
}
return GetRootDirectory();
@@ -230,12 +230,20 @@ Path::GetUserHomeDirectory() {
bool
Path::isFile() const {
- return (isValid() && path[path.length()-1] != '/');
+ struct stat buf;
+ if (0 != stat(path.c_str(), &buf)) {
+ ThrowErrno(path + ": can't determine type of path object: ");
+ }
+ return S_ISREG(buf.st_mode);
}
bool
Path::isDirectory() const {
- return (isValid() && path[path.length()-1] == '/');
+ struct stat buf;
+ if (0 != stat(path.c_str(), &buf)) {
+ ThrowErrno(path + ": can't determine type of path object: ");
+ }
+ return S_ISDIR(buf.st_mode);
}
std::string
@@ -357,8 +365,6 @@ Path::getStatusInfo(StatusInfo& info) const {
info.user = buf.st_uid;
info.group = buf.st_gid;
info.isDir = S_ISDIR(buf.st_mode);
- if (info.isDir && path[path.length()-1] != '/')
- path += '/';
}
static bool AddPermissionBits(const std::string& Filename, int bits) {
@@ -419,8 +425,6 @@ Path::getDirectoryContents(std::set<Path>& result) const {
ThrowErrno(aPath.path +
": can't determine file object type", stat_errno);
}
- if (S_ISDIR(buf.st_mode))
- aPath.path += "/";
result.insert(aPath);
}
}
@@ -430,124 +434,84 @@ Path::getDirectoryContents(std::set<Path>& result) const {
}
bool
-Path::setDirectory(const std::string& a_path) {
- if (a_path.size() == 0)
+Path::set(const std::string& a_path) {
+ if (a_path.empty())
return false;
- Path save(*this);
+ std::string save(path);
path = a_path;
- size_t last = a_path.size() -1;
- if (a_path[last] != '/')
- path += '/';
if (!isValid()) {
- path = save.path;
+ path = save;
return false;
}
return true;
}
bool
-Path::setFile(const std::string& a_path) {
- if (a_path.size() == 0)
- return false;
- Path save(*this);
- path = a_path;
- size_t last = a_path.size() - 1;
- while (last > 0 && a_path[last] == '/')
- last--;
- path.erase(last+1);
- if (!isValid()) {
- path = save.path;
+Path::appendComponent(const std::string& name) {
+ if (name.empty())
return false;
+ std::string save(path);
+ if (!path.empty()) {
+ size_t last = path.size() - 1;
+ if (path[last] != '/')
+ path += '/';
}
- return true;
-}
-
-bool
-Path::appendDirectory(const std::string& dir) {
- if (isFile())
- return false;
- Path save(*this);
- path += dir;
- path += "/";
+ path += name;
if (!isValid()) {
- path = save.path;
+ path = save;
return false;
}
return true;
}
bool
-Path::elideDirectory() {
- if (isFile())
- return false;
+Path::eraseComponent() {