How much do you want sponsor somebody to solve this feature: $0
Is your feature request related to a problem? Please describe.
The FileUtils::removeDirectory method makes a system call to delete the directory. This invokes a separate process and comes with command line interpretation of the command, which makes this slow.
Describe the solution you'd like
Can we use std::filesystem::remove_all instead to achieve this? To my knowledge, it is cross platform and should perform better than making a system call.
Code Snippet
bool FileUtils::removeDirectory(std::string_view path) const
{
# if !defined(AX_TARGET_OS_TVOS)
# if (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID)
if (nftw(path.data(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1)
return false;
else
return true;
# else
std::string command = "rm -r \""s;
// Path may include space.
command.append(path).append("\"", 1);
if (system(command.c_str()) >= 0)
return true;
else
return false;
# endif // (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID)
How much do you want sponsor somebody to solve this feature: $0
Is your feature request related to a problem? Please describe. The FileUtils::removeDirectory method makes a system call to delete the directory. This invokes a separate process and comes with command line interpretation of the command, which makes this slow.
Describe the solution you'd like Can we use std::filesystem::remove_all instead to achieve this? To my knowledge, it is cross platform and should perform better than making a system call.
Code Snippet
bool FileUtils::removeDirectory(std::string_view path) const { # if !defined(AX_TARGET_OS_TVOS)
# if (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID) if (nftw(path.data(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1) return false; else return true; # else std::string command = "rm -r \""s; // Path may include space. command.append(path).append("\"", 1); if (system(command.c_str()) >= 0) return true; else return false; # endif // (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID)
# else return false; # endif // !defined(AX_TARGET_OS_TVOS) }
Suggested Improvement
bool FileUtils::removeDirectory(std::string_view path) const { # if !defined(AX_TARGET_OS_TVOS)
# if (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID) if (nftw(path.data(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1) return false; else return true; # else std::error_code ec; std::filesystem::remove_all(path, ec); return !ec; # endif // (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID)
# else return false; # endif // !defined(AX_TARGET_OS_TVOS) }