Changeset 22 for trunk/lib/Directory.cc
- Timestamp:
- Jan 2, 2006, 1:44:17 AM (17 years ago)
- File:
-
- 1 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;
Note: See TracChangeset
for help on using the changeset viewer.