{
bool rtn = true;
- try {
+ try
+ {
struct stat my_stat;
- if (stat(path.c_str(), &my_stat) != 0) {
+ if (stat(path.c_str(), &my_stat) != 0)
throw runtime_error("can't stat " + path);
- }
- if (S_ISDIR(my_stat.st_mode)) {
+ if (S_ISDIR(my_stat.st_mode))
+ {
DIR *dir = opendir(path.c_str());
- if (!dir) {
+ if (!dir)
throw runtime_error("can't open directory " + path);
- }
struct dirent store, *entry = NULL;
while (readdir_r(dir, &store, &entry) == 0 && entry != NULL)
{
string filename = entry->d_name;
- if (filename == "." || filename == "..") {
+ if (filename == "." || filename == "..")
continue;
- }
// Delete subdir or file.
rtn = recursive_delete(path + "/" + filename, false, error);
- if (rtn == false) {
+ if (rtn == false)
break;
- }
}
closedir(dir);
- if (keep_parent_dir == false && !rmdir(path)) {
+ if (keep_parent_dir == false && !rmdir(path))
throw runtime_error("can't remove directory " + path);
- }
- } else {
- if (!unlink(path)) {
+ }
+ else
+ {
+ if (!unlink(path))
throw runtime_error("can't unlink " + path);
- }
}
- } catch (exception &e) {
- if (error) {
+ }
+ catch (exception &e)
+ {
+ if (error)
+ {
ostringstream out;
out << e.what() << " (" << strerror(errno) << ")";
*error = out.str();
}
rtn = false;
- } catch (...) {
- if (error) {
+ }
+ catch (...)
+ {
+ if (error)
+ {
ostringstream out;
out << "unknown error (" << strerror(errno) << ")";
*error = out.str();