Changeset 22
- Timestamp:
- Jan 2, 2006, 1:44:17 AM (17 years ago)
- Location:
- trunk/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Directory.cc
r19 r22 12 12 #include <errno.h> // Needed to check error state below. 13 13 #include <dirent.h> 14 #include <sys/stat.h> 14 15 15 16 namespace theplu{ … … 20 21 { 21 22 using namespace std; 22 DIR* directory=opendir(path.c_str()); 23 DIR* directory=opendir(path.c_str()); // C API from dirent.h 23 24 if (!directory) { 24 25 // Jari, throw exception … … 28 29 list<string> entries; 29 30 struct dirent* entry; 30 errno=0; // Global variable used by C to track errors .31 while ((entry=readdir(directory))) 32 entries.push_back(string(entry->d_name)); // Jari, push backing31 errno=0; // Global variable used by C to track errors, from errno.h 32 while ((entry=readdir(directory))) // C API from dirent.h 33 entries.push_back(string(entry->d_name)); 33 34 if (errno) { 34 35 // Jari, throw exception … … 41 42 for (list<string>::iterator i=entries.begin(); i!=entries.end(); i++) 42 43 if ((*i)!=string(".") && (*i)!=string("..") && (*i)!=string(".svn")) { 43 /// Jari, should test if directory in some other way44 44 string fullpath(path_+'/'+(*i)); 45 DIR* dirtest=opendir(fullpath.c_str()); 46 if (!dirtest) 45 struct stat nodestat; // C api from sys/stat.h 46 lstat(fullpath.c_str(),&nodestat); // C api from sys/stat.h 47 if (S_ISDIR(nodestat.st_mode)) // C api from sys/stat.h 48 daughters_.push_back(new Directory(fullpath)); 49 else 47 50 daughters_.push_back(new File(fullpath)); 48 else49 daughters_.push_back(new Directory(fullpath));50 51 } 51 52 } … … 54 55 Directory::~Directory(void) 55 56 { 56 // Jari, change this to some STL algo? 57 for (std::list<Node*>::iterator i=daughters_.begin(); 58 i!=daughters_.end(); i++) 57 for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); i++) 59 58 delete *i; 60 59 } … … 65 64 stats_.reset(); 66 65 67 for (std::list<Node*>::iterator i=daughters_.begin(); 68 i!=daughters_.end(); i++) 66 for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); i++) 69 67 stats_ += (*i)->parse(); 70 68 return stats_; … … 79 77 80 78 void Directory::purge(void) { 81 for ( std::list<Node*>::iterator i=daughters_.begin(); i!=daughters_.end(); )79 for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ) 82 80 if (!((*i)->subversion_controlled())) { 83 81 delete *i; -
trunk/lib/Directory.h
r18 r22 21 21 /// @brief Constructor 22 22 /// 23 /// Recursively create a directory tree starting from \a 24 /// path. Nodes named '.', '..', and '.svn' are ignored and not 23 /// Recursively create a directory tree starting from \a path. All 24 /// entries except explicit directories are treated as File nodes, 25 /// i.e. symbolic links to directories are treated as File 26 /// nodes. This will ensure that the directory structure is a tree 27 /// and double counting of branches is avoided. 28 /// 29 /// @note Nodes named '.', '..', and '.svn' are ignored and not 25 30 /// traversed. 26 31 /// … … 44 49 Directory(const Directory&); 45 50 51 typedef std::list<Node*>::iterator NodeIterator; 46 52 std::list<Node*> daughters_; 47 53 };
Note: See TracChangeset
for help on using the changeset viewer.