Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FileUtils removeDirectory implementation for android #2208

Open
aryamansingh2008 opened this issue Oct 11, 2024 · 0 comments
Open

Improve FileUtils removeDirectory implementation for android #2208

aryamansingh2008 opened this issue Oct 11, 2024 · 0 comments

Comments

@aryamansingh2008
Copy link

aryamansingh2008 commented Oct 11, 2024

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant