From df65de231f45cffea1f8bbdbc5ea5e9cb4beb367 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Thu, 9 Apr 2020 10:22:34 -0400 Subject: [PATCH] filesystem: use std for DeleteFolder Remove custom platform implementation of `DeleteFolder` and replace two uses with `std::filesystem::remove_all` which removes a file or directory with all its contents. --- src/xenia/base/filesystem.h | 4 ---- src/xenia/base/filesystem_posix.cc | 6 ------ src/xenia/base/filesystem_win.cc | 9 --------- src/xenia/kernel/xam/content_manager.cc | 3 +-- src/xenia/vfs/devices/host_path_entry.cc | 2 +- 5 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/xenia/base/filesystem.h b/src/xenia/base/filesystem.h index a2d11458e..f936cc14f 100644 --- a/src/xenia/base/filesystem.h +++ b/src/xenia/base/filesystem.h @@ -41,10 +41,6 @@ std::filesystem::path GetUserFolder(); // attempting to create it. bool CreateParentFolder(const std::filesystem::path& path); -// Recursively deletes the files and folders at the specified path. -// Returns true if the path was found and removed. -bool DeleteFolder(const std::filesystem::path& path); - // Creates an empty file at the given path. bool CreateFile(const std::filesystem::path& path); diff --git a/src/xenia/base/filesystem_posix.cc b/src/xenia/base/filesystem_posix.cc index e26e55250..c5bf420b0 100644 --- a/src/xenia/base/filesystem_posix.cc +++ b/src/xenia/base/filesystem_posix.cc @@ -112,12 +112,6 @@ static int removeCallback(const char* fpath, const struct stat* sb, return rv; } -bool DeleteFolder(const std::filesystem::path& path) { - return nftw(path.c_str(), removeCallback, 64, FTW_DEPTH | FTW_PHYS) == 0 - ? true - : false; -} - static uint64_t convertUnixtimeToWinFiletime(time_t unixtime) { // Linux uses number of seconds since 1/1/1970, and Windows uses // number of nanoseconds since 1/1/1601 diff --git a/src/xenia/base/filesystem_win.cc b/src/xenia/base/filesystem_win.cc index ddc80d2ab..53c8052c7 100644 --- a/src/xenia/base/filesystem_win.cc +++ b/src/xenia/base/filesystem_win.cc @@ -61,15 +61,6 @@ std::filesystem::path GetUserFolder() { return result; } -bool DeleteFolder(const std::filesystem::path& path) { - auto double_null_path = path.wstring() + std::wstring(L"\0", 1); - SHFILEOPSTRUCT op = {0}; - op.wFunc = FO_DELETE; - op.pFrom = double_null_path.c_str(); - op.fFlags = FOF_NO_UI; - return SHFileOperation(&op) == 0; -} - bool CreateFile(const std::filesystem::path& path) { auto handle = CreateFileW(path.c_str(), 0, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); diff --git a/src/xenia/kernel/xam/content_manager.cc b/src/xenia/kernel/xam/content_manager.cc index 7e7026ae8..235e550b3 100644 --- a/src/xenia/kernel/xam/content_manager.cc +++ b/src/xenia/kernel/xam/content_manager.cc @@ -243,8 +243,7 @@ X_RESULT ContentManager::DeleteContent(const XCONTENT_DATA& data) { auto global_lock = global_critical_region_.Acquire(); auto package_path = ResolvePackagePath(data); - if (std::filesystem::exists(package_path)) { - xe::filesystem::DeleteFolder(package_path); + if (std::filesystem::remove_all(package_path) > 0) { return X_ERROR_SUCCESS; } else { return X_ERROR_FILE_NOT_FOUND; diff --git a/src/xenia/vfs/devices/host_path_entry.cc b/src/xenia/vfs/devices/host_path_entry.cc index 069c2be5a..96f0399d9 100644 --- a/src/xenia/vfs/devices/host_path_entry.cc +++ b/src/xenia/vfs/devices/host_path_entry.cc @@ -99,7 +99,7 @@ bool HostPathEntry::DeleteEntryInternal(Entry* entry) { auto full_path = host_path_ / xe::to_path(entry->name()); if (entry->attributes() & kFileAttributeDirectory) { // Delete entire directory and contents. - return xe::filesystem::DeleteFolder(full_path); + return std::filesystem::remove_all(full_path); } else { // Delete file. return xe::filesystem::DeleteFile(full_path);