Merge "fs_mgr: fs_mgr_rm_all error propagation inconsequential EPERM"
This commit is contained in:
commit
d2dfb33942
1 changed files with 13 additions and 7 deletions
|
|
@ -261,7 +261,7 @@ bool fs_mgr_wants_overlayfs(const fstab_rec* fsrec) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr) {
|
bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr, int level = 0) {
|
||||||
auto save_errno = errno;
|
auto save_errno = errno;
|
||||||
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(path.c_str()), closedir);
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(path.c_str()), closedir);
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
|
|
@ -269,7 +269,11 @@ bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr) {
|
||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PERROR << "opendir " << path;
|
PERROR << "opendir " << path << " depth=" << level;
|
||||||
|
if ((errno == EPERM) && (level != 0)) {
|
||||||
|
errno = save_errno;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dirent* entry;
|
dirent* entry;
|
||||||
|
|
@ -279,23 +283,25 @@ bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr) {
|
||||||
auto file = path + "/" + entry->d_name;
|
auto file = path + "/" + entry->d_name;
|
||||||
if (entry->d_type == DT_UNKNOWN) {
|
if (entry->d_type == DT_UNKNOWN) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
save_errno = errno;
|
||||||
if (!lstat(file.c_str(), &st) && (st.st_mode & S_IFDIR)) entry->d_type = DT_DIR;
|
if (!lstat(file.c_str(), &st) && (st.st_mode & S_IFDIR)) entry->d_type = DT_DIR;
|
||||||
|
errno = save_errno;
|
||||||
}
|
}
|
||||||
if (entry->d_type == DT_DIR) {
|
if (entry->d_type == DT_DIR) {
|
||||||
ret &= fs_mgr_rm_all(file, change);
|
ret &= fs_mgr_rm_all(file, change, level + 1);
|
||||||
if (!rmdir(file.c_str())) {
|
if (!rmdir(file.c_str())) {
|
||||||
if (change) *change = true;
|
if (change) *change = true;
|
||||||
} else {
|
} else {
|
||||||
ret = false;
|
if (errno != ENOENT) ret = false;
|
||||||
PERROR << "rmdir " << file;
|
PERROR << "rmdir " << file << " depth=" << level;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!unlink(file.c_str())) {
|
if (!unlink(file.c_str())) {
|
||||||
if (change) *change = true;
|
if (change) *change = true;
|
||||||
} else {
|
} else {
|
||||||
ret = false;
|
if (errno != ENOENT) ret = false;
|
||||||
PERROR << "rm " << file;
|
PERROR << "rm " << file << " depth=" << level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue