aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
authorZousar Shaker <[email protected]>2024-12-06 21:47:11 -0700
committerZousar Shaker <[email protected]>2024-12-06 21:47:11 -0700
commit5688fa8f46fe3cd32f283adcc590e447174c58a8 (patch)
treedccaef1a87cf454639f45e330732221ce4eb1712 /src/zencore
parentchangelog (diff)
parent5.5.16-pre0 (diff)
downloadzen-zs/xrepo.tar.xz
zen-zs/xrepo.zip
Merge branch 'main' into zs/xrepozs/xrepo
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/filesystem.cpp24
-rw-r--r--src/zencore/include/zencore/compactbinarypackage.h4
-rw-r--r--src/zencore/include/zencore/filesystem.h4
-rw-r--r--src/zencore/include/zencore/memory/align.h2
-rw-r--r--src/zencore/include/zencore/testutils.h1
-rw-r--r--src/zencore/testutils.cpp20
-rw-r--r--src/zencore/xmake.lua1
7 files changed, 54 insertions, 2 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp
index 36147c5a9..52f2c4adc 100644
--- a/src/zencore/filesystem.cpp
+++ b/src/zencore/filesystem.cpp
@@ -1435,12 +1435,34 @@ FileSizeFromHandle(void* NativeHandle)
int Fd = int(intptr_t(NativeHandle));
struct stat Stat;
fstat(Fd, &Stat);
- FileSize = size_t(Stat.st_size);
+ FileSize = size_t(Stat.st_size);
#endif
return FileSize;
}
+uint64_t
+GetModificationTickFromHandle(void* NativeHandle, std::error_code& Ec)
+{
+#if ZEN_PLATFORM_WINDOWS
+ FILETIME LastWriteTime;
+ BOOL OK = GetFileTime((HANDLE)NativeHandle, NULL, NULL, &LastWriteTime);
+ if (OK)
+ {
+ return ((uint64_t(LastWriteTime.dwHighDateTime) << 32) | LastWriteTime.dwLowDateTime);
+ }
+#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+ int Fd = int(uintptr_t(NativeHandle));
+ struct stat Stat;
+ if (0 == fstat(Fd, &Stat))
+ {
+ return gsl::narrow<uint64_t>(Stat.st_mtime);
+ }
+#endif
+ Ec = MakeErrorCodeFromLastError();
+ return 0;
+}
+
std::filesystem::path
GetRunningExecutablePath()
{
diff --git a/src/zencore/include/zencore/compactbinarypackage.h b/src/zencore/include/zencore/compactbinarypackage.h
index 064481f83..12fcc41b7 100644
--- a/src/zencore/include/zencore/compactbinarypackage.h
+++ b/src/zencore/include/zencore/compactbinarypackage.h
@@ -64,6 +64,9 @@ public:
ZENCORE_API CbAttachment(const CompressedBuffer& InValue, const IoHash& Hash);
ZENCORE_API CbAttachment(CompressedBuffer&& InValue, const IoHash& Hash);
+ /** Construct a binary attachment. Value is cloned if not owned. */
+ ZENCORE_API CbAttachment(CompositeBuffer&& InValue, const IoHash& Hash);
+
/** Reset this to a null attachment. */
inline void Reset() { *this = CbAttachment(); }
@@ -130,7 +133,6 @@ public:
private:
ZENCORE_API CbAttachment(const CbObject& Value, const IoHash* Hash);
ZENCORE_API explicit CbAttachment(CompositeBuffer&& InValue);
- ZENCORE_API CbAttachment(CompositeBuffer&& InValue, const IoHash& Hash);
IoHash Hash;
std::variant<std::nullptr_t, CbObject, CompositeBuffer, CompressedBuffer> Value;
diff --git a/src/zencore/include/zencore/filesystem.h b/src/zencore/include/zencore/filesystem.h
index 2cd663afb..dba4981f0 100644
--- a/src/zencore/include/zencore/filesystem.h
+++ b/src/zencore/include/zencore/filesystem.h
@@ -45,6 +45,10 @@ ZENCORE_API std::filesystem::path CanonicalPath(std::filesystem::path InPath, st
*/
ZENCORE_API uint64_t FileSizeFromHandle(void* NativeHandle);
+/** Get a native time tick of last modification time
+ */
+ZENCORE_API uint64_t GetModificationTickFromHandle(void* NativeHandle, std::error_code& Ec);
+
ZENCORE_API std::filesystem::path GetRunningExecutablePath();
/** Set the max open file handle count to max allowed for the current process on Linux and MacOS
diff --git a/src/zencore/include/zencore/memory/align.h b/src/zencore/include/zencore/memory/align.h
index acf4157c4..9d4101fab 100644
--- a/src/zencore/include/zencore/memory/align.h
+++ b/src/zencore/include/zencore/memory/align.h
@@ -1,5 +1,7 @@
// Copyright Epic Games, Inc. All Rights Reserved.
+#pragma once
+
#include <zenbase/zenbase.h>
namespace zen {
diff --git a/src/zencore/include/zencore/testutils.h b/src/zencore/include/zencore/testutils.h
index 6a1c0184b..45fde4eda 100644
--- a/src/zencore/include/zencore/testutils.h
+++ b/src/zencore/include/zencore/testutils.h
@@ -33,6 +33,7 @@ struct ScopedCurrentDirectoryChange
};
IoBuffer CreateRandomBlob(uint64_t Size);
+IoBuffer CreateSemiRandomBlob(uint64_t Size);
struct FalseType
{
diff --git a/src/zencore/testutils.cpp b/src/zencore/testutils.cpp
index d4c8aeaef..641d5508a 100644
--- a/src/zencore/testutils.cpp
+++ b/src/zencore/testutils.cpp
@@ -71,6 +71,26 @@ CreateRandomBlob(uint64_t Size)
return Data;
};
+IoBuffer
+CreateSemiRandomBlob(uint64_t Size)
+{
+ IoBuffer Result(Size);
+ const size_t PartCount = (Size / (1u * 1024u * 64)) + 1;
+ const size_t PartSize = Size / PartCount;
+ auto Part = CreateRandomBlob(PartSize);
+ auto Remain = Result.GetMutableView().CopyFrom(Part.GetView());
+ while (Remain.GetSize() >= PartSize)
+ {
+ Remain = Remain.CopyFrom(Part.GetView());
+ }
+ if (Remain.GetSize() > 0)
+ {
+ auto RemainBuffer = CreateRandomBlob(Remain.GetSize());
+ Remain.CopyFrom(RemainBuffer.GetView());
+ }
+ return Result;
+};
+
} // namespace zen
#endif // ZEN_WITH_TESTS
diff --git a/src/zencore/xmake.lua b/src/zencore/xmake.lua
index ce8cd0996..2f82d38a3 100644
--- a/src/zencore/xmake.lua
+++ b/src/zencore/xmake.lua
@@ -13,6 +13,7 @@ target('zencore')
end)
set_configdir("include/zencore")
add_files("**.cpp")
+ add_files("trace.cpp", {unity_ignored = true })
if has_config("zenrpmalloc") then
set_languages("c17", "cxx20")