Fix errno behavior on sceKernelRmdir

Also reduces function logging to bring it closer to the level of logging seen in other filesystem functions.
This commit is contained in:
Stephen Miller 2025-02-17 19:28:18 -06:00
parent c83c2e73f5
commit b5fa582573

View file

@ -463,54 +463,42 @@ s32 PS4_SYSV_ABI sceKernelMkdir(const char* path, u16 mode) {
return result; return result;
} }
int PS4_SYSV_ABI sceKernelRmdir(const char* path) { s32 PS4_SYSV_ABI posix_rmdir(const char* path) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance(); auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
bool ro = false; bool ro = false;
const std::filesystem::path dir_name = mnt->GetHostPath(path, &ro); const std::filesystem::path dir_name = mnt->GetHostPath(path, &ro);
if (dir_name.empty()) { if (dir_name.empty() || !std::filesystem::is_directory(dir_name)) {
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, permission denied", *__Error() = POSIX_ENOTDIR;
fmt::UTF(dir_name.u8string())); return -1;
return ORBIS_KERNEL_ERROR_EACCES;
} }
if (ro) { if (ro) {
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, directory is read only", *__Error() = POSIX_EROFS;
fmt::UTF(dir_name.u8string())); return -1;
return ORBIS_KERNEL_ERROR_EROFS;
}
if (!std::filesystem::is_directory(dir_name)) {
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, path is not a directory",
fmt::UTF(dir_name.u8string()));
return ORBIS_KERNEL_ERROR_ENOTDIR;
} }
if (!std::filesystem::exists(dir_name)) { if (!std::filesystem::exists(dir_name)) {
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, no such file or directory", *__Error() = POSIX_ENOENT;
fmt::UTF(dir_name.u8string())); return -1;
return ORBIS_KERNEL_ERROR_ENOENT;
} }
std::error_code ec; std::error_code ec;
int result = std::filesystem::remove_all(dir_name, ec); s32 result = std::filesystem::remove_all(dir_name, ec);
if (!ec) { if (ec) {
LOG_INFO(Kernel_Fs, "Removed directory: {}", fmt::UTF(dir_name.u8string())); *__Error() = POSIX_EIO;
return ORBIS_OK; return -1;
} }
LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, error_code={}", return ORBIS_OK;
fmt::UTF(dir_name.u8string()), ec.message());
return ErrnoToSceKernelError(ec.value());
} }
int PS4_SYSV_ABI posix_rmdir(const char* path) { s32 PS4_SYSV_ABI sceKernelRmdir(const char* path) {
int result = sceKernelRmdir(path); s32 result = posix_rmdir(path);
if (result < 0) { if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_rmdir: error = {}", result); LOG_ERROR(Kernel_Fs, "error = {}", *__Error());
ErrSceToPosix(result); return ErrnoToSceKernelError(*__Error());
return -1;
} }
return result; return result;
} }