aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'zencore')
-rw-r--r--zencore/compositebuffer.cpp4
-rw-r--r--zencore/filesystem.cpp10
-rw-r--r--zencore/include/zencore/snapshot_manifest.h57
-rw-r--r--zencore/snapshot_manifest.cpp285
-rw-r--r--zencore/zencore.cpp2
-rw-r--r--zencore/zencore.vcxproj2
-rw-r--r--zencore/zencore.vcxproj.filters2
7 files changed, 7 insertions, 355 deletions
diff --git a/zencore/compositebuffer.cpp b/zencore/compositebuffer.cpp
index 0e27e6f0e..3190ca5ea 100644
--- a/zencore/compositebuffer.cpp
+++ b/zencore/compositebuffer.cpp
@@ -90,8 +90,8 @@ CompositeBuffer
CompositeBuffer::Mid(uint64_t Offset, uint64_t Size) const
{
const uint64_t BufferSize = GetSize();
- Offset = zen::Min(Offset, BufferSize);
- Size = zen::Min(Size, BufferSize - Offset);
+ Offset = Min(Offset, BufferSize);
+ Size = Min(Size, BufferSize - Offset);
CompositeBuffer Buffer;
IterateRange(Offset, Size, [&Buffer](MemoryView View, const SharedBuffer& ViewOuter) {
Buffer.m_Segments.push_back(SharedBuffer::MakeView(View, ViewOuter));
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 59300b7ad..45e177aaa 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -406,14 +406,14 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
HRESULT hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
if (hRes == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))
{
- zen::CreateDirectories(Path.parent_path());
+ CreateDirectories(Path.parent_path());
hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
}
if (FAILED(hRes))
{
- zen::ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str());
+ ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str());
}
// TODO: this should be block-enlightened
@@ -425,13 +425,13 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
while (WriteSize)
{
- const uint64_t ChunkSize = zen::Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024);
+ const uint64_t ChunkSize = Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024);
hRes = Outfile.Write(DataPtr, gsl::narrow_cast<uint32_t>(WriteSize));
if (FAILED(hRes))
{
- zen::ThrowSystemException(hRes, "File write failed for '{}'"_format(Path).c_str());
+ ThrowSystemException(hRes, "File write failed for '{}'"_format(Path).c_str());
}
WriteSize -= ChunkSize;
@@ -529,7 +529,7 @@ FileSystemTraversal::TraverseFileSystem(const std::filesystem::path& RootDir, Tr
if (FAILED(hRes))
{
- zen::ThrowSystemException(hRes, "Failed to open handle to volume root");
+ ThrowSystemException(hRes, "Failed to open handle to volume root");
}
while (Continue)
diff --git a/zencore/include/zencore/snapshot_manifest.h b/zencore/include/zencore/snapshot_manifest.h
deleted file mode 100644
index 95e64773a..000000000
--- a/zencore/include/zencore/snapshot_manifest.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#pragma once
-
-#include <zencore/iohash.h>
-#include <zencore/zencore.h>
-
-#include <filesystem>
-#include <functional>
-#include <string>
-#include <vector>
-
-namespace zen {
-
-struct LeafNode
-{
- uint64_t FileSize = 0;
- uint64_t FileModifiedTime = 0;
- zen::IoHash ChunkHash = zen::IoHash::Zero;
- std::wstring Name;
-};
-
-struct TreeNode
-{
- std::vector<TreeNode> Children;
- std::vector<LeafNode> Leaves;
- std::wstring Name;
- zen::BLAKE3 ChunkHash = zen::BLAKE3::Zero;
-
- ZENCORE_API void VisitModifyFiles(std::function<void(LeafNode& node)> func);
- ZENCORE_API void VisitFiles(std::function<void(const LeafNode& node)> func);
- ZENCORE_API void Finalize();
-};
-
-struct SnapshotManifest
-{
- std::string Id;
- TreeNode Root;
- zen::BLAKE3 ChunkHash = zen::BLAKE3::Zero;
-
- ZENCORE_API void finalize();
-};
-
-class InStream;
-class OutStream;
-
-ZENCORE_API void ReadManifest(SnapshotManifest& Manifest, InStream& FromStream);
-ZENCORE_API void WriteManifest(const SnapshotManifest& Manifest, OutStream& ToStream);
-ZENCORE_API void PrintManifest(const SnapshotManifest& Manifest, OutStream& ToStream);
-
-// Translate a user-provided manifest specification into a file path.
-// Supports hashtag syntax to implicitly refer to user documents zenfs folder
-ZENCORE_API std::filesystem::path ManifestSpecToPath(const char* ManifestSpec);
-
-void snapshotmanifest_forcelink();
-
-} // namespace zen
diff --git a/zencore/snapshot_manifest.cpp b/zencore/snapshot_manifest.cpp
deleted file mode 100644
index 6e9945cf0..000000000
--- a/zencore/snapshot_manifest.cpp
+++ /dev/null
@@ -1,285 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#include <zencore/snapshot_manifest.h>
-#include <zencore/stream.h>
-#include <zencore/streamutil.h>
-#include <zencore/string.h>
-#include <zencore/testing.h>
-
-#include <filesystem>
-#include <ostream>
-
-// Used for getting My Documents for default snapshot dir
-#include <ShlObj.h>
-#if ZEN_PLATFORM_WINDOWS
-# pragma comment(lib, "shell32.lib")
-#endif
-
-namespace zen {
-
-constexpr const char* magicString = "-=- ZEN_SNAP -=-";
-
-struct SerializedManifestHeader
-{
- char Magic[16];
-
- void init() { memcpy(Magic, magicString, sizeof Magic); }
- bool verify() const { return memcmp(Magic, magicString, sizeof Magic) == 0; }
-};
-
-TextWriter&
-operator<<(TextWriter& Writer, const LeafNode& Leaf)
-{
- Writer << "modTime: " << Leaf.FileModifiedTime << ", size: " << Leaf.FileSize << ", hash: " << Leaf.ChunkHash << ", name: " << Leaf.Name
- << "\n";
-
- return Writer;
-}
-
-BinaryWriter&
-operator<<(BinaryWriter& Writer, const LeafNode& Leaf)
-{
- Writer << Leaf.FileModifiedTime << Leaf.FileSize << Leaf.ChunkHash << Leaf.Name;
-
- return Writer;
-}
-
-BinaryReader&
-operator>>(BinaryReader& Reader, LeafNode& Leaf)
-{
- Reader >> Leaf.FileModifiedTime >> Leaf.FileSize >> Leaf.ChunkHash >> Leaf.Name;
-
- return Reader;
-}
-
-void
-TreeNode::Finalize()
-{
- zen::BLAKE3Stream Blake3Stream;
-
- for (auto& Node : Children)
- {
- Node.Finalize();
- Blake3Stream.Append(Node.ChunkHash.Hash, sizeof Node.ChunkHash);
- Blake3Stream.Append(Node.Name.data(), Node.Name.size() + 1);
- }
-
- for (auto& leaf : Leaves)
- {
- Blake3Stream.Append(leaf.ChunkHash.Hash, sizeof leaf.ChunkHash);
- Blake3Stream.Append(leaf.Name.data(), leaf.Name.size() + 1);
- }
-
- this->ChunkHash = Blake3Stream.GetHash();
-}
-
-void
-TreeNode::VisitFiles(std::function<void(const LeafNode& node)> func)
-{
- for (auto& Node : Children)
- Node.VisitFiles(func);
-
- for (auto& Leaf : Leaves)
- func(Leaf);
-}
-
-void
-TreeNode::VisitModifyFiles(std::function<void(LeafNode& node)> func)
-{
- for (auto& Node : Children)
- Node.VisitModifyFiles(func);
-
- for (auto& Leaf : Leaves)
- func(Leaf);
-}
-
-IndentTextWriter&
-operator<<(IndentTextWriter& Writer, const TreeNode& Node)
-{
- Writer << "hash: " << Node.ChunkHash << ", name: " << Node.Name << "\n";
-
- if (!Node.Leaves.empty())
- {
- Writer << "files: "
- << "\n";
-
- IndentTextWriter::Scope _(Writer);
-
- for (const LeafNode& Leaf : Node.Leaves)
- Writer << Leaf;
- }
-
- if (!Node.Children.empty())
- {
- Writer << "children: "
- << "\n";
-
- IndentTextWriter::Scope _(Writer);
-
- for (const TreeNode& Child : Node.Children)
- {
- Writer << Child;
- }
- }
-
- return Writer;
-}
-
-BinaryWriter&
-operator<<(BinaryWriter& Writer, const TreeNode& Node)
-{
- Writer << Node.ChunkHash << Node.Name;
- Writer << uint32_t(Node.Children.size());
-
- for (const TreeNode& child : Node.Children)
- Writer << child;
-
- Writer << uint32_t(Node.Leaves.size());
-
- for (const LeafNode& Leaf : Node.Leaves)
- Writer << Leaf;
-
- return Writer;
-}
-
-BinaryReader&
-operator>>(BinaryReader& Reader, TreeNode& Node)
-{
- Reader >> Node.ChunkHash >> Node.Name;
-
- uint32_t ChildCount = 0;
- Reader >> ChildCount;
- Node.Children.resize(ChildCount);
-
- for (TreeNode& Child : Node.Children)
- Reader >> Child;
-
- uint32_t LeafCount = 0;
- Reader >> LeafCount;
- Node.Leaves.resize(LeafCount);
-
- for (LeafNode& Leaf : Node.Leaves)
- Reader >> Leaf;
-
- return Reader;
-}
-
-void
-SnapshotManifest::finalize()
-{
- Root.Finalize();
-
- zen::BLAKE3Stream Blake3Stream;
-
- Blake3Stream.Append(Root.ChunkHash.Hash, sizeof Root.ChunkHash);
- Blake3Stream.Append(Root.Name.data(), Root.Name.size() + 1);
-
- this->ChunkHash = Blake3Stream.GetHash();
-}
-
-void
-WriteManifest(const SnapshotManifest& Manifest, OutStream& ToStream)
-{
- BinaryWriter Out(ToStream);
- SerializedManifestHeader Header;
- Header.init();
- Out.Write(&Header, sizeof Header);
-
- Out << Manifest.ChunkHash << Manifest.Id << Manifest.Root;
-}
-
-void
-ReadManifest(SnapshotManifest& Manifest, InStream& FromStream)
-{
- BinaryReader Reader(FromStream);
- SerializedManifestHeader Header;
- Reader.Read(&Header, sizeof Header);
-
- Reader >> Manifest.ChunkHash >> Manifest.Id >> Manifest.Root;
-}
-
-void
-PrintManifest(const SnapshotManifest& Manifest, OutStream& ToStream)
-{
- IndentTextWriter Writer(ToStream);
-
- Writer << "hash: " << Manifest.ChunkHash << "\n";
- Writer << "id: " << Manifest.Id << "\n";
- Writer << "root: "
- << "\n";
- IndentTextWriter::Scope _(Writer);
- Writer << Manifest.Root;
-}
-
-std::filesystem::path
-ManifestSpecToPath(const char* ManifestSpec)
-{
- ExtendableWideStringBuilder<128> ManifestTargetFile;
-
- if (ManifestSpec[0] == '#')
- {
- // Pick sensible default
-
- WCHAR MyDocumentsDir[MAX_PATH];
- HRESULT hRes = SHGetFolderPathW(NULL,
- CSIDL_PERSONAL /* My Documents */,
- NULL,
- SHGFP_TYPE_CURRENT,
- /* out */ MyDocumentsDir);
-
- if (SUCCEEDED(hRes))
- {
- wcscat_s(MyDocumentsDir, L"\\zenfs\\Snapshots\\");
-
- ManifestTargetFile.Append(MyDocumentsDir);
- ManifestTargetFile.AppendAscii(ManifestSpec + 1);
- }
- }
- else
- {
- ManifestTargetFile.AppendAscii(ManifestSpec);
- }
-
- std::filesystem::path ManifestPath{ManifestTargetFile.c_str()};
-
- if (ManifestPath.extension() != L".zenfs")
- {
- ManifestPath.append(L".zenfs");
- }
-
- return ManifestPath;
-}
-
-//////////////////////////////////////////////////////////////////////////
-//
-// Testing related code follows...
-//
-
-#if ZEN_WITH_TESTS
-
-void
-snapshotmanifest_forcelink()
-{
-}
-
-TEST_CASE("Snapshot manifest")
-{
- SnapshotManifest Manifest;
-
- Manifest.Id = "test_manifest";
- Manifest.ChunkHash = zen::BLAKE3::HashMemory("abcd", 4);
-
- MemoryOutStream Outstream;
- WriteManifest(Manifest, Outstream);
-
- MemoryInStream Instream(Outstream.Data(), Outstream.Size());
- SnapshotManifest Manifest2;
- ReadManifest(/* out */ Manifest2, Instream);
-
- CHECK(Manifest.Id == Manifest2.Id);
- CHECK(Manifest.ChunkHash == Manifest2.ChunkHash);
-}
-
-#endif
-
-} // namespace zen
diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp
index 185b191f4..b025f5b5c 100644
--- a/zencore/zencore.cpp
+++ b/zencore/zencore.cpp
@@ -20,7 +20,6 @@
#include <zencore/memory.h>
#include <zencore/refcount.h>
#include <zencore/sha1.h>
-#include <zencore/snapshot_manifest.h>
#include <zencore/stats.h>
#include <zencore/stream.h>
#include <zencore/string.h>
@@ -114,7 +113,6 @@ zencore_forcelinktests()
zen::memory_forcelink();
zen::refcount_forcelink();
zen::sha1_forcelink();
- zen::snapshotmanifest_forcelink();
zen::stats_forcelink();
zen::stream_forcelink();
zen::string_forcelink();
diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj
index 46ec02892..f0eae411e 100644
--- a/zencore/zencore.vcxproj
+++ b/zencore/zencore.vcxproj
@@ -136,7 +136,6 @@
<ClInclude Include="include\zencore\sha1.h" />
<ClInclude Include="include\zencore\iobuffer.h" />
<ClInclude Include="include\zencore\sharedbuffer.h" />
- <ClInclude Include="include\zencore\snapshot_manifest.h" />
<ClInclude Include="include\zencore\stats.h" />
<ClInclude Include="include\zencore\stream.h" />
<ClInclude Include="include\zencore\streamutil.h" />
@@ -178,7 +177,6 @@
</ClCompile>
<ClCompile Include="iobuffer.cpp" />
<ClCompile Include="sharedbuffer.cpp" />
- <ClCompile Include="snapshot_manifest.cpp" />
<ClCompile Include="stats.cpp" />
<ClCompile Include="stream.cpp" />
<ClCompile Include="streamutil.cpp" />
diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters
index b09eb1b73..b9c69a33f 100644
--- a/zencore/zencore.vcxproj.filters
+++ b/zencore/zencore.vcxproj.filters
@@ -4,7 +4,6 @@
<ClInclude Include="include\zencore\intmath.h" />
<ClInclude Include="include\zencore\scopeguard.h" />
<ClInclude Include="include\zencore\sha1.h" />
- <ClInclude Include="include\zencore\snapshot_manifest.h" />
<ClInclude Include="include\zencore\targetver.h" />
<ClInclude Include="include\zencore\zencore.h" />
<ClInclude Include="include\zencore\compactbinary.h" />
@@ -46,7 +45,6 @@
<ClInclude Include="include\zencore\testing.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="snapshot_manifest.cpp" />
<ClCompile Include="sha1.cpp" />
<ClCompile Include="zencore.cpp" />
<ClCompile Include="compactbinary.cpp" />