Changeset 682 for branches/0.6-stable


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

refs #342 and #343 - commit in right branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.6-stable/lib/rmdirhier.cc

    r677 r682  
    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    }
    6677    if (chdir(dir.c_str()))
    6778      throw BadDirectory(dir);
     
    7384      throw DirectoryOpenError(dir);
    7485    while ((entry=readdir(dp)) != NULL) {
    75       struct stat buf;
    7686      if ((std::string(entry->d_name) == ".") ||
    7787          (std::string(entry->d_name) == ".."))
    7888        continue;
    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       }
     89      rmdirhier__(entry->d_name);
    8890    }
    8991    closedir(dp);
Note: See TracChangeset for help on using the changeset viewer.