diff options
| author | Dan Engelbrecht <[email protected]> | 2025-06-02 14:41:30 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-06-02 14:41:30 +0200 |
| commit | 8494a3c61ae23c74510c5327f0c1e31bc1e42bb9 (patch) | |
| tree | 64c4b38cf92e404be7f853df125da6d8a405efe0 /src | |
| parent | Update README.md (diff) | |
| download | zen-8494a3c61ae23c74510c5327f0c1e31bc1e42bb9.tar.xz zen-8494a3c61ae23c74510c5327f0c1e31bc1e42bb9.zip | |
use system temp dir (#412)
* use system temp dir when uploading builds
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/cmds/builds_cmd.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/zen/cmds/builds_cmd.cpp b/src/zen/cmds/builds_cmd.cpp index d998ed3e8..f6f15acb0 100644 --- a/src/zen/cmds/builds_cmd.cpp +++ b/src/zen/cmds/builds_cmd.cpp @@ -121,9 +121,11 @@ namespace { { return ZenTempFolderPath(ZenFolderPath) / "blocks"; // Temp storage for whole and partial blocks } - std::filesystem::path ZenTempChunkFolderPath(const std::filesystem::path& ZenFolderPath) + std::filesystem::path UploadTempDirectory(const std::filesystem::path& Path) { - return ZenTempFolderPath(ZenFolderPath) / "chunks"; // Temp storage for decompressed and validated chunks + const std::u8string LocalPathString = Path.generic_u8string(); + IoHash PathHash = IoHash::HashBuffer(LocalPathString.data(), LocalPathString.length()); + return std::filesystem::temp_directory_path() / fmt::format("zen_{}", PathHash); } std::filesystem::path ZenTempDownloadFolderPath(const std::filesystem::path& ZenFolderPath) @@ -2561,7 +2563,7 @@ namespace { void UploadPartBlobs(StorageInstance& Storage, const Oid& BuildId, const std::filesystem::path& Path, - const std::filesystem::path& ZenFolderPath, + const std::filesystem::path& TempDir, const ChunkedFolderContent& Content, const ChunkedContentLookup& Lookup, std::span<IoHash> RawHashes, @@ -2635,7 +2637,7 @@ namespace { auto AsyncUploadBlock = [&Storage, &BuildId, &Work, - &ZenFolderPath, + &TempDir, &NewBlocks, UploadBlockCount, &UploadedBlockCount, @@ -2652,7 +2654,7 @@ namespace { if (QueuedPendingInMemoryBlocksForUpload.load() > 16) { ZEN_TRACE_CPU("AsyncUploadBlock_WriteTempBlock"); - Payload = CompositeBuffer(WriteToTempFile(std::move(Payload), ZenTempBlockFolderPath(ZenFolderPath), BlockHash)); + Payload = CompositeBuffer(WriteToTempFile(std::move(Payload), TempDir, BlockHash)); IsInMemoryBlock = false; } else @@ -2931,7 +2933,7 @@ namespace { [&Path, &Content, &Lookup, - &ZenFolderPath, + &TempDir, &LooseChunksStats, &LooseChunkOrderIndexes, &FilteredCompressedBytesPerSecond, @@ -2944,8 +2946,7 @@ namespace { FilteredCompressedBytesPerSecond.Start(); Stopwatch CompressTimer; - CompositeBuffer Payload = - CompressChunk(Path, Content, Lookup, ChunkIndex, ZenTempChunkFolderPath(ZenFolderPath), LooseChunksStats); + CompositeBuffer Payload = CompressChunk(Path, Content, Lookup, ChunkIndex, TempDir, LooseChunksStats); ZEN_CONSOLE_VERBOSE("Compressed chunk {} ({} -> {}) in {}", Content.ChunkedContent.ChunkHashes[ChunkIndex], NiceBytes(Content.ChunkedContent.ChunkRawSizes[ChunkIndex]), @@ -3174,7 +3175,7 @@ namespace { const Oid& BuildPartId, const std::string_view BuildPartName, const std::filesystem::path& Path, - const std::filesystem::path& ZenFolderPath, + const std::filesystem::path& TempDir, const std::filesystem::path& ManifestPath, const uint64_t FindBlockMaxCount, const uint8_t BlockReuseMinPercentLimit, @@ -3203,18 +3204,15 @@ namespace { Stopwatch ProcessTimer; - const std::filesystem::path ZenTempFolder = ZenTempFolderPath(ZenFolderPath); - CreateDirectories(ZenTempFolder); - CleanDirectory(ZenTempFolder, {}); + CreateDirectories(TempDir); + CleanDirectory(TempDir, {}); auto _ = MakeGuard([&]() { - if (CleanDirectory(ZenTempFolder, {})) + if (CleanDirectory(TempDir, {})) { std::error_code DummyEc; - RemoveDir(ZenTempFolder, DummyEc); + RemoveDir(TempDir, DummyEc); } }); - CreateDirectories(ZenTempBlockFolderPath(ZenFolderPath)); - CreateDirectories(ZenTempChunkFolderPath(ZenFolderPath)); ProgressBar::SetLogOperationProgress(ProgressMode, TaskSteps::PrepareBuild, TaskSteps::StepCount); @@ -3814,7 +3812,7 @@ namespace { auto UploadAttachments = [&Storage, &BuildId, &Path, - &ZenFolderPath, + &TempDir, &LocalContent, &LocalLookup, &NewBlockChunks, @@ -3853,7 +3851,7 @@ namespace { UploadPartBlobs(Storage, BuildId, Path, - ZenFolderPath, + TempDir, LocalContent, LocalLookup, RawHashes, @@ -10413,12 +10411,14 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) CbObject MetaData = ParseBuildMetadata(); + const std::filesystem::path TempDir = UploadTempDirectory(m_Path); + UploadFolder(Storage, BuildId, BuildPartId, m_BuildPartName, m_Path, - m_ZenFolderPath, + TempDir, m_ManifestPath, m_FindBlockMaxCount, m_BlockReuseMinPercentLimit, @@ -10720,12 +10720,15 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) ZEN_CONSOLE("Upload Build {}, Part {} ({})\n{}", m_BuildId, BuildPartId, m_BuildPartName, SB.ToView()); } + const std::filesystem::path UploadTempDir = UploadTempDirectory(m_Path); + // std::filesystem::path UploadTempDir = m_ZenFolderPath / "upload_tmp"; + UploadFolder(Storage, BuildId, BuildPartId, m_BuildPartName, m_Path, - m_ZenFolderPath, + UploadTempDir, {}, m_FindBlockMaxCount, m_BlockReuseMinPercentLimit, @@ -10919,7 +10922,7 @@ BuildsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) BuildPartId2, m_BuildPartName, DownloadPath, - m_ZenFolderPath, + UploadTempDir, {}, m_FindBlockMaxCount, m_BlockReuseMinPercentLimit, |