[VFS/Posix] Fix Rename to properly handle guest paths
And ensure string_views aren't pointing at freed memory by saving a reference to the result of path_to_utf8
This commit is contained in:
committed by
Radosław Gliński
parent
dce4d38c0a
commit
4b6ac45650
@@ -14,6 +14,7 @@
|
||||
#include "xenia/base/mapped_memory.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/base/utf8.h"
|
||||
#include "xenia/vfs/device.h"
|
||||
#include "xenia/vfs/devices/host_path_device.h"
|
||||
#include "xenia/vfs/devices/host_path_file.h"
|
||||
@@ -121,12 +122,20 @@ bool HostPathEntry::DeleteEntryInternal(Entry* entry) {
|
||||
}
|
||||
}
|
||||
|
||||
void HostPathEntry::RenameEntryInternal(const std::filesystem::path file_path) {
|
||||
void HostPathEntry::RenameEntryInternal(
|
||||
const std::vector<std::string_view>& path_parts) {
|
||||
const std::string relative_path = xe::utf8::join_paths(path_parts);
|
||||
const std::string new_host_path_ = xe::utf8::join_paths(
|
||||
xe::path_to_utf8(((HostPathDevice*)device_)->host_path()),
|
||||
xe::path_to_utf8(file_path));
|
||||
xe::path_to_utf8(static_cast<HostPathDevice*>(device_)->host_path()),
|
||||
relative_path);
|
||||
|
||||
std::filesystem::rename(host_path_, new_host_path_);
|
||||
std::error_code ec;
|
||||
std::filesystem::rename(host_path_, new_host_path_, ec);
|
||||
if (ec) {
|
||||
XELOGE("RenameEntryInternal: Failed to rename '{}' to '{}': {}",
|
||||
xe::path_to_utf8(host_path_), new_host_path_, ec.message());
|
||||
return;
|
||||
}
|
||||
host_path_ = new_host_path_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user