Implement fs::isfile (#11447)

This commit is contained in:
Eladash 2022-01-29 21:10:48 +02:00 committed by GitHub
parent bb65e6797f
commit 781b2b4548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -1413,6 +1413,12 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
}; };
m_file = std::make_unique<unix_file>(fd); m_file = std::make_unique<unix_file>(fd);
if (mode & fs::isfile && !(mode & fs::write) && stat().is_directory)
{
m_file.reset();
g_tls_error = error::isdir;
}
#endif #endif
} }

View file

@ -32,6 +32,7 @@ namespace fs
excl, excl,
lock, lock,
unread, unread,
isfile,
__bitset_enum_max __bitset_enum_max
}; };
@ -44,6 +45,7 @@ namespace fs
constexpr auto excl = +open_mode::excl; // Failure if the file already exists (used with `create`) constexpr auto excl = +open_mode::excl; // Failure if the file already exists (used with `create`)
constexpr auto lock = +open_mode::lock; // Prevent opening the file more than once constexpr auto lock = +open_mode::lock; // Prevent opening the file more than once
constexpr auto unread = +open_mode::unread; // Aggressively prevent reading the opened file (do not use) constexpr auto unread = +open_mode::unread; // Aggressively prevent reading the opened file (do not use)
constexpr auto isfile = +open_mode::isfile; // Ensure valid fs::file handle is not of directory
constexpr auto write_new = write + create + excl; constexpr auto write_new = write + create + excl;
constexpr auto rewrite = write + create + trunc; constexpr auto rewrite = write + create + trunc;

View file

@ -27,9 +27,9 @@ namespace rsx
{ {
image_info::image_info(const char* filename) image_info::image_info(const char* filename)
{ {
fs::file f(filename); fs::file f(filename, fs::read + fs::isfile);
if (!f || f.stat().is_directory) if (!f)
{ {
rsx_log.error("Image resource file `%s' could not be opened (%s)", filename, fs::g_tls_error); rsx_log.error("Image resource file `%s' could not be opened (%s)", filename, fs::g_tls_error);
return; return;

View file

@ -931,7 +931,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
break; break;
} }
if (fs::file sfb_file{parent_dir + "/PS3_DISC.SFB"}; sfb_file && sfb_file.size() >= 4 && sfb_file.read<u32>() == ".SFB"_u32) if (fs::file sfb_file{parent_dir + "/PS3_DISC.SFB", fs::read + fs::isfile}; sfb_file && sfb_file.size() >= 4 && sfb_file.read<u32>() == ".SFB"_u32)
{ {
main_dir_name = std::string_view{search_dir}.substr(search_dir.find_last_of(fs::delim) + 1); main_dir_name = std::string_view{search_dir}.substr(search_dir.find_last_of(fs::delim) + 1);