Remove fs::file::set_delete

Since it's Windows-only functionality with limited use.
This commit is contained in:
Nekotekina 2019-11-08 00:18:16 +03:00
parent d6087978b5
commit 742bd633d8
4 changed files with 13 additions and 17 deletions

View File

@ -1328,15 +1328,6 @@ fs::native_handle fs::file::get_handle() const
#endif
}
#ifdef _WIN32
bool fs::file::set_delete(bool autodelete) const
{
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = autodelete;
return SetFileInformationByHandle(get_handle(), FileDispositionInfo, &disp, sizeof(disp)) != 0;
}
#endif
void fs::dir::xnull() const
{
fmt::throw_exception<std::logic_error>("fs::dir is null");

View File

@ -377,11 +377,6 @@ namespace fs
if (!m_file) xnull();
return m_file->write_gather(buffers, buf_count);
}
#ifdef _WIN32
// Windows-specific function
bool set_delete(bool autodelete = true) const;
#endif
};
class dir final

View File

@ -415,7 +415,9 @@ logs::file_writer::file_writer(const std::string& name)
#ifdef _WIN32
// Autodelete compressed log file
m_fout2.set_delete();
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = true;
SetFileInformationByHandle(m_fout2.get_handle(), FileDispositionInfo, &disp, sizeof(disp));
#endif
}
catch (const std::exception& e)
@ -495,7 +497,9 @@ logs::file_writer::~file_writer()
#ifdef _WIN32
// Cancel compressed log file autodeletion
m_fout2.set_delete(false);
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = false;
SetFileInformationByHandle(m_fout2.get_handle(), FileDispositionInfo, &disp, sizeof(disp));
UnmapViewOfFile(m_fptr);
CloseHandle(m_fmap);

View File

@ -6,6 +6,10 @@
#include "Utilities/mutex.h"
#include "Utilities/StrUtil.h"
#ifdef _WIN32
#include <Windows.h>
#endif
struct vfs_directory
{
// Real path (empty if root or not exists)
@ -599,7 +603,9 @@ bool vfs::host::unlink(const std::string& path, const std::string& dev_root)
if (fs::file f{dummy, fs::read + fs::write})
{
// Set to delete on close on last handle
f.set_delete();
FILE_DISPOSITION_INFO disp;
disp.DeleteFileW = true;
SetFileInformationByHandle(f.get_handle(), FileDispositionInfo, &disp, sizeof(disp));
return true;
}