diff --git a/External/FEXCore/Source/Common/Paths.cpp b/External/FEXCore/Source/Common/Paths.cpp index 598bf245cb..9e5125110f 100644 --- a/External/FEXCore/Source/Common/Paths.cpp +++ b/External/FEXCore/Source/Common/Paths.cpp @@ -38,7 +38,7 @@ namespace FEXCore::Paths { std::error_code ec{}; // Ensure the folder structure is created for our Data - if (!std::filesystem::exists(*EntryCache) && + if (!std::filesystem::exists(*EntryCache, ec) && !std::filesystem::create_directories(*EntryCache, ec)) { LogMan::Msg::D("Couldn't create EntryCache directory: '%s'", EntryCache->c_str()); } diff --git a/External/FEXCore/Source/Interface/Config/Config.cpp b/External/FEXCore/Source/Interface/Config/Config.cpp index 7b8d8eea47..e02ff8776c 100644 --- a/External/FEXCore/Source/Interface/Config/Config.cpp +++ b/External/FEXCore/Source/Interface/Config/Config.cpp @@ -60,7 +60,7 @@ namespace FEXCore::Config { // Ensure the folder structure is created for our configuration std::error_code ec{}; - if (!std::filesystem::exists(ConfigDir) && + if (!std::filesystem::exists(ConfigDir, ec) && !std::filesystem::create_directories(ConfigDir, ec)) { // Let's go local in this case return "./"; @@ -88,7 +88,7 @@ namespace FEXCore::Config { std::error_code ec{}; if (!Global && - !std::filesystem::exists(ConfigFile) && + !std::filesystem::exists(ConfigFile, ec) && !std::filesystem::create_directories(ConfigFile, ec)) { LogMan::Msg::D("Couldn't create config directory: '%s'", ConfigFile.c_str()); // Let's go local in this case @@ -99,7 +99,7 @@ namespace FEXCore::Config { // Attempt to create the local folder if it doesn't exist if (!Global && - !std::filesystem::exists(ConfigFile) && + !std::filesystem::exists(ConfigFile, ec) && !std::filesystem::create_directories(ConfigFile, ec)) { // Let's go local in this case return "./" + Filename + ".json"; @@ -274,7 +274,8 @@ namespace FEXCore::Config { Path = std::filesystem::absolute(Path); // Only return if it exists - if (std::filesystem::exists(Path)) { + std::error_code ec{}; + if (std::filesystem::exists(Path, ec)) { return Path; } } @@ -310,7 +311,8 @@ namespace FEXCore::Config { else if (!PathName().empty()) { // If the filesystem doesn't exist then let's see if it exists in the fex-emu folder std::string NamedRootFS = GetDataDirectory() + "RootFS/" + PathName(); - if (std::filesystem::exists(NamedRootFS)) { + std::error_code ec{}; + if (std::filesystem::exists(NamedRootFS, ec)) { FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, NamedRootFS); } } @@ -333,7 +335,8 @@ namespace FEXCore::Config { else if (!PathName().empty()) { // If the filesystem doesn't exist then let's see if it exists in the fex-emu folder std::string NamedConfig = GetDataDirectory() + "ThunkConfigs/" + PathName(); - if (std::filesystem::exists(NamedConfig)) { + std::error_code ec{}; + if (std::filesystem::exists(NamedConfig, ec)) { FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_THUNKCONFIG, NamedConfig); } } diff --git a/Source/Common/RootFSSetup.cpp b/Source/Common/RootFSSetup.cpp index 9b4e6ce9df..0049b0aa8f 100644 --- a/Source/Common/RootFSSetup.cpp +++ b/Source/Common/RootFSSetup.cpp @@ -21,7 +21,8 @@ static std::fstream SquashFSLock{}; bool SanityCheckPath(std::string const &LDPath) { // Check if we have an directory inside our temp folder std::string PathUser = LDPath + "/usr"; - if (!std::filesystem::exists(PathUser)) { + std::error_code ec{}; + if (!std::filesystem::exists(PathUser, ec)) { LogMan::Msg::D("Child couldn't mount rootfs, /usr doesn't exist"); rmdir(LDPath.c_str()); return false; @@ -33,7 +34,8 @@ bool SanityCheckPath(std::string const &LDPath) { bool CheckLockExists(std::string const LockPath) { // If the lock file for a squashfs path exists the we can try // to open it and ref counting will keep it alive - if (std::filesystem::exists(LockPath)) { + std::error_code ec{}; + if (std::filesystem::exists(LockPath, ec)) { SquashFSLock.open(LockPath, std::ios_base::in | std::ios_base::binary); if (SquashFSLock.is_open()) { // We managed to open the file. Which means the mount application has now refcounted our interaction with it diff --git a/Source/Linux/Utils/ELFContainer.cpp b/Source/Linux/Utils/ELFContainer.cpp index aa9330b7bb..f57b1cfc0b 100644 --- a/Source/Linux/Utils/ELFContainer.cpp +++ b/Source/Linux/Utils/ELFContainer.cpp @@ -95,11 +95,12 @@ ELFContainer::ELFContainer(std::string const &Filename, std::string const &RootF RawString = &RawFile.at(InterpreterHeader._64->p_offset); } std::string RootFSLink = RootFS + RawString; - while (std::filesystem::is_symlink(RootFSLink)) { + std::error_code ec{}; + while (std::filesystem::is_symlink(RootFSLink, ec)) { // Do some special handling if the RootFS's linker is a symlink // Ubuntu's rootFS by default provides an absolute location symlink to the linker // Resolve this around back to the rootfs - auto SymlinkTarget = std::filesystem::read_symlink(RootFSLink); + auto SymlinkTarget = std::filesystem::read_symlink(RootFSLink, ec); if (SymlinkTarget.is_absolute()) { RootFSLink = RootFS + SymlinkTarget.string(); } diff --git a/Source/Tests/FEXLoader.cpp b/Source/Tests/FEXLoader.cpp index e7f0a4caf8..3d457b5b32 100644 --- a/Source/Tests/FEXLoader.cpp +++ b/Source/Tests/FEXLoader.cpp @@ -165,9 +165,11 @@ bool RanAsInterpreter(char *Program) { bool IsInterpreterInstalled() { // The interpreter is installed if both the binfmt_misc handlers are available // Or if we were originally executed with FD. Which means the interpreter is installed + + std::error_code ec{}; return ExecutedWithFD || - (std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86") && - std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86_64")); + (std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86", ec) && + std::filesystem::exists("/proc/sys/fs/binfmt_misc/FEX-x86_64", ec)); } void AOTGenSection(FEXCore::Context::Context *CTX, ELFCodeLoader2::LoadedSection &Section) { @@ -409,7 +411,8 @@ int main(int argc, char **argv, char **const envp) { InterpreterHandler(&Program, LDPath(), &Args); - if (!std::filesystem::exists(Program)) { + std::error_code ec{}; + if (!std::filesystem::exists(Program, ec)) { // Early exit if the program passed in doesn't exist // Will prevent a crash later fprintf(stderr, "%s: command not found\n", Program.c_str()); @@ -548,7 +551,6 @@ int main(int argc, char **argv, char **const envp) { FEXCore::Context::RunUntilExit(CTX); } - std::error_code ec{}; if (std::filesystem::create_directories(std::filesystem::path(FEXCore::Config::GetDataDirectory()) / "aotir", ec)) { FEXCore::Context::WriteFilesWithCode(CTX, [](const std::string& fileid, const std::string& filename) { auto filepath = std::filesystem::path(FEXCore::Config::GetDataDirectory()) / "aotir" / (fileid + ".path"); diff --git a/Source/Tools/FEXConfig/Main.cpp b/Source/Tools/FEXConfig/Main.cpp index 7d53448a23..29142985c1 100644 --- a/Source/Tools/FEXConfig/Main.cpp +++ b/Source/Tools/FEXConfig/Main.cpp @@ -77,7 +77,8 @@ namespace { } bool OpenFile(std::string Filename, bool LoadDefault = false) { - if (!std::filesystem::exists(Filename)) { + std::error_code ec{}; + if (!std::filesystem::exists(Filename, ec)) { if (LoadDefault) { LoadDefaultSettings(); ConfigFilename = Filename; @@ -98,9 +99,10 @@ namespace { std::scoped_lock lk{NamedRootFSUpdator}; NamedRootFS.clear(); std::string RootFS = FEXCore::Config::GetDataDirectory() + "RootFS/"; - if (!std::filesystem::exists(RootFS)) { + std::error_code ec{}; + if (!std::filesystem::exists(RootFS, ec)) { // Doesn't exist, create the the folder as a user convenience - if (!std::filesystem::create_directories(RootFS)) { + if (!std::filesystem::create_directories(RootFS, ec)) { // Well I guess we failed return; }