diff options
| author | Stefan Boberg <[email protected]> | 2021-10-29 19:21:33 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-29 19:21:41 +0200 |
| commit | 73a5bec027b5879a9870b156d85343c8a018fe1e (patch) | |
| tree | 2be926bb314bc95bcf950b05a699c2cc96a79243 /zenstore/basicfile.cpp | |
| parent | cas: minor improvement to CasLogFile::Open error handling (diff) | |
| parent | Minor cleanup (diff) | |
| download | zen-73a5bec027b5879a9870b156d85343c8a018fe1e.tar.xz zen-73a5bec027b5879a9870b156d85343c8a018fe1e.zip | |
Merged from main
Diffstat (limited to 'zenstore/basicfile.cpp')
| -rw-r--r-- | zenstore/basicfile.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp index bbb9e1036..9ed70a5ec 100644 --- a/zenstore/basicfile.cpp +++ b/zenstore/basicfile.cpp @@ -2,6 +2,7 @@ #include "zenstore/basicfile.h" +#include <zencore/compactbinary.h> #include <zencore/except.h> #include <zencore/filesystem.h> #include <zencore/fmtutils.h> @@ -266,6 +267,53 @@ TemporaryFile::MoveTemporaryIntoPlace(std::filesystem::path FinalFileName, std:: std::filesystem::rename(m_TempPath, FinalFileName, Ec); } +////////////////////////////////////////////////////////////////////////// + +LockFile::LockFile() +{ +} + +LockFile::~LockFile() +{ +} + +void +LockFile::Create(std::filesystem::path FileName, CbObject Payload, std::error_code& Ec) +{ + Ec.clear(); + + const DWORD dwCreationDisposition = CREATE_ALWAYS; + DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE | DELETE; + const DWORD dwShareMode = FILE_SHARE_READ; + const DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE; + HANDLE hTemplateFile = nullptr; + + HANDLE FileHandle = CreateFile(FileName.c_str(), + dwDesiredAccess, + dwShareMode, + /* lpSecurityAttributes */ nullptr, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); + + if (FileHandle == INVALID_HANDLE_VALUE) + { + Ec = zen::MakeErrorCodeFromLastError(); + + return; + } + + m_FileHandle = FileHandle; + + BasicFile::Write(Payload.GetBuffer(), 0, Ec); +} + +void +LockFile::Update(CbObject Payload, std::error_code& Ec) +{ + BasicFile::Write(Payload.GetBuffer(), 0, Ec); +} + /* ___________ __ \__ ___/___ _______/ |_ ______ |