From 5d12f1a203ff731b685c0163ad62671857b34f4d Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Mon, 18 Sep 2023 07:11:34 +0100 Subject: [PATCH] [*] Resolve IO regressions (4. Hello FS) (Mostly UNIX) --- Source/IO/FS/FS.Unix.cpp | 3 +-- Source/IO/FS/FileStream.Unix.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Source/IO/FS/FS.Unix.cpp b/Source/IO/FS/FS.Unix.cpp index e769dbc2..bbfdfa0f 100755 --- a/Source/IO/FS/FS.Unix.cpp +++ b/Source/IO/FS/FS.Unix.cpp @@ -265,12 +265,11 @@ namespace Aurora::IO::FS SysPushErrorIO(); return false; } - + // NOTE: File devices love to lie // Do not entertain an arbitrarily large page length provided by non-regular fds buffer.writePtr += uLength; - if (bIsZero) { AuTryDownsize(buffer, uLength); diff --git a/Source/IO/FS/FileStream.Unix.cpp b/Source/IO/FS/FileStream.Unix.cpp index d86254e1..55267f1c 100755 --- a/Source/IO/FS/FileStream.Unix.cpp +++ b/Source/IO/FS/FileStream.Unix.cpp @@ -38,7 +38,6 @@ namespace Aurora::IO::FS #else #error accient 32-bit posix operating systems require 64-bit file awareness #endif - if (ret < 0) { //SysPushErrorIO("PosixLseek63 IO Error: %i", ret); @@ -56,7 +55,7 @@ namespace Aurora::IO::FS static AuUInt64 PosixGetOffset(int fd) { AuUInt64 ret; - if (!PosixLseek63(fd, 0, SEEK_SET, &ret)) + if (!PosixLseek63(fd, 0, SEEK_CUR, &ret)) { return 0; } @@ -73,14 +72,13 @@ namespace Aurora::IO::FS AuUInt64 ret {}, old {}; bool status {}; - if (!PosixLseek63(fd, 0, SEEK_SET, &old)) + if (!PosixLseek63(fd, 0, SEEK_CUR, &old)) { return 0; } status = PosixLseek63(fd, 0, SEEK_END, &ret); status &= PosixLseek63(fd, old, SEEK_SET, nullptr); - return status ? ret : 0; } @@ -105,7 +103,7 @@ namespace Aurora::IO::FS bool PosixWrite(int fd, const void *buf, AuUInt32 count, AuUInt32 *pWritten) { auto ret = write(fd, buf, count); - + if (ret < 0) { SysPushErrorIO("PosixWrite IO Error: %i", ret); @@ -238,6 +236,7 @@ namespace Aurora::IO::FS AU_LOCK_GUARD(this->spinlock_); parameters.outVariable = 0; + if (!this->pHandle_) { @@ -378,7 +377,7 @@ namespace Aurora::IO::FS return; } - ::ftruncate(fd, GetOffset()); + ::ftruncate(fd, PosixGetOffset(fd)); } void PosixFileStream::MakeTemporary()