diff options
author | Ilho Kim <ilho159.kim@samsung.com> | 2024-08-12 15:28:12 +0900 |
---|---|---|
committer | Ilho Kim <ilho159.kim@samsung.com> | 2024-08-12 16:07:12 +0900 |
commit | 4f82239aee6dfb30b437fd4b70cc3878a6e19d93 (patch) | |
tree | f54dd7f572a71ab9ea68864c2fd4d5beaa92f2f6 | |
parent | fe0f07d8ba109715fa25c8892dab2196d2e94c7d (diff) | |
download | app-installers-tizen_7.0.tar.gz app-installers-tizen_7.0.tar.bz2 app-installers-tizen_7.0.zip |
Add exception handling of RemoveAlltizen_7.0
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: I857d1a768df59fc8f45ef67526818cad1fb4f4f1
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
(cherry picked from commit 80ae58e3d079e57c82ef070458b8ce0a4e899a59)
-rw-r--r-- | src/common/utils/file_util.cc | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/common/utils/file_util.cc b/src/common/utils/file_util.cc index 8df33f45..27c9b05c 100644 --- a/src/common/utils/file_util.cc +++ b/src/common/utils/file_util.cc @@ -316,18 +316,30 @@ bool RemoveBackup(const bf::path& path) { } bool RemoveAll(const bf::path& path) { - if (!bf::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) { |