Fix crashes when opening non-existent directories

This commit is contained in:
Billy Laws 2022-10-30 16:29:39 +00:00
parent ec139b3027
commit 29e89a3950
3 changed files with 9 additions and 6 deletions

View File

@ -61,6 +61,8 @@ namespace skyline::service::fssrv {
auto listMode{request.Pop<vfs::Directory::ListMode>()};
auto directory{backing->OpenDirectory(path, listMode)};
if (!directory)
return result::PathDoesNotExist;
manager.RegisterService(std::make_shared<IDirectory>(std::move(directory), backing, state, manager), session, response);
return {};

View File

@ -134,11 +134,7 @@ namespace skyline::vfs {
* @return A shared pointer to a Directory object of the directory
*/
std::shared_ptr<Directory> OpenDirectory(const std::string &path, Directory::ListMode listMode = {true, true}) {
auto dir{OpenDirectoryUnchecked(path, listMode)};
if (dir == nullptr)
throw exception("Failed to open directory: {}", path);
return dir;
return OpenDirectoryUnchecked(path, listMode);
};
};
}

View File

@ -84,7 +84,12 @@ namespace skyline::vfs {
}
std::shared_ptr<Directory> OsFileSystem::OpenDirectoryImpl(const std::string &path, Directory::ListMode listMode) {
return std::make_shared<OsFileSystemDirectory>(basePath + path, listMode);
struct dirent *entry;
auto directory{opendir((basePath + path).c_str())};
if (!directory)
return nullptr;
else
return std::make_shared<OsFileSystemDirectory>(basePath + path, listMode);
}
OsFileSystemDirectory::OsFileSystemDirectory(std::string path, Directory::ListMode listMode) : Directory(listMode), path(std::move(path)) {}