Changeset 1445 for trunk


Ignore:
Timestamp:
Dec 20, 2011, 9:35:04 PM (9 years ago)
Author:
Peter Johansson
Message:

shuffle code to simplify logic in rmdirhier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/rmdirhier.cc

    r1435 r1445  
    4545    // using lstat because links should not be treated as dirs
    4646    lstat(dir, &buf);
    47     // check if dir - if not delete the node
    48     if (!(buf.st_mode & S_IFDIR)) {
    49       // Make sure file is removable before removing it
    50       chmod(dir.c_str(),S_IWRITE);
    51       remove(dir);
    52       return;
     47    // check if dir
     48    if ((buf.st_mode & S_IFDIR)) {
     49      // Delete sub-nodes
     50      DirectoryUtil du(dir);
     51      for (DirectoryUtil::const_iterator node=du.begin();node!=du.end();++node){
     52        if ((file_name(node->path())!=".") && (file_name(node->path())!=".."))
     53          rmdirhier(node->path());
     54      }
    5355    }
    54 
    55    // Delete any remaining directory entries
    56     DirectoryUtil du(dir);
    57     for (DirectoryUtil::const_iterator node=du.begin(); node!=du.end();++node){
    58       if ((file_name(node->path())!=".") && (file_name(node->path())!=".."))
    59         rmdirhier(node->path());
    60     }
    61 
    62     // Remove the directory from its parent
     56    // Make sure file is removable before removing it
     57    chmod(dir.c_str(),S_IWRITE);
    6358    remove(dir);
    6459  }
Note: See TracChangeset for help on using the changeset viewer.