diff --git a/Include/Aurora/IO/FS/FS.hpp b/Include/Aurora/IO/FS/FS.hpp index 4b1cec2d..c8961c5f 100644 --- a/Include/Aurora/IO/FS/FS.hpp +++ b/Include/Aurora/IO/FS/FS.hpp @@ -56,4 +56,5 @@ namespace Aurora::IO::FS #include "IAsyncFileStream.hpp" #include "IAsyncFinishedSubscriber.hpp" #include "IAsyncTransaction.hpp" -#include "Async.hpp" \ No newline at end of file +#include "Async.hpp" +#include "Watcher.hpp" \ No newline at end of file diff --git a/Include/Aurora/IO/FS/IFileStream.hpp b/Include/Aurora/IO/FS/IFileStream.hpp index a69d69da..bc8311fb 100644 --- a/Include/Aurora/IO/FS/IFileStream.hpp +++ b/Include/Aurora/IO/FS/IFileStream.hpp @@ -60,5 +60,11 @@ namespace Aurora::IO::FS */ virtual void Close() = 0; + + /** + * @brief Indicates that the file should automatically be deleted upon destruction of the stream + */ + virtual void MakeTemporary() = 0; + }; } \ No newline at end of file diff --git a/Source/IO/FS/FileStream.NT.cpp b/Source/IO/FS/FileStream.NT.cpp index 462cb79d..052e5120 100644 --- a/Source/IO/FS/FileStream.NT.cpp +++ b/Source/IO/FS/FileStream.NT.cpp @@ -149,7 +149,7 @@ namespace Aurora::IO::FS if (!::WriteFile(this->handle_, reinterpret_cast(parameters.ptr) + offset, blockSize, &written, NULL)) { - AuLogWarn("WriteFileEx IO Error: 0x{:x}, {}", GetLastError(), path_); + AuLogWarn("WriteFileEx IO Error: 0x{:x}, {}", GetLastError(), this->path_); SysPushErrorIO(); return false; } @@ -176,23 +176,38 @@ namespace Aurora::IO::FS void WinFileStream::WriteEoS() { - if (handle_ == INVALID_HANDLE_VALUE) + if (this->handle_ == INVALID_HANDLE_VALUE) { SysPushErrorUninitialized(); return; } - SetEndOfFile(handle_); + SetEndOfFile(this->handle_); } void WinFileStream::Close() { - AuWin32CloseHandle(handle_); + if ((this->handle_ != INVALID_HANDLE_VALUE) && + (this->bShouldDelete)) + { + FILE_DISPOSITION_INFO rm {}; + rm.DeleteFile = true; + if (!SetFileInformationByHandle(this->handle_, _FILE_INFO_BY_HANDLE_CLASS::FileDispositionInfo, &rm, sizeof(rm))) + { + SysPushErrorIO("Couldn't delete temporary file {}", this->path_); + } + } + AuWin32CloseHandle(this->handle_); } void WinFileStream::Flush() { - FlushFileBuffers(handle_); + FlushFileBuffers(this->handle_); + } + + void WinFileStream::MakeTemporary() + { + this->bShouldDelete = true; } AUKN_SYM IFileStream *OpenNew(const AuString &path, EFileOpenMode openMode, EFileAdvisoryLockLevel lock)