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

Add SDMC::DeleteFile #526

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/core/fs/archive_sdmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,35 @@ HorizonResult SDMCArchive::createFile(const FSPath& path, u64 size) {
}

HorizonResult SDMCArchive::deleteFile(const FSPath& path) {
Helpers::panic("[SDMC] Unimplemented DeleteFile");
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path)) {
Helpers::panic("Unsafe path in SDMC::DeleteFile");
}

fs::path p = IOFile::getAppData() / "SDMC";
p += fs::path(path.utf16_string).make_preferred();

if (fs::is_directory(p)) {
Helpers::panic("SDMC::DeleteFile: Tried to delete directory");
}

if (!fs::is_regular_file(p)) {
return Result::FS::FileNotFoundAlt;
}

std::error_code ec;
bool success = fs::remove(p, ec);

// It might still be possible for fs::remove to fail, if there's eg an open handle to a file being deleted
// In this case, print a warning, but still return success for now
if (!success) {
Helpers::warn("SDMC::DeleteFile: fs::remove failed\n");
}

return Result::Success;
}

Helpers::panic("SDMCArchive::DeleteFile: Unknown path type");
return Result::Success;
}

Expand Down Expand Up @@ -145,7 +173,7 @@ Rust::Result<DirectorySession, HorizonResult> SDMCArchive::openDirectory(const F

if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path)) {
Helpers::panic("Unsafe path in SaveData::OpenDirectory");
Helpers::panic("Unsafe path in SDMC::OpenDirectory");
}

fs::path p = IOFile::getAppData() / "SDMC";
Expand Down
Loading