Changeset 22 for trunk/lib/Directory.cc


Ignore:
Timestamp:
Jan 2, 2006, 1:44:17 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Fixed check of symbolic links by checking if a node is an explicit directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r19 r22  
    1212#include <errno.h>  // Needed to check error state below.
    1313#include <dirent.h>
     14#include <sys/stat.h>
    1415
    1516namespace theplu{
     
    2021  {
    2122    using namespace std;
    22     DIR* directory=opendir(path.c_str());
     23    DIR* directory=opendir(path.c_str());    // C API from dirent.h
    2324    if (!directory) {
    2425      // Jari, throw exception
     
    2829    list<string> entries;
    2930    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 backing
     31    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));
    3334    if (errno) {
    3435      // Jari, throw exception
     
    4142    for (list<string>::iterator i=entries.begin(); i!=entries.end(); i++)
    4243      if ((*i)!=string(".") && (*i)!=string("..") && (*i)!=string(".svn")) {
    43         /// Jari, should test if directory in some other way
    4444        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
    4750          daughters_.push_back(new File(fullpath));
    48         else
    49           daughters_.push_back(new Directory(fullpath));
    5051      }
    5152  }
     
    5455  Directory::~Directory(void)
    5556  {
    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++)
    5958      delete *i;
    6059  }
     
    6564    stats_.reset();
    6665
    67     for (std::list<Node*>::iterator i=daughters_.begin();
    68          i!=daughters_.end(); i++)
     66    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); i++)
    6967      stats_ += (*i)->parse();
    7068    return stats_;
     
    7977
    8078  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(); )
    8280      if (!((*i)->subversion_controlled())) {
    8381        delete *i;
Note: See TracChangeset for help on using the changeset viewer.