// Callback for use with nftw(3) to assist with clearing files and sub-directories. // This method removes files and directories below the top-level directory passed to nftw(). staticint NftwCleanUpCallback(constchar* fpath,
[[maybe_unused]] conststruct stat* sb, int typeflag, struct FTW* ftwbuf) { switch (typeflag) { case FTW_F: return unlink(fpath); case FTW_DP: return (ftwbuf->level == 0) ? 0 : rmdir(fpath); default: return -1;
}
}
static constexpr int kMaxDescriptors = 4; // Limit the need for nftw() to re-open descriptors. if (nftw(dir_path.c_str(), NftwCleanUpCallback, kMaxDescriptors, FTW_DEPTH | FTW_MOUNT) != 0) {
LOG(ERROR) << "Failed to clean-up '" << dir_path << "'"; returnfalse;
}
if (rmdir(dir_path.c_str()) != 0) { // It's possible that we are not able to remove the directory itself. For example, when // odrefresh is running in CompOS, the staging dir is prepared beforehand passed to the VM as an // FD. In this case, just log and ignore the error. It's okay to keep the directory.
LOG(WARNING) << "Failed to delete '" << dir_path << "'";
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.