FileSys: remove Open from DirectoryBackend
Open should not be an interface exposed by Directory because it is the Archive thats implement the methed to open the directory. The service API of 3DS also implies this - Open is not a function of directory service, but is of FS main service
This commit is contained in:
parent
75ee2f8c67
commit
0e754875d1
|
@ -40,12 +40,6 @@ public:
|
||||||
DirectoryBackend() {}
|
DirectoryBackend() {}
|
||||||
virtual ~DirectoryBackend() {}
|
virtual ~DirectoryBackend() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the directory
|
|
||||||
* @return true if the directory opened correctly
|
|
||||||
*/
|
|
||||||
virtual bool Open() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List files contained in the directory
|
* List files contained in the directory
|
||||||
* @param count Number of entries to return at once in entries
|
* @param count Number of entries to return at once in entries
|
||||||
|
|
|
@ -112,10 +112,11 @@ ResultCode DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_p
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<DirectoryBackend>> DiskArchive::OpenDirectory(const Path& path) const {
|
ResultVal<std::unique_ptr<DirectoryBackend>> DiskArchive::OpenDirectory(const Path& path) const {
|
||||||
LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str());
|
LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str());
|
||||||
auto directory = std::make_unique<DiskDirectory>(*this, path);
|
auto full_path = mount_point + path.AsString();
|
||||||
if (!directory->Open())
|
if (!FileUtil::IsDirectory(full_path))
|
||||||
return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
||||||
ErrorLevel::Permanent);
|
ErrorLevel::Permanent);
|
||||||
|
auto directory = std::make_unique<DiskDirectory>(full_path);
|
||||||
return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
|
return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,21 +212,11 @@ bool DiskFile::Close() const {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DiskDirectory::DiskDirectory(const DiskArchive& archive, const Path& path) : directory() {
|
DiskDirectory::DiskDirectory(const std::string& path) : directory() {
|
||||||
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
|
||||||
// the root directory we set while opening the archive.
|
|
||||||
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
|
||||||
this->path = archive.mount_point + path.AsString();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiskDirectory::Open() {
|
|
||||||
if (!FileUtil::IsDirectory(path))
|
|
||||||
return false;
|
|
||||||
unsigned size = FileUtil::ScanDirectoryTree(path, directory);
|
unsigned size = FileUtil::ScanDirectoryTree(path, directory);
|
||||||
directory.size = size;
|
directory.size = size;
|
||||||
directory.isDirectory = true;
|
directory.isDirectory = true;
|
||||||
children_iterator = directory.children.begin();
|
children_iterator = directory.children.begin();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 DiskDirectory::Read(const u32 count, Entry* entries) {
|
u32 DiskDirectory::Read(const u32 count, Entry* entries) {
|
||||||
|
|
|
@ -75,13 +75,12 @@ protected:
|
||||||
|
|
||||||
class DiskDirectory : public DirectoryBackend {
|
class DiskDirectory : public DirectoryBackend {
|
||||||
public:
|
public:
|
||||||
DiskDirectory(const DiskArchive& archive, const Path& path);
|
DiskDirectory(const std::string& path);
|
||||||
|
|
||||||
~DiskDirectory() override {
|
~DiskDirectory() override {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Open() override;
|
|
||||||
u32 Read(const u32 count, Entry* entries) override;
|
u32 Read(const u32 count, Entry* entries) override;
|
||||||
|
|
||||||
bool Close() const override {
|
bool Close() const override {
|
||||||
|
@ -89,7 +88,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string path;
|
|
||||||
u32 total_entries_in_directory;
|
u32 total_entries_in_directory;
|
||||||
FileUtil::FSTEntry directory;
|
FileUtil::FSTEntry directory;
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,6 @@ private:
|
||||||
|
|
||||||
class IVFCDirectory : public DirectoryBackend {
|
class IVFCDirectory : public DirectoryBackend {
|
||||||
public:
|
public:
|
||||||
bool Open() override {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
u32 Read(const u32 count, Entry* entries) override {
|
u32 Read(const u32 count, Entry* entries) override {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue