mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-01 16:13:23 +00:00
VFS cleanup, some methods added
VFS::DeleteAll, VFS::GetDirSize, VFS::Exists, VFS::Rename (VFS::RenameFile, VFS::RenameDir removed)
This commit is contained in:
parent
db88c539fb
commit
e18db20630
@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "VFS.h"
|
||||
#include "vfsDir.h"
|
||||
#include "vfsFile.h"
|
||||
#include "vfsDirBase.h"
|
||||
#include "Emu/HDD/HDD.h"
|
||||
#include "vfsDeviceLocalFile.h"
|
||||
@ -168,12 +170,8 @@ bool VFS::CreateDir(const std::string& ps3_path) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
std::unique_ptr<vfsDirBase> res(dev->GetNewDirStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Create(path);
|
||||
}
|
||||
// return dev->create_dir(path);
|
||||
return fs::create_dir(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -185,6 +183,7 @@ bool VFS::CreatePath(const std::string& ps3_path) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
// return dev->create_path(path);
|
||||
return fs::create_path(path);
|
||||
}
|
||||
|
||||
@ -197,12 +196,8 @@ bool VFS::RemoveFile(const std::string& ps3_path) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
std::unique_ptr<vfsFileBase> res(dev->GetNewFileStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Remove(path);
|
||||
}
|
||||
// return dev->remove_file(path);
|
||||
return fs::remove_file(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -214,29 +209,68 @@ bool VFS::RemoveDir(const std::string& ps3_path) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
std::unique_ptr<vfsDirBase> res(dev->GetNewDirStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Remove(path);
|
||||
}
|
||||
// return dev->remove_dir(path);
|
||||
return fs::remove_dir(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void VFS::DeleteAll(const std::string& ps3_path) const
|
||||
{
|
||||
// Delete directory and all its contents recursively
|
||||
for (const auto entry : vfsDir(ps3_path))
|
||||
{
|
||||
if (entry->name == "." || entry->name == "..")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry->flags & DirEntry_TypeFile)
|
||||
{
|
||||
RemoveFile(ps3_path + "/" + entry->name);
|
||||
}
|
||||
|
||||
if (entry->flags & DirEntry_TypeDir)
|
||||
{
|
||||
DeleteAll(ps3_path + "/" + entry->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u64 VFS::GetDirSize(const std::string& ps3_path) const
|
||||
{
|
||||
u64 result = 0;
|
||||
|
||||
for (const auto entry : vfsDir(ps3_path))
|
||||
{
|
||||
if (entry->name == "." || entry->name == "..")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry->flags & DirEntry_TypeFile)
|
||||
{
|
||||
result += entry->size;
|
||||
}
|
||||
|
||||
if (entry->flags & DirEntry_TypeDir)
|
||||
{
|
||||
result += GetDirSize(ps3_path + "/" + entry->name);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool VFS::ExistsFile(const std::string& ps3_path) const
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
std::unique_ptr<vfsFileBase> res(dev->GetNewFileStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Exists(path);
|
||||
}
|
||||
// return dev->is_file(path);
|
||||
return fs::is_file(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -248,18 +282,27 @@ bool VFS::ExistsDir(const std::string& ps3_path) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
std::unique_ptr<vfsDirBase> res(dev->GetNewDirStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->IsExists(path);
|
||||
}
|
||||
// return dev->is_dir(path);
|
||||
return fs::is_dir(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const
|
||||
bool VFS::Exists(const std::string& ps3_path) const
|
||||
{
|
||||
std::string path;
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
// return dev->exists(path);
|
||||
return fs::exists(path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFS::Rename(const std::string& ps3_path_from, const std::string& ps3_path_to) const
|
||||
{
|
||||
std::string path_from, path_to;
|
||||
|
||||
@ -267,32 +310,8 @@ bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_pa
|
||||
{
|
||||
if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to))
|
||||
{
|
||||
std::unique_ptr<vfsFileBase> res(dev->GetNewFileStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Rename(path_from, path_to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFS::RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const
|
||||
{
|
||||
std::string path_from, path_to;
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path_from, path_from))
|
||||
{
|
||||
if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to))
|
||||
{
|
||||
std::unique_ptr<vfsDirBase> res(dev->GetNewDirStream());
|
||||
|
||||
if (res)
|
||||
{
|
||||
return res->Rename(path_from, path_to);
|
||||
}
|
||||
// return dev->rename(dev_, path_from, path_to);
|
||||
return fs::rename(path_from, path_to);
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,6 +326,7 @@ bool VFS::CopyFile(const std::string& ps3_path_from, const std::string& ps3_path
|
||||
{
|
||||
if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to))
|
||||
{
|
||||
// return dev->copy_file(dev_, path_from, path_to, overwrite);
|
||||
return fs::copy_file(path_from, path_to, overwrite);
|
||||
}
|
||||
}
|
||||
@ -320,6 +340,7 @@ bool VFS::TruncateFile(const std::string& ps3_path, u64 length) const
|
||||
|
||||
if (vfsDevice* dev = GetDevice(ps3_path, path))
|
||||
{
|
||||
// return dev->truncate_file(path, length);
|
||||
return fs::truncate_file(path, length);
|
||||
}
|
||||
|
||||
|
@ -81,10 +81,12 @@ struct VFS
|
||||
bool CreatePath(const std::string& ps3_path) const;
|
||||
bool RemoveFile(const std::string& ps3_path) const;
|
||||
bool RemoveDir(const std::string& ps3_path) const;
|
||||
void DeleteAll(const std::string& ps3_path) const;
|
||||
u64 GetDirSize(const std::string& ps3_path) const;
|
||||
bool ExistsFile(const std::string& ps3_path) const;
|
||||
bool ExistsDir(const std::string& ps3_path) const;
|
||||
bool RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const;
|
||||
bool RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const;
|
||||
bool Exists(const std::string& ps3_path) const;
|
||||
bool Rename(const std::string& ps3_path_from, const std::string& ps3_path_to) const;
|
||||
bool CopyFile(const std::string& ps3_path_from, const std::string& ps3_path_to, bool overwrite = true) const;
|
||||
bool TruncateFile(const std::string& ps3_path, u64 length) const;
|
||||
|
||||
|
@ -68,39 +68,6 @@ bool vfsDir::Open(const std::string& path)
|
||||
return !m_entries.empty();
|
||||
}
|
||||
|
||||
bool vfsDir::Create(const std::string& path)
|
||||
{
|
||||
return Emu.GetVFS().CreateDir(path);
|
||||
}
|
||||
|
||||
bool vfsDir::IsExists(const std::string& path) const
|
||||
{
|
||||
auto path_blocks = simplify_path_blocks(path);
|
||||
|
||||
if (path_blocks.empty())
|
||||
return false;
|
||||
|
||||
std::string dir_name = path_blocks[path_blocks.size() - 1];
|
||||
|
||||
for (const auto entry : vfsDir(path + "/.."))
|
||||
{
|
||||
if (!strcmp(entry->name.c_str(), dir_name.c_str()))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfsDir::Rename(const std::string& from, const std::string& to)
|
||||
{
|
||||
return Emu.GetVFS().RenameDir(from, to);
|
||||
}
|
||||
|
||||
bool vfsDir::Remove(const std::string& path)
|
||||
{
|
||||
return Emu.GetVFS().RemoveDir(path);
|
||||
}
|
||||
|
||||
void vfsDir::Close()
|
||||
{
|
||||
m_stream.reset();
|
||||
|
@ -12,12 +12,6 @@ public:
|
||||
|
||||
virtual bool Open(const std::string& path) override;
|
||||
virtual bool IsOpened() const override;
|
||||
virtual bool IsExists(const std::string& path) const override;
|
||||
virtual void Close() override;
|
||||
//virtual std::string GetPath() const override;
|
||||
|
||||
virtual bool Create(const std::string& path) override;
|
||||
//virtual bool Create(const DirEntryInfo& info) override;
|
||||
virtual bool Rename(const std::string& from, const std::string& to) override;
|
||||
virtual bool Remove(const std::string& path) override;
|
||||
};
|
||||
|
@ -14,11 +14,10 @@ vfsDirBase::~vfsDirBase()
|
||||
|
||||
bool vfsDirBase::Open(const std::string& path)
|
||||
{
|
||||
if(IsOpened())
|
||||
if (IsOpened())
|
||||
{
|
||||
Close();
|
||||
|
||||
if(!IsExists(path))
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pos = 0;
|
||||
m_cwd += '/' + path;
|
||||
@ -30,11 +29,6 @@ bool vfsDirBase::IsOpened() const
|
||||
return !m_cwd.empty();
|
||||
}
|
||||
|
||||
bool vfsDirBase::IsExists(const std::string& path) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<DirEntryInfo>& vfsDirBase::GetEntries() const
|
||||
{
|
||||
return m_entries;
|
||||
|
@ -45,15 +45,10 @@ public:
|
||||
|
||||
virtual bool Open(const std::string& path);
|
||||
virtual bool IsOpened() const;
|
||||
virtual bool IsExists(const std::string& path) const;
|
||||
virtual const std::vector<DirEntryInfo>& GetEntries() const;
|
||||
virtual void Close();
|
||||
virtual std::string GetPath() const;
|
||||
|
||||
virtual bool Create(const std::string& path) = 0;
|
||||
//virtual bool Create(const DirEntryInfo& info)=0;
|
||||
virtual bool Rename(const std::string& from, const std::string& to) = 0;
|
||||
virtual bool Remove(const std::string& path) = 0;
|
||||
virtual const DirEntryInfo* Read();
|
||||
virtual const DirEntryInfo* First();
|
||||
|
||||
|
@ -26,21 +26,6 @@ bool vfsFile::Open(const std::string& path, u32 mode)
|
||||
return m_stream && m_stream->IsOpened();
|
||||
}
|
||||
|
||||
bool vfsFile::Exists(const std::string& path)
|
||||
{
|
||||
return m_stream->Exists(path);
|
||||
}
|
||||
|
||||
bool vfsFile::Rename(const std::string& from, const std::string& to)
|
||||
{
|
||||
return m_stream->Rename(from, to);
|
||||
}
|
||||
|
||||
bool vfsFile::Remove(const std::string& path)
|
||||
{
|
||||
return m_stream->Remove(path);
|
||||
}
|
||||
|
||||
bool vfsFile::Close()
|
||||
{
|
||||
m_stream.reset();
|
||||
|
@ -11,9 +11,6 @@ public:
|
||||
vfsFile(const std::string& path, u32 mode = vfsRead);
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode = vfsRead) override;
|
||||
virtual bool Exists(const std::string& path) override;
|
||||
virtual bool Rename(const std::string& from, const std::string& to) override;
|
||||
virtual bool Remove(const std::string& path) override;
|
||||
virtual bool Close() override;
|
||||
|
||||
virtual u64 GetSize() const override;
|
||||
|
@ -24,9 +24,6 @@ public:
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode);
|
||||
virtual bool Close() override;
|
||||
virtual bool Exists(const std::string& path) { return false; }
|
||||
virtual bool Rename(const std::string& from, const std::string& to) { return false; }
|
||||
virtual bool Remove(const std::string& path) { return false; }
|
||||
virtual bool IsOpened() const override { return !m_path.empty(); }
|
||||
|
||||
std::string GetPath() const;
|
||||
|
@ -38,26 +38,6 @@ bool vfsLocalDir::Open(const std::string& path)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfsLocalDir::Create(const std::string& path)
|
||||
{
|
||||
return fs::create_dir(path);
|
||||
}
|
||||
|
||||
bool vfsLocalDir::IsExists(const std::string& path) const
|
||||
{
|
||||
return fs::is_dir(path);
|
||||
}
|
||||
|
||||
bool vfsLocalDir::Rename(const std::string& from, const std::string& to)
|
||||
{
|
||||
return fs::rename(from, to);
|
||||
}
|
||||
|
||||
bool vfsLocalDir::Remove(const std::string& path)
|
||||
{
|
||||
return fs::remove_dir(path);
|
||||
}
|
||||
|
||||
bool vfsLocalDir::IsOpened() const
|
||||
{
|
||||
return m_dir && vfsDirBase::IsOpened();
|
||||
|
@ -13,10 +13,5 @@ public:
|
||||
virtual ~vfsLocalDir();
|
||||
|
||||
virtual bool Open(const std::string& path) override;
|
||||
|
||||
virtual bool Create(const std::string& path) override;
|
||||
virtual bool Rename(const std::string& from, const std::string& to) override;
|
||||
virtual bool Remove(const std::string& path) override;
|
||||
virtual bool IsOpened() const override;
|
||||
virtual bool IsExists(const std::string& path) const override;
|
||||
};
|
||||
|
@ -47,18 +47,3 @@ bool vfsLocalFile::IsOpened() const
|
||||
{
|
||||
return m_file && vfsFileBase::IsOpened();
|
||||
}
|
||||
|
||||
bool vfsLocalFile::Exists(const std::string& path)
|
||||
{
|
||||
return fs::is_file(path);
|
||||
}
|
||||
|
||||
bool vfsLocalFile::Rename(const std::string& from, const std::string& to)
|
||||
{
|
||||
return fs::rename(from, to);
|
||||
}
|
||||
|
||||
bool vfsLocalFile::Remove(const std::string& path)
|
||||
{
|
||||
return fs::remove_file(path);
|
||||
}
|
||||
|
@ -11,9 +11,6 @@ public:
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode = vfsRead) override;
|
||||
virtual bool Close() override;
|
||||
virtual bool Exists(const std::string& path) override;
|
||||
virtual bool Rename(const std::string& from, const std::string& to) override;
|
||||
virtual bool Remove(const std::string& path) override;
|
||||
|
||||
virtual u64 GetSize() const override;
|
||||
|
||||
|
@ -158,7 +158,7 @@ public:
|
||||
|
||||
int OpenDir(const std::string& name);
|
||||
|
||||
bool Rename(const std::string& from, const std::string& to) override;
|
||||
bool Rename(const std::string& from, const std::string& to);
|
||||
|
||||
u64 FindFreeBlock();
|
||||
|
||||
|
@ -48,7 +48,7 @@ struct content_permission_t final
|
||||
{
|
||||
if (is_temporary)
|
||||
{
|
||||
// TODO: delete temporary directory and all its contents
|
||||
Emu.GetVFS().DeleteAll("/dev_hdd1/game/" + dir);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -342,7 +342,7 @@ s32 cellGameContentPermit(vm::ptr<char[CELL_GAME_PATH_MAX]> contentInfoPath, vm:
|
||||
const std::string dir = "/dev_hdd0/game/" + path_set->dir;
|
||||
|
||||
// make temporary directory persistent
|
||||
if (Emu.GetVFS().RenameDir("/dev_hdd1/game/" + path_set->dir, dir))
|
||||
if (Emu.GetVFS().Rename("/dev_hdd1/game/" + path_set->dir, dir))
|
||||
{
|
||||
cellGame.Success("cellGameContentPermit(): '%s' directory created", dir);
|
||||
}
|
||||
|
@ -388,31 +388,13 @@ s32 sys_fs_rename(vm::cptr<char> from, vm::cptr<char> to)
|
||||
sys_fs.Warning("*** from = '%s'", from.get_ptr());
|
||||
sys_fs.Warning("*** to = '%s'", to.get_ptr());
|
||||
|
||||
std::string ps3_path = from.get_ptr();
|
||||
|
||||
if (Emu.GetVFS().ExistsDir(ps3_path))
|
||||
if (!Emu.GetVFS().Rename(from.get_ptr(), to.get_ptr()))
|
||||
{
|
||||
if (!Emu.GetVFS().RenameDir(ps3_path, to.get_ptr()))
|
||||
{
|
||||
return CELL_FS_EIO; // ???
|
||||
}
|
||||
|
||||
sys_fs.Notice("sys_fs_rename(): directory '%s' renamed to '%s'", from.get_ptr(), to.get_ptr());
|
||||
return CELL_OK;
|
||||
return CELL_FS_ENOENT; // ???
|
||||
}
|
||||
|
||||
if (Emu.GetVFS().ExistsFile(ps3_path))
|
||||
{
|
||||
if (!Emu.GetVFS().RenameFile(ps3_path, to.get_ptr()))
|
||||
{
|
||||
return CELL_FS_EIO; // ???
|
||||
}
|
||||
|
||||
sys_fs.Notice("sys_fs_rename(): file '%s' renamed to '%s'", from.get_ptr(), to.get_ptr());
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
return CELL_FS_ENOENT;
|
||||
sys_fs.Notice("sys_fs_rename(): '%s' renamed to '%s'", from.get_ptr(), to.get_ptr());
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
s32 sys_fs_rmdir(vm::cptr<char> path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user