[+] MakeTemporary

This commit is contained in:
Reece Wilson 2022-04-02 19:14:24 +01:00
parent ce62600e18
commit a31136a5d4
3 changed files with 28 additions and 6 deletions

View File

@ -56,4 +56,5 @@ namespace Aurora::IO::FS
#include "IAsyncFileStream.hpp"
#include "IAsyncFinishedSubscriber.hpp"
#include "IAsyncTransaction.hpp"
#include "Async.hpp"
#include "Async.hpp"
#include "Watcher.hpp"

View File

@ -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;
};
}

View File

@ -149,7 +149,7 @@ namespace Aurora::IO::FS
if (!::WriteFile(this->handle_, reinterpret_cast<const char *>(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)