Merge pull request #14142 from JosJuice/directiofile-cant-create-saf

Common: Treat DirectIOFile as unable to create SAF files
This commit is contained in:
JosJuice 2025-11-23 09:50:44 +01:00 committed by GitHub
commit 490615c72a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -121,29 +121,20 @@ bool DirectIOFile::Open(const std::string& path, AccessMode access_mode, OpenMod
else if (access_mode == AccessMode::Write)
open_mode_str = "w";
// FYI: File::Exists can be slow on Android.
Common::Lazy<bool> file_exists{[&] { return Exists(path); }};
// A few features are emulated in a non-atomic manner.
if (open_mode == OpenMode::Existing)
{
if (access_mode != AccessMode::Read && !*file_exists)
return false;
}
else
{
if (open_mode == OpenMode::Truncate)
open_mode_str += 't';
else if (open_mode == OpenMode::Create && *file_exists)
return false;
// Modes other than `Existing` may create a file, but "r" won't do that automatically.
if (access_mode == AccessMode::Read && !*file_exists)
CreateEmptyFile(path);
if (open_mode == OpenMode::Create)
{
ASSERT_MSG(COMMON, false, "DirectIOFile doesn't support creating SAF files");
return false;
}
m_fd = OpenAndroidContent(path, open_mode_str);
if (!IsOpen() && (open_mode == OpenMode::Always || open_mode == OpenMode::Truncate))
ASSERT_MSG(COMMON, Exists(path), "DirectIOFile doesn't support creating SAF files");
return IsOpen();
}
#endif