Commit bbc06771 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Remove some more unused VFS functions

parent f544ac68
Pipeline #44230 passed with stage
in 43 seconds
......@@ -66,123 +66,6 @@ Stream* NativeVFS::open(const std::string& path, const uint32 mode, const bool t
}
}
bool NativeVFS::unlink(const std::string& path, const bool throw_on_noent, const CanaryType canary)
{
if(canary != CanaryType::unlink)
_exit(-1);
if(path.find('\0') != std::string::npos)
throw MDFN_Error(EINVAL, _("Error unlinking \"%s\": %s"), path.c_str(), _("Null character in path."));
#ifdef WIN32
bool invalid_utf8;
std::u16string u16path = UTF8_to_UTF16(path, &invalid_utf8, true);
if(invalid_utf8)
throw MDFN_Error(EINVAL, _("Error unlinking \"%s\": %s"), path.c_str(), _("Invalid UTF-8"));
if(::_wunlink((const wchar_t*)u16path.c_str()))
#else
if(::unlink(path.c_str()))
#endif
{
ErrnoHolder ene(errno);
if(ene.Errno() == ENOENT && !throw_on_noent)
return false;
else
throw MDFN_Error(ene.Errno(), _("Error unlinking \"%s\": %s"), path.c_str(), ene.StrError());
}
return true;
}
void NativeVFS::rename(const std::string& oldpath, const std::string& newpath, const CanaryType canary)
{
if(canary != CanaryType::rename)
_exit(-1);
if(oldpath.find('\0') != std::string::npos || newpath.find('\0') != std::string::npos)
throw MDFN_Error(EINVAL, _("Error renaming \"%s\" to \"%s\": %s"), oldpath.c_str(), newpath.c_str(), _("Null character in path."));
#ifdef WIN32
bool invalid_utf8_old;
bool invalid_utf8_new;
std::u16string u16oldpath = UTF8_to_UTF16(oldpath, &invalid_utf8_old, true);
std::u16string u16newpath = UTF8_to_UTF16(newpath, &invalid_utf8_new, true);
if(invalid_utf8_old || invalid_utf8_new)
throw MDFN_Error(EINVAL, _("Error renaming \"%s\" to \"%s\": %s"), oldpath.c_str(), newpath.c_str(), _("Invalid UTF-8"));
if(::_wrename((const wchar_t*)u16oldpath.c_str(), (const wchar_t*)u16newpath.c_str()))
{
ErrnoHolder ene(errno);
// TODO/FIXME: Ensure oldpath and newpath don't refer to the same file via symbolic link.
if(oldpath != newpath && (ene.Errno() == EACCES || ene.Errno() == EEXIST))
{
if(::_wunlink((const wchar_t*)u16newpath.c_str()) || _wrename((const wchar_t*)u16oldpath.c_str(), (const wchar_t*)u16newpath.c_str()))
throw MDFN_Error(ene.Errno(), _("Error renaming \"%s\" to \"%s\": %s"), oldpath.c_str(), newpath.c_str(), ene.StrError());
}
else
throw MDFN_Error(ene.Errno(), _("Error renaming \"%s\" to \"%s\": %s"), oldpath.c_str(), newpath.c_str(), ene.StrError());
}
#else
if(::rename(oldpath.c_str(), newpath.c_str()))
{
ErrnoHolder ene(errno);
throw MDFN_Error(ene.Errno(), _("Error renaming \"%s\" to \"%s\": %s"), oldpath.c_str(), newpath.c_str(), ene.StrError());
}
#endif
}
bool NativeVFS::finfo(const std::string& path, FileInfo* fi, const bool throw_on_noent)
{
if(path.find('\0') != std::string::npos)
throw MDFN_Error(EINVAL, _("Error getting file information for \"%s\": %s"), path.c_str(), _("Null character in path."));
//
//
#ifdef WIN32
bool invalid_utf8;
std::u16string u16path = UTF8_to_UTF16(path, &invalid_utf8, true);
struct _stati64 buf;
if(invalid_utf8)
throw MDFN_Error(EINVAL, _("Error getting file information for \"%s\": %s"), path.c_str(), _("Invalid UTF-8"));
if(::_wstati64((const wchar_t*)u16path.c_str(), &buf))
#else
struct stat buf;
if(::stat(path.c_str(), &buf))
#endif
{
ErrnoHolder ene(errno);
if(ene.Errno() == ENOENT && !throw_on_noent)
return false;
throw MDFN_Error(ene.Errno(), _("Error getting file information for \"%s\": %s"), path.c_str(), ene.StrError());
}
if(fi)
{
FileInfo new_fi;
new_fi.size = buf.st_size;
new_fi.mtime_us = (int64)buf.st_mtime * 1000 * 1000;
new_fi.is_regular = S_ISREG(buf.st_mode);
new_fi.is_directory = S_ISDIR(buf.st_mode);
*fi = new_fi;
}
return true;
}
void NativeVFS::readdirentries(const std::string& path, std::function<bool(const std::string&)> callb)
{
if(path.find('\0') != std::string::npos)
......
......@@ -33,9 +33,6 @@ class NativeVFS final : public VirtualFS
virtual ~NativeVFS() override;
virtual Stream* open(const std::string& path, const uint32 mode, const bool throw_on_noent = true, const CanaryType canary = CanaryType::open) override;
virtual bool unlink(const std::string& path, const bool throw_on_noent = false, const CanaryType canary = CanaryType::unlink) override;
virtual void rename(const std::string& oldpath, const std::string& newpath, const CanaryType canary = CanaryType::rename) override;
virtual bool finfo(const std::string& path, FileInfo*, const bool throw_on_noent = true) override;
virtual void readdirentries(const std::string& path, std::function<bool(const std::string&)> callb) override;
virtual bool is_absolute_path(const std::string& path) override;
......
......@@ -19,17 +19,6 @@
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
struct FileInfo
{
uint64 size;
};
// Returns false if file doesn't exist(and fi is unmodified), throws on other errors?
bool finfo(FileInfo* fi);
*/
#include <mednafen/mednafen.h>
#include <mednafen/VirtualFS.h>
......
......@@ -62,9 +62,7 @@ class VirtualFS
// Probably not necessary, but virtual functions make me a little uneasy. ;)
enum class CanaryType : uint64
{
open = 0xA8D4C7D433EC0BC9ULL,
unlink = 0xCBE552428A86F001ULL,
rename = 0x4C8642D1246B775DULL
open = 0xA8D4C7D433EC0BC9ULL
};
public:
......@@ -72,15 +70,6 @@ class VirtualFS
// Otherwise, will return nullptr if the file doesn't exist/wasn't found.
virtual Stream* open(const std::string& path, const uint32 mode, const bool throw_on_noent = true, const CanaryType canary = CanaryType::open) = 0;
// Returns true if the file was unlinked successfully, false if the file didn't exist(unless throw_on_noent is true), and throws on other errors.
virtual bool unlink(const std::string& path, const bool throw_on_noent = false, const CanaryType canary = CanaryType::unlink) = 0;
// Renames file at oldpath to newpath. Will replace file at newpath if it already exists. On Windows, it will not be atomic, and oldpath will end up deleted
// if oldpath and newpath refer to the same underlying file via symlink shenanigans, so be careful in how it's used.
//
// Throws on error.
virtual void rename(const std::string& oldpath, const std::string& newpath, const CanaryType canary = CanaryType::rename) = 0;
struct FileInfo
{
INLINE FileInfo() : size(0), mtime_us(0), is_regular(false), is_directory(false) { }
......@@ -91,8 +80,6 @@ class VirtualFS
bool is_directory : 1; // Is directory.
};
virtual bool finfo(const std::string& path, FileInfo*, const bool throw_on_noent = true) = 0;
virtual void readdirentries(const std::string& path, std::function<bool(const std::string&)> callb) = 0;
//
......@@ -100,7 +87,6 @@ class VirtualFS
//
virtual bool is_absolute_path(const std::string& path);
virtual bool is_path_separator(const char c);
//virtual bool is_driverel_path(const std::string& path) = 0;
//
// Note: It IS permissible for an output to point to the same string as the file_path reference.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment