| | 578 | } |
| | 579 | |
| | 580 | /* remove a directory and everything under it */ |
| | 581 | int mutt_rmtree (const char* path) |
| | 582 | { |
| | 583 | DIR* dirp; |
| | 584 | struct dirent* de; |
| | 585 | char cur[_POSIX_PATH_MAX]; |
| | 586 | int rc = 0; |
| | 587 | |
| | 588 | if (!(dirp = opendir (path))) |
| | 589 | { |
| | 590 | dprint (1, (debugfile, "mutt_rmtree: error opening directory %s\n", path)); |
| | 591 | return -1; |
| | 592 | } |
| | 593 | while ((de = readdir (dirp))) |
| | 594 | { |
| | 595 | if (!strcmp (".", de->d_name) || !strcmp ("..", de->d_name)) |
| | 596 | continue; |
| | 597 | |
| | 598 | snprintf (cur, sizeof (cur), "%s/%s", path, de->d_name); |
| | 599 | /* XXX make nonrecursive version */ |
| | 600 | if (de->d_type == DT_DIR) |
| | 601 | rc |= mutt_rmtree (cur); |
| | 602 | else |
| | 603 | rc |= unlink (cur); |
| | 604 | } |
| | 605 | closedir (dirp); |
| | 606 | |
| | 607 | rc |= rmdir (path); |
| | 608 | |
| | 609 | return rc; |