| 1539 | |
| 1540 | |
| 1541 | int SyntheticClient::clean_dir(string& basedir) |
| 1542 | { |
| 1543 | // read dir |
| 1544 | list<string> contents; |
| 1545 | UserPerm perms = client->pick_my_perms(); |
| 1546 | int r = client->getdir(basedir.c_str(), contents, perms); |
| 1547 | if (r < 0) { |
| 1548 | dout(1) << "getdir on " << basedir << " returns " << r << dendl; |
| 1549 | return r; |
| 1550 | } |
| 1551 | |
| 1552 | for (list<string>::iterator it = contents.begin(); |
| 1553 | it != contents.end(); |
| 1554 | ++it) { |
| 1555 | if (*it == ".") continue; |
| 1556 | if (*it == "..") continue; |
| 1557 | string file = basedir + "/" + *it; |
| 1558 | |
| 1559 | if (time_to_stop()) break; |
| 1560 | |
| 1561 | struct stat st; |
| 1562 | int r = client->lstat(file.c_str(), &st, perms); |
| 1563 | if (r < 0) { |
| 1564 | dout(1) << "stat error on " << file << " r=" << r << dendl; |
| 1565 | continue; |
| 1566 | } |
| 1567 | |
| 1568 | if ((st.st_mode & S_IFMT) == S_IFDIR) { |
| 1569 | clean_dir(file); |
| 1570 | client->rmdir(file.c_str(), perms); |
| 1571 | } else { |
| 1572 | client->unlink(file.c_str(), perms); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | return 0; |
| 1577 | |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | int SyntheticClient::full_walk(string& basedir) |