summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar archshift2014-12-07 14:40:27 -0800
committerGravatar archshift2014-12-07 14:47:14 -0800
commit20d2ed09502f41519beb435a1300f2a57995c651 (patch)
tree4d58349bdfc1ab122d522780c1d9692832ce9ad0
parentMerge pull request #250 from Subv/cbranch_2 (diff)
downloadyuzu-20d2ed09502f41519beb435a1300f2a57995c651.tar.gz
yuzu-20d2ed09502f41519beb435a1300f2a57995c651.tar.xz
yuzu-20d2ed09502f41519beb435a1300f2a57995c651.zip
Make OpenDirectory fail if the directory doesn't exist
This is in line with what the hardware itself does. It does this by splitting the initial directory opening into Directory.Open(), which will return false if a stat fails. Then, Archive::OpenDirectory will return nullptr, and archive.cpp will return an error code .
-rw-r--r--src/core/file_sys/archive_sdmc.cpp2
-rw-r--r--src/core/file_sys/directory.h6
-rw-r--r--src/core/file_sys/directory_romfs.cpp4
-rw-r--r--src/core/file_sys/directory_romfs.h6
-rw-r--r--src/core/file_sys/directory_sdmc.cpp13
-rw-r--r--src/core/file_sys/directory_sdmc.h7
-rw-r--r--src/core/hle/kernel/archive.cpp5
7 files changed, 40 insertions, 3 deletions
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 169ab0f1c..fc0b9b72d 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -100,6 +100,8 @@ bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys:
100std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const { 100std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
101 DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str()); 101 DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
102 Directory_SDMC* directory = new Directory_SDMC(this, path); 102 Directory_SDMC* directory = new Directory_SDMC(this, path);
103 if (!directory->Open())
104 return nullptr;
103 return std::unique_ptr<Directory>(directory); 105 return std::unique_ptr<Directory>(directory);
104} 106}
105 107
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index e10431337..1bb4101d6 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -42,6 +42,12 @@ public:
42 virtual ~Directory() { } 42 virtual ~Directory() { }
43 43
44 /** 44 /**
45 * Open the directory
46 * @return true if the directory opened correctly
47 */
48 virtual bool Open() = 0;
49
50 /**
45 * List files contained in the directory 51 * List files contained in the directory
46 * @param count Number of entries to return at once in entries 52 * @param count Number of entries to return at once in entries
47 * @param entries Buffer to read data into 53 * @param entries Buffer to read data into
diff --git a/src/core/file_sys/directory_romfs.cpp b/src/core/file_sys/directory_romfs.cpp
index 4e8f4c04d..e6d571391 100644
--- a/src/core/file_sys/directory_romfs.cpp
+++ b/src/core/file_sys/directory_romfs.cpp
@@ -17,6 +17,10 @@ Directory_RomFS::Directory_RomFS() {
17Directory_RomFS::~Directory_RomFS() { 17Directory_RomFS::~Directory_RomFS() {
18} 18}
19 19
20bool Directory_RomFS::Open() {
21 return false;
22}
23
20/** 24/**
21 * List files contained in the directory 25 * List files contained in the directory
22 * @param count Number of entries to return at once in entries 26 * @param count Number of entries to return at once in entries
diff --git a/src/core/file_sys/directory_romfs.h b/src/core/file_sys/directory_romfs.h
index 4b71c4b13..e2944099e 100644
--- a/src/core/file_sys/directory_romfs.h
+++ b/src/core/file_sys/directory_romfs.h
@@ -20,6 +20,12 @@ public:
20 ~Directory_RomFS() override; 20 ~Directory_RomFS() override;
21 21
22 /** 22 /**
23 * Open the directory
24 * @return true if the directory opened correctly
25 */
26 bool Open() override;
27
28 /**
23 * List files contained in the directory 29 * List files contained in the directory
24 * @param count Number of entries to return at once in entries 30 * @param count Number of entries to return at once in entries
25 * @param entries Buffer to read data into 31 * @param entries Buffer to read data into
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index 60a197ce9..0f156a127 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -19,15 +19,22 @@ Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) {
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../usr/bin can give the emulated program your installed programs. 21 // For example, opening /../../usr/bin can give the emulated program your installed programs.
22 std::string absolute_path = archive->GetMountPoint() + path.AsString(); 22 this->path = archive->GetMountPoint() + path.AsString();
23 FileUtil::ScanDirectoryTree(absolute_path, directory); 23
24 children_iterator = directory.children.begin();
25} 24}
26 25
27Directory_SDMC::~Directory_SDMC() { 26Directory_SDMC::~Directory_SDMC() {
28 Close(); 27 Close();
29} 28}
30 29
30bool Directory_SDMC::Open() {
31 if (!FileUtil::IsDirectory(path))
32 return false;
33 FileUtil::ScanDirectoryTree(path, directory);
34 children_iterator = directory.children.begin();
35 return true;
36}
37
31/** 38/**
32 * List files contained in the directory 39 * List files contained in the directory
33 * @param count Number of entries to return at once in entries 40 * @param count Number of entries to return at once in entries
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index 4520d0401..4c08b0d61 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -23,6 +23,12 @@ public:
23 ~Directory_SDMC() override; 23 ~Directory_SDMC() override;
24 24
25 /** 25 /**
26 * Open the directory
27 * @return true if the directory opened correctly
28 */
29 bool Open() override;
30
31 /**
26 * List files contained in the directory 32 * List files contained in the directory
27 * @param count Number of entries to return at once in entries 33 * @param count Number of entries to return at once in entries
28 * @param entries Buffer to read data into 34 * @param entries Buffer to read data into
@@ -37,6 +43,7 @@ public:
37 bool Close() const override; 43 bool Close() const override;
38 44
39private: 45private:
46 std::string path;
40 u32 total_entries_in_directory; 47 u32 total_entries_in_directory;
41 FileUtil::FSTEntry directory; 48 FileUtil::FSTEntry directory;
42 49
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 647f0dea9..a875fa7ff 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -421,6 +421,11 @@ ResultVal<Handle> OpenDirectoryFromArchive(Handle archive_handle, const FileSys:
421 directory->path = path; 421 directory->path = path;
422 directory->backend = archive->backend->OpenDirectory(path); 422 directory->backend = archive->backend->OpenDirectory(path);
423 423
424 if (!directory->backend) {
425 return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
426 ErrorSummary::NotFound, ErrorLevel::Permanent);
427 }
428
424 return MakeResult<Handle>(handle); 429 return MakeResult<Handle>(handle);
425} 430}
426 431