From 09b0564c75c3da41eaf15dcb847831c11f4c27b9 Mon Sep 17 00:00:00 2001
From: Subv <subv2112@gmail.com>
Date: Mon, 28 Dec 2015 09:59:27 -0500
Subject: [PATCH] HLE/FS: Corrected the error codes for DeleteFile

---
 src/core/file_sys/archive_backend.h |  4 ++--
 src/core/file_sys/disk_archive.cpp  | 15 +++++++++++++--
 src/core/file_sys/disk_archive.h    |  2 +-
 src/core/file_sys/ivfc_archive.cpp  |  6 ++++--
 src/core/file_sys/ivfc_archive.h    |  2 +-
 src/core/hle/service/fs/archive.cpp |  5 +----
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 152c8201c..c5da9bd6f 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -83,9 +83,9 @@ public:
     /**
      * Delete a file specified by its path
      * @param path Path relative to the archive
-     * @return Whether the file could be deleted
+     * @return Result of the operation
      */
-    virtual bool DeleteFile(const Path& path) const = 0;
+    virtual ResultCode DeleteFile(const Path& path) const = 0;
 
     /**
      * Rename a File specified by its path
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 5c68e944f..0c55a4863 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -25,8 +25,19 @@ std::unique_ptr<FileBackend> DiskArchive::OpenFile(const Path& path, const Mode
     return std::move(file);
 }
 
-bool DiskArchive::DeleteFile(const Path& path) const {
-    return FileUtil::Delete(mount_point + path.AsString());
+ResultCode DiskArchive::DeleteFile(const Path& path) const {
+    std::string file_path = mount_point + path.AsString();
+
+    if (FileUtil::IsDirectory(file_path))
+        return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
+
+    if (!FileUtil::Exists(file_path))
+        return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status);
+
+    if (FileUtil::Delete(file_path))
+        return RESULT_SUCCESS;
+
+    return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status);
 }
 
 bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 1bdbc2698..c0a3d3f7b 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -34,7 +34,7 @@ public:
     virtual std::string GetName() const override { return "DiskArchive: " + mount_point; }
 
     std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
-    bool DeleteFile(const Path& path) const override;
+    ResultCode DeleteFile(const Path& path) const override;
     bool RenameFile(const Path& src_path, const Path& dest_path) const override;
     bool DeleteDirectory(const Path& path) const override;
     ResultCode CreateFile(const Path& path, u64 size) const override;
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index 5325afb58..f2f96ef1a 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -24,9 +24,11 @@ std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode
     return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size);
 }
 
-bool IVFCArchive::DeleteFile(const Path& path) const {
+ResultCode IVFCArchive::DeleteFile(const Path& path) const {
     LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", GetName().c_str());
-    return false;
+    // TODO(Subv): Verify error code
+    return ResultCode(ErrorDescription::NoData, ErrorModule::FS,
+                      ErrorSummary::Canceled, ErrorLevel::Status);
 }
 
 bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 2a4e4def3..5d3a5b61e 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -35,7 +35,7 @@ public:
     std::string GetName() const override;
 
     std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
-    bool DeleteFile(const Path& path) const override;
+    ResultCode DeleteFile(const Path& path) const override;
     bool RenameFile(const Path& src_path, const Path& dest_path) const override;
     bool DeleteDirectory(const Path& path) const override;
     ResultCode CreateFile(const Path& path, u64 size) const override;
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 57fc2f44d..cb98fa7aa 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -309,10 +309,7 @@ ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Pa
     if (archive == nullptr)
         return ERR_INVALID_HANDLE;
 
-    if (archive->DeleteFile(path))
-        return RESULT_SUCCESS;
-    return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
-                      ErrorSummary::Canceled, ErrorLevel::Status);
+    return archive->DeleteFile(path);
 }
 
 ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,