diff --git a/source/lib/file/vfs/vfs_lookup.cpp b/source/lib/file/vfs/vfs_lookup.cpp index 5535cabbc7..0b0681ae6e 100644 --- a/source/lib/file/vfs/vfs_lookup.cpp +++ b/source/lib/file/vfs/vfs_lookup.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -38,40 +38,26 @@ #include "lib/os_path.h" #include "lib/path.h" #include "lib/posix/posix_filesystem.h" -#include "lib/sysdep/filesystem.h" -#include +#include #include +#include -static Status CreateDirectory(const OsPath& path) +static Status CreateDirectory(const OsPath& dirpath) { - { - const mode_t mode = S_IRWXU; // 0700 as prescribed by XDG basedir - const int ret = wmkdir(path, mode); - if(ret == 0) // success - return INFO::OK; - } + const std::filesystem::path path{dirpath.string()}; + std::error_code ec{}; - // Failed because the directory already exists. - // Return 'success' to attach the existing directory. - if(errno == EEXIST) - { - // But first ensure it's really a directory - // (otherwise, a file is "in the way" and needs to be deleted). - struct stat s; - const int ret = wstat(path, &s); - ENSURE(ret == 0); // (wmkdir said it existed) - ENSURE(S_ISDIR(s.st_mode)); + if (std::filesystem::is_directory(path)) return INFO::OK; - } - if (errno == EACCES) - return ERR::FILE_ACCESS; + std::filesystem::create_directory(path, ec); + if (ec) + return StatusFromSystemError(ec); - // unexpected failure - debug_printf("wmkdir failed with errno=%d\n", errno); - DEBUG_WARN_ERR(ERR::LOGIC); - WARN_RETURN(StatusFromErrno()); + // 0700 as prescribed by XDG basedir + std::filesystem::permissions(path, std::filesystem::perms::owner_all, ec); + return StatusFromSystemError(ec); } diff --git a/source/lib/sysdep/filesystem.h b/source/lib/sysdep/filesystem.h index 7d0c72f059..e2c21d35b1 100644 --- a/source/lib/sysdep/filesystem.h +++ b/source/lib/sysdep/filesystem.h @@ -60,8 +60,6 @@ extern int wclose(int fd); // sys/stat.h // -int wstat(const OsPath& pathname, struct stat* buf); - int wmkdir(const OsPath& path, mode_t mode); #endif // #ifndef INCLUDED_SYSDEP_FILESYSTEM diff --git a/source/lib/sysdep/os/unix/ufilesystem.cpp b/source/lib/sysdep/os/unix/ufilesystem.cpp index 9444390c1d..60631ad354 100644 --- a/source/lib/sysdep/os/unix/ufilesystem.cpp +++ b/source/lib/sysdep/os/unix/ufilesystem.cpp @@ -98,11 +98,6 @@ int wrename(const OsPath& pathnameOld, const OsPath& pathnameNew) return rename(OsString(pathnameOld).c_str(), OsString(pathnameNew).c_str()); } -int wstat(const OsPath& pathname, struct stat* buf) -{ - return stat(OsString(pathname).c_str(), buf); -} - int wmkdir(const OsPath& path, mode_t mode) { return mkdir(OsString(path).c_str(), mode); diff --git a/source/lib/sysdep/os/win/wposix/wfilesystem.cpp b/source/lib/sysdep/os/win/wposix/wfilesystem.cpp index 6bbe3b88b9..66a48b6704 100644 --- a/source/lib/sysdep/os/win/wposix/wfilesystem.cpp +++ b/source/lib/sysdep/os/win/wposix/wfilesystem.cpp @@ -160,9 +160,3 @@ int wmkdir(const OsPath& path, mode_t) return 0; } - - -int wstat(const OsPath& pathname, struct stat* buf) -{ - return _wstat64(OsString(pathname).c_str(), buf); -} diff --git a/source/lib/sysdep/tests/test_sysdep.h b/source/lib/sysdep/tests/test_sysdep.h index 657de94037..c6916158d3 100644 --- a/source/lib/sysdep/tests/test_sysdep.h +++ b/source/lib/sysdep/tests/test_sysdep.h @@ -37,6 +37,7 @@ #include #include #include +#include #include class TestSysdep : public CxxTest::TestSuite @@ -59,8 +60,7 @@ public: // Check it's absolute TSM_ASSERT(L"Path: "+path.string(), path_is_absolute(path.string().c_str())); // Check the file exists - struct stat s; - TSM_ASSERT_EQUALS(L"Path: "+path.string(), wstat(path, &s), 0); + TS_ASSERT(std::filesystem::is_regular_file(path.string())); } private: