Changeset 682
- Timestamp:
- Aug 2, 2008, 10:19:43 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.6-stable/lib/rmdirhier.cc
r677 r682 64 64 void rmdirhier__(const std::string& dir) 65 65 { 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 } 66 77 if (chdir(dir.c_str())) 67 78 throw BadDirectory(dir); … … 73 84 throw DirectoryOpenError(dir); 74 85 while ((entry=readdir(dp)) != NULL) { 75 struct stat buf;76 86 if ((std::string(entry->d_name) == ".") || 77 87 (std::string(entry->d_name) == "..")) 78 88 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); 88 90 } 89 91 closedir(dp);
Note: See TracChangeset
for help on using the changeset viewer.