Changeset 687 for trunk/lib/rmdirhier.cc


Ignore:
Timestamp:
Aug 4, 2008, 9:37:10 PM (13 years ago)
Author:
Peter Johansson
Message:

Merged patch release 0.6.6 to trunk. Delta 0.6.6 - 0.6.5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/rmdirhier.cc

    r681 r687  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2008 Peter Johansson
    56
    6   This file is part of svndigest, http://trac.thep.lu.se/svndigest
     7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
    78
    89  svndigest is free software; you can redistribute it and/or modify it
     
    6465  void rmdirhier__(const std::string& dir)
    6566  {
     67    struct stat buf;
     68    // using lstat because links should not be treated as dirs
     69    lstat(dir.c_str(),&buf);
     70    // check if dir - if not delete the node
     71    if (!(buf.st_mode & S_IFDIR)) {
     72      // Make sure file is removable before removing it
     73      chmod(dir.c_str(),S_IWRITE);
     74      if (unlink(dir.c_str()))
     75        throw FileDeleteError(dir);
     76      return;
     77    }
    6678    if (chdir(dir.c_str()))
    6779      throw BadDirectory(dir);
     
    7385      throw DirectoryOpenError(dir);
    7486    while ((entry=readdir(dp)) != NULL) {
    75       struct stat buf;
    7687      if ((std::string(entry->d_name) == ".") ||
    7788          (std::string(entry->d_name) == ".."))
    7889        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       }
     90      rmdirhier__(entry->d_name);
    8891    }
    8992    closedir(dp);
Note: See TracChangeset for help on using the changeset viewer.