}
bool RemoveAll(const bf::path& path) {
- if (!exists(path) && !bf::is_symlink(bf::symlink_status(path)))
- return true;
+ int retry_cnt = 5;
+ do {
+ if (!bf::exists(path) && !bf::is_symlink(bf::symlink_status(path)))
+ return true;
- bs::error_code error;
- bf::remove_all(path, error);
+ bs::error_code error;
+ bf::remove_all(path, error);
- if (error) {
- LOG(ERROR) << "Cannot remove: " << path << ", " << error.message();
- return false;
- }
+ if (error) {
+ if (error.value() == ENOENT || error.value() == ENOTEMPTY) {
+ LOG(WARNING) << "Cannot remove " << path << ", " << error.message() <<
+ ", because other process access some file in this path, retry[" <<
+ retry_cnt << "]";
+ usleep(500 * 1000);
+ continue;
+ }
+ LOG(ERROR) << "Cannot remove: " << path << ", " << error.message();
+ return false;
+ }
- return true;
+ return true;
+ } while(--retry_cnt);
+
+ return false;
}
bool Remove(const bf::path& path) {