Per code review:
authorReid Spencer <rspencer@reidspencer.com>
Tue, 16 Nov 2004 06:15:19 +0000 (06:15 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 16 Nov 2004 06:15:19 +0000 (06:15 +0000)
* Clean up the StatusInfo constructor to construct all members and give
  them reasonable values.
* Get rid of the Vector typedef and make the interface to
  getDirectoryContent use a std::set instead of a std::vector so the dir
  content is sorted.
* Make the getStatusInfo method const and not return a useless boolean.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17872 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Unix/Path.cpp
lib/System/Unix/Path.inc

index f5770e9839c1be15713a7deaced0b98a6b4b94b9..f9ee040dbc7ec4eca00d0013b668c23fec749bf7 100644 (file)
 #ifndef LLVM_SYSTEM_PATH_H
 #define LLVM_SYSTEM_PATH_H
 
+#include "llvm/System/TimeValue.h"
+#include <set>
 #include <string>
 #include <vector>
-#include "llvm/System/TimeValue.h"
 
 namespace llvm {
 namespace sys {
@@ -46,8 +47,6 @@ namespace sys {
     /// @name Types
     /// @{
     public:
-      typedef std::vector<Path> Vector;
-
       /// This structure provides basic file system information about a file. It
       /// is patterned after the stat(2) Unix operating system call but made
       /// platform independent and eliminates many of the unix-specific fields.
@@ -58,7 +57,8 @@ namespace sys {
       /// filled in by the getStatusInfo method.
       /// @brief File status structure
       struct StatusInfo {
-        StatusInfo() : modTime(0,0) { fileSize=0; mode=0; user=0; group=0; }
+        StatusInfo() : fileSize(0), modTime(0,0), mode(0777), user(999), 
+                       group(999), isDir(false) { }
         size_t      fileSize;   ///< Size of the file in bytes
         TimeValue   modTime;    ///< Time of file's modification
         uint32_t    mode;       ///< Mode of the file, if applicable
@@ -345,7 +345,7 @@ namespace sys {
       /// @returns false if \p this is not a directory, true otherwise
       /// @throws std::string if the directory cannot be searched
       /// @brief Build a list of directory's contents.
-      bool getDirectoryContents(Vector& paths) const;
+      bool getDirectoryContents(std::set<Path>& paths) const;
 
       /// Obtain a 'C' string for the path name.
       /// @returns a 'C' string containing the path name.
@@ -367,11 +367,9 @@ namespace sys {
       /// of the file system. If the file does not exist, false is returned. 
       /// For other (hard I/O) errors, a std::string is throwing indicating the
       /// problem.
-      /// @returns true if the status info was obtained, false if the file does
-      /// not exist.
       /// @throws std::string if an error occurs.
       /// @brief Get file status.
-      bool getStatusInfo(StatusInfo& stat);
+      void getStatusInfo(StatusInfo& info) const;
 
       /// This method attempts to set the Path object to \p unverified_path
       /// and interpret the name as a directory name.  The \p unverified_path 
@@ -527,7 +525,7 @@ namespace sys {
     /// @name Data
     /// @{
     private:
-        std::string path; ///< Platform agnostic storage for the path name.
+        mutable std::string path;   ///< Storage for the path name.
 
     /// @}
   };
index d2ba0f903591080acd594eb53998a2a5c2e3573f..55ef6669ee35075b47766bc375433d3624e12ea2 100644 (file)
@@ -239,10 +239,8 @@ Path::getLast() const {
   return path.substr(pos+1);
 }
 
-bool
-Path::getStatusInfo(StatusInfo& info) {
-  if (!isFile() || !readable())
-    return false;
+void
+Path::getStatusInfo(StatusInfo& info) const {
   struct stat buf;
   if (0 != stat(path.c_str(), &buf)) {
     ThrowErrno(std::string("Can't get status: ")+path);
@@ -255,11 +253,10 @@ Path::getStatusInfo(StatusInfo& info) {
   info.isDir = S_ISDIR(buf.st_mode);
   if (info.isDir && path[path.length()-1] != '/')
     path += '/';
-  return true;
 }
 
 bool
-Path::getDirectoryContents(Vector& result) const {
+Path::getDirectoryContents(std::set<Path>& result) const {
   if (!isDirectory())
     return false;
   DIR* direntries = ::opendir(path.c_str());
@@ -276,7 +273,7 @@ Path::getDirectoryContents(Vector& result) const {
         ThrowErrno(aPath.path + ": can't get status");
       if (S_ISDIR(buf.st_mode))
         aPath.path += "/";
-      result.push_back(aPath);
+      result.insert(aPath);
     }
     de = ::readdir(direntries);
   }
index d2ba0f903591080acd594eb53998a2a5c2e3573f..55ef6669ee35075b47766bc375433d3624e12ea2 100644 (file)
@@ -239,10 +239,8 @@ Path::getLast() const {
   return path.substr(pos+1);
 }
 
-bool
-Path::getStatusInfo(StatusInfo& info) {
-  if (!isFile() || !readable())
-    return false;
+void
+Path::getStatusInfo(StatusInfo& info) const {
   struct stat buf;
   if (0 != stat(path.c_str(), &buf)) {
     ThrowErrno(std::string("Can't get status: ")+path);
@@ -255,11 +253,10 @@ Path::getStatusInfo(StatusInfo& info) {
   info.isDir = S_ISDIR(buf.st_mode);
   if (info.isDir && path[path.length()-1] != '/')
     path += '/';
-  return true;
 }
 
 bool
-Path::getDirectoryContents(Vector& result) const {
+Path::getDirectoryContents(std::set<Path>& result) const {
   if (!isDirectory())
     return false;
   DIR* direntries = ::opendir(path.c_str());
@@ -276,7 +273,7 @@ Path::getDirectoryContents(Vector& result) const {
         ThrowErrno(aPath.path + ": can't get status");
       if (S_ISDIR(buf.st_mode))
         aPath.path += "/";
-      result.push_back(aPath);
+      result.insert(aPath);
     }
     de = ::readdir(direntries);
   }