diff options
| author | Stefan Boberg <[email protected]> | 2021-05-21 20:40:09 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-21 20:40:09 +0200 |
| commit | 83e3c364e6403883cd60e7dda10165b6e84269f3 (patch) | |
| tree | dc190b846bc73968988690880cdf1f5f8f6aaeb0 | |
| parent | Merge branch 'jupiter-structured' of https://github.com/EpicGames/zen into ju... (diff) | |
| download | zen-83e3c364e6403883cd60e7dda10165b6e84269f3.tar.xz zen-83e3c364e6403883cd60e7dda10165b6e84269f3.zip | |
Moved CasBlobFile into basicfile.h
| -rw-r--r-- | zenserver/projectstore.cpp | 1 | ||||
| -rw-r--r-- | zenstore/basicfile.cpp | 85 | ||||
| -rw-r--r-- | zenstore/caslog.cpp | 74 | ||||
| -rw-r--r-- | zenstore/compactcas.h | 1 | ||||
| -rw-r--r-- | zenstore/include/zenstore/basicfile.h | 30 | ||||
| -rw-r--r-- | zenstore/include/zenstore/caslog.h | 20 | ||||
| -rw-r--r-- | zenstore/zenstore.vcxproj | 2 | ||||
| -rw-r--r-- | zenstore/zenstore.vcxproj.filters | 6 |
8 files changed, 125 insertions, 94 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 8753d50fc..e30742e33 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -13,6 +13,7 @@ #include <zencore/windows.h> #include <zenstore/cas.h> #include <zenstore/caslog.h> +#include <zenstore/basicfile.h> #pragma comment(lib, "Rpcrt4.lib") // RocksDB made me do this #include <rocksdb/db.h> diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp new file mode 100644 index 000000000..961e43735 --- /dev/null +++ b/zenstore/basicfile.cpp @@ -0,0 +1,85 @@ +#include "zenstore/basicfile.h" + +#include <zencore/filesystem.h> +#include <zencore/fmtutils.h> + +#include <fmt/format.h> +#include <gsl/gsl-lite.hpp> + +namespace zen { + +using namespace fmt::literals; + +void +CasBlobFile::Open(std::filesystem::path FileName, bool isCreate) +{ + const DWORD dwCreationDisposition = isCreate ? CREATE_ALWAYS : OPEN_EXISTING; + + HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition); + + if (FAILED(hRes)) + { + throw std::system_error(GetLastError(), std::system_category(), "Failed to open bucket sobs file '{}'"_format(FileName)); + } +} + +void +CasBlobFile::Read(void* Data, uint64_t Size, uint64_t Offset) +{ + OVERLAPPED Ovl{}; + + Ovl.Offset = DWORD(Offset & 0xffff'ffffu); + Ovl.OffsetHigh = DWORD(Offset >> 32); + + HRESULT hRes = m_File.Read(Data, gsl::narrow<DWORD>(Size), &Ovl); + + if (FAILED(hRes)) + { + throw std::system_error(GetLastError(), + std::system_category(), + "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File))); + } +} + +IoBuffer +CasBlobFile::ReadAll() +{ + IoBuffer Buffer(FileSize()); + + Read((void*)Buffer.Data(), Buffer.Size(), 0); + + return Buffer; +} + +void +CasBlobFile::Write(const void* Data, uint64_t Size, uint64_t Offset) +{ + OVERLAPPED Ovl{}; + + Ovl.Offset = DWORD(Offset & 0xffff'ffffu); + Ovl.OffsetHigh = DWORD(Offset >> 32); + + HRESULT hRes = m_File.Write(Data, gsl::narrow<DWORD>(Size), &Ovl); + + if (FAILED(hRes)) + { + throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File))); + } +} + +void +CasBlobFile::Flush() +{ + m_File.Flush(); +} + +uint64_t +CasBlobFile::FileSize() +{ + ULONGLONG Sz; + m_File.GetSize(Sz); + + return uint64_t(Sz); +} + +} diff --git a/zenstore/caslog.cpp b/zenstore/caslog.cpp index c648cea5e..4b9aacb42 100644 --- a/zenstore/caslog.cpp +++ b/zenstore/caslog.cpp @@ -152,78 +152,4 @@ CasLogFile::Flush() m_File.Flush(); } -////////////////////////////////////////////////////////////////////////// - -void -CasBlobFile::Open(std::filesystem::path FileName, bool isCreate) -{ - const DWORD dwCreationDisposition = isCreate ? CREATE_ALWAYS : OPEN_EXISTING; - - HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition); - - if (FAILED(hRes)) - { - throw std::system_error(GetLastError(), std::system_category(), "Failed to open bucket sobs file '{}'"_format(FileName)); - } -} - -void -CasBlobFile::Read(void* Data, uint64_t Size, uint64_t Offset) -{ - OVERLAPPED Ovl{}; - - Ovl.Offset = DWORD(Offset & 0xffff'ffffu); - Ovl.OffsetHigh = DWORD(Offset >> 32); - - HRESULT hRes = m_File.Read(Data, gsl::narrow<DWORD>(Size), &Ovl); - - if (FAILED(hRes)) - { - throw std::system_error(GetLastError(), - std::system_category(), - "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File))); - } -} - -IoBuffer -CasBlobFile::ReadAll() -{ - IoBuffer Buffer(FileSize()); - - Read((void*)Buffer.Data(), Buffer.Size(), 0); - - return Buffer; -} - -void -CasBlobFile::Write(const void* Data, uint64_t Size, uint64_t Offset) -{ - OVERLAPPED Ovl{}; - - Ovl.Offset = DWORD(Offset & 0xffff'ffffu); - Ovl.OffsetHigh = DWORD(Offset >> 32); - - HRESULT hRes = m_File.Write(Data, gsl::narrow<DWORD>(Size), &Ovl); - - if (FAILED(hRes)) - { - throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File))); - } -} - -void -CasBlobFile::Flush() -{ - m_File.Flush(); -} - -uint64_t -CasBlobFile::FileSize() -{ - ULONGLONG Sz; - m_File.GetSize(Sz); - - return uint64_t(Sz); -} - } // namespace zen diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h index 4d318c2e2..abea83dbd 100644 --- a/zenstore/compactcas.h +++ b/zenstore/compactcas.h @@ -12,6 +12,7 @@ #include <zencore/windows.h> #include <zenstore/cas.h> #include <zenstore/caslog.h> +#include <zenstore/basicfile.h> #include <atlfile.h> #include <functional> diff --git a/zenstore/include/zenstore/basicfile.h b/zenstore/include/zenstore/basicfile.h new file mode 100644 index 000000000..e3d218a78 --- /dev/null +++ b/zenstore/include/zenstore/basicfile.h @@ -0,0 +1,30 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include <zencore/zencore.h> +#include <zencore/iobuffer.h> + +#include <zencore/windows.h> + +#include <atlfile.h> +#include <filesystem> + +namespace zen { + +class CasBlobFile +{ +public: + void Open(std::filesystem::path FileName, bool IsCreate); + void Read(void* Data, uint64_t Size, uint64_t Offset); + void Write(const void* Data, uint64_t Size, uint64_t Offset); + void Flush(); + uint64_t FileSize(); + void* Handle() { return m_File; } + IoBuffer ReadAll(); + +private: + CAtlFile m_File; +}; + +} // namespace zen diff --git a/zenstore/include/zenstore/caslog.h b/zenstore/include/zenstore/caslog.h index b318577d7..95282b5fb 100644 --- a/zenstore/include/zenstore/caslog.h +++ b/zenstore/include/zenstore/caslog.h @@ -73,24 +73,4 @@ public: void Open(std::filesystem::path FileName, bool IsCreate) { CasLogFile::Open(FileName, sizeof(T), IsCreate); } }; -////////////////////////////////////////////////////////////////////////// -// -// This should go in its own header -// - -class CasBlobFile -{ -public: - void Open(std::filesystem::path FileName, bool IsCreate); - void Read(void* Data, uint64_t Size, uint64_t Offset); - void Write(const void* Data, uint64_t Size, uint64_t Offset); - void Flush(); - uint64_t FileSize(); - void* Handle() { return m_File; } - IoBuffer ReadAll(); - -private: - CAtlFile m_File; -}; - } // namespace zen diff --git a/zenstore/zenstore.vcxproj b/zenstore/zenstore.vcxproj index 06cb9db32..5384bf3eb 100644 --- a/zenstore/zenstore.vcxproj +++ b/zenstore/zenstore.vcxproj @@ -11,6 +11,7 @@ </ProjectConfiguration> </ItemGroup> <ItemGroup> + <ClCompile Include="basicfile.cpp" /> <ClCompile Include="CAS.cpp" /> <ClCompile Include="caslog.cpp" /> <ClCompile Include="compactcas.cpp" /> @@ -21,6 +22,7 @@ <ItemGroup> <ClInclude Include="compactcas.h" /> <ClInclude Include="filecas.h" /> + <ClInclude Include="include\zenstore\basicfile.h" /> <ClInclude Include="include\zenstore\gc.h" /> <ClInclude Include="include\zenstore\scrub.h" /> <ClInclude Include="include\zenstore\CAS.h" /> diff --git a/zenstore/zenstore.vcxproj.filters b/zenstore/zenstore.vcxproj.filters index 6ab5a7cb2..8f08ca6cf 100644 --- a/zenstore/zenstore.vcxproj.filters +++ b/zenstore/zenstore.vcxproj.filters @@ -5,11 +5,17 @@ <ClCompile Include="caslog.cpp" /> <ClCompile Include="compactcas.cpp" /> <ClCompile Include="filecas.cpp" /> + <ClCompile Include="gc.cpp" /> + <ClCompile Include="scrub.cpp" /> + <ClCompile Include="basicfile.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="compactcas.h" /> <ClInclude Include="filecas.h" /> <ClInclude Include="include\zenstore\CAS.h" /> <ClInclude Include="include\zenstore\caslog.h" /> + <ClInclude Include="include\zenstore\gc.h" /> + <ClInclude Include="include\zenstore\scrub.h" /> + <ClInclude Include="include\zenstore\basicfile.h" /> </ItemGroup> </Project>
\ No newline at end of file |