Changeset 681


Ignore:
Timestamp:
Aug 2, 2008, 10:13:25 PM (15 years ago)
Author:
Peter Johansson
Message:

reverting r680

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/rmdirhier.cc

    r680 r681  
    6464  void rmdirhier__(const std::string& dir)
    6565  {
    66     struct stat buf;
    67     // using lstat because links should not be treated as dirs
    68     lstat(dir.c_str(),&buf);
    69     // check if dir - if not delete the node
    70     if (!(buf.st_mode & S_IFDIR)) {
    71       // Make sure file is removable before removing it
    72       chmod(dir.c_str(),S_IWRITE);
    73       if (unlink(dir.c_str()))
    74         throw FileDeleteError(dir);
    75       return;
    76     }
    7766    if (chdir(dir.c_str()))
    7867      throw BadDirectory(dir);
     
    8473      throw DirectoryOpenError(dir);
    8574    while ((entry=readdir(dp)) != NULL) {
     75      struct stat buf;
    8676      if ((std::string(entry->d_name) == ".") ||
    8777          (std::string(entry->d_name) == ".."))
    8878        continue;
    89       rmdirhier__(entry->d_name);
     79      stat(entry->d_name,&buf);
     80      if (buf.st_mode & S_IFDIR)
     81        rmdirhier__(entry->d_name);      // sub-directory
     82      else {
     83        // Make sure file is removable before removing it
     84        chmod(entry->d_name,S_IWRITE);
     85        if (unlink(entry->d_name))
     86          throw FileDeleteError(entry->d_name);
     87      }
    9088    }
    9189    closedir(dp);
Note: See TracChangeset for help on using the changeset viewer.