From 1e6278ce034c74249a751c22d241854cbb5af141 Mon Sep 17 00:00:00 2001 From: huangyuchen Date: Fri, 7 Jul 2023 14:43:48 +0800 Subject: [PATCH] Modify implementation of ForceRemoveDirectory since whether `faccessat2` sys-call can be called should be further dicussed. Issue:I7JJOE Test:UT Signed-off-by: huangyuchen Change-Id: I9b45e070f1ab84cde1988bd719be09b0a78df56d --- base/src/directory_ex.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/base/src/directory_ex.cpp b/base/src/directory_ex.cpp index 9e79b9b..650a4e2 100644 --- a/base/src/directory_ex.cpp +++ b/base/src/directory_ex.cpp @@ -204,6 +204,8 @@ bool ForceRemoveDirectory(const string& path) return false; } + struct stat unused; + while (true) { struct dirent *ptr = readdir(dir); if (ptr == nullptr) { @@ -218,7 +220,7 @@ bool ForceRemoveDirectory(const string& path) if (ptr->d_type == DT_DIR) { ret = ForceRemoveDirectory(subPath); } else { - if (faccessat(AT_FDCWD, subPath.c_str(), F_OK, AT_SYMLINK_NOFOLLOW) == 0) { + if (lstat(subPath.c_str(), &unused) == 0) { if (remove(subPath.c_str()) != 0) { closedir(dir); return false; @@ -229,13 +231,13 @@ bool ForceRemoveDirectory(const string& path) closedir(dir); string currentPath = ExcludeTrailingPathDelimiter(path); - if (faccessat(AT_FDCWD, currentPath.c_str(), F_OK, AT_SYMLINK_NOFOLLOW) == 0) { + if (lstat(currentPath.c_str(), &unused) == 0) { if (remove(currentPath.c_str()) != 0) { return false; } } - return ret && (faccessat(AT_FDCWD, path.c_str(), F_OK, AT_SYMLINK_NOFOLLOW) != 0); + return ret && (lstat(path.c_str(), &unused) != 0); } bool RemoveFile(const string& fileName) -- Gitee