summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlho Kim <ilho159.kim@samsung.com>2024-08-12 15:46:57 +0900
committerIlho Kim <ilho159.kim@samsung.com>2024-08-12 16:00:45 +0900
commit63f6f7d45885f653422cd64da6a81c8a0c72e8a6 (patch)
treeb7e8a5ee2be3a38322238fbb8543c43da82f42d8
parent7ed47167872c3aa5563e4b8b6ec47506c07acd9a (diff)
downloadapp-installers-63f6f7d45885f653422cd64da6a81c8a0c72e8a6.tar.gz
app-installers-63f6f7d45885f653422cd64da6a81c8a0c72e8a6.tar.bz2
app-installers-63f6f7d45885f653422cd64da6a81c8a0c72e8a6.zip
Add exception handling of RemoveAll
If a file is create or removed in the directory by another process while calling RemoveAll on the direcotry, an ENOENT or ENOTEMPTY error may occur. In that case the remove_all to be attempted again Change-Id: Ic9600fb9f1ca097d9a4fae6f53cf94336c452e53 Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
-rw-r--r--src/common/utils/file_util.cc30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/common/utils/file_util.cc b/src/common/utils/file_util.cc
index aa87c788..248db577 100644
--- a/src/common/utils/file_util.cc
+++ b/src/common/utils/file_util.cc
@@ -307,18 +307,30 @@ bool RemoveBackup(const fs::path& path) {
}
bool RemoveAll(const fs::path& path) {
- if (!fs::exists(path) && !fs::is_symlink(fs::symlink_status(path)))
- return true;
+ int retry_cnt = 5;
+ do {
+ if (!fs::exists(path) && !fs::is_symlink(fs::symlink_status(path)))
+ return true;
- std::error_code error;
- fs::remove_all(path, error);
+ std::error_code error;
+ fs::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 fs::path& path) {