mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-30 14:04:55 +00:00
Revert truncate fix
Using ftruncate works fine after moving the call to before the proper file opening code.
This commit is contained in:
parent
8e42dd2a07
commit
86fde87161
@ -330,7 +330,7 @@ bool IOFile::Commit() const {
|
||||
return commit_result;
|
||||
}
|
||||
|
||||
bool IOFile::SetSize(const char* host_path, u64 size) const {
|
||||
bool IOFile::SetSize(u64 size) const {
|
||||
if (!IsOpen()) {
|
||||
return false;
|
||||
}
|
||||
@ -340,7 +340,7 @@ bool IOFile::SetSize(const char* host_path, u64 size) const {
|
||||
#ifdef _WIN32
|
||||
const auto set_size_result = _chsize_s(fileno(file), static_cast<s64>(size)) == 0;
|
||||
#else
|
||||
const auto set_size_result = truncate(host_path, static_cast<s64>(size)) == 0;
|
||||
const auto set_size_result = ftruncate(fileno(file), static_cast<s64>(size)) == 0;
|
||||
#endif
|
||||
|
||||
if (!set_size_result) {
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
bool Flush() const;
|
||||
bool Commit() const;
|
||||
|
||||
bool SetSize(const char* host_path, u64 size) const;
|
||||
bool SetSize(u64 size) const;
|
||||
u64 GetSize() const;
|
||||
|
||||
bool Seek(s64 offset, SeekOrigin origin = SeekOrigin::SetOrigin) const;
|
||||
|
@ -181,7 +181,7 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
// Start by opening as read-write so we can truncate on all platforms.
|
||||
// Start by opening as read-write so we can truncate regardless of flags.
|
||||
// Since open starts by closing the file, this won't interfere with later open calls.
|
||||
e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::ReadWrite);
|
||||
|
||||
@ -194,7 +194,7 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
|
||||
return -1;
|
||||
} else if (truncate && e == 0) {
|
||||
// If the file was opened successfully and truncate was enabled, reduce size to 0
|
||||
file->f.SetSize(file->m_host_name.string().c_str(), 0);
|
||||
file->f.SetSize(0);
|
||||
}
|
||||
|
||||
if (read) {
|
||||
@ -705,7 +705,7 @@ s32 PS4_SYSV_ABI posix_ftruncate(s32 fd, s64 length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->f.SetSize(file->m_host_name.string().c_str(), length);
|
||||
file->f.SetSize(length);
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user