From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id EB2BD1FF0E1 for ; Mon, 13 Jul 2026 11:50:34 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2026F2151B; Mon, 13 Jul 2026 11:50:20 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v2 11/15] task cache: use ArchiveFileWriter when creating new archive files Date: Mon, 13 Jul 2026 11:49:33 +0200 Message-ID: <20260713094937.151838-12-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713094937.151838-1-l.wagner@proxmox.com> References: <20260713094937.151838-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783936169927 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.308 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SVEROZV45NR2YZIKIPPP3DIWOYKGUK4L X-Message-ID-Hash: SVEROZV45NR2YZIKIPPP3DIWOYKGUK4L X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: As a nice side-effect this ensures that any zstd-compressed files are initialized atomically, making it impossible to have a missing zstd header if the process is terminated during the `new_file` call. Signed-off-by: Lukas Wagner --- server/src/remote_tasks/task_cache.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs index 7f6ccdf4..f70584aa 100644 --- a/server/src/remote_tasks/task_cache.rs +++ b/server/src/remote_tasks/task_cache.rs @@ -256,19 +256,16 @@ impl<'a> WritableTaskCache<'a> { fn new_file(&self, now: i64, compress: bool) -> Result { let path = self.cache.archive_path(now, compress); - let mut file = File::create(&path)?; - self.cache.create_options.apply_to(&mut file, &path)?; - - if compress { - let encoder = zstd::stream::write::Encoder::new(file, zstd::DEFAULT_COMPRESSION_LEVEL)?; - encoder.finish()?; - } - - Ok(ArchiveFile { + let file = ArchiveFile { path, compressed: compress, starttime: now, - }) + }; + + let writer = file.writer(self.cache.create_options)?; + writer.commit()?; + + Ok(file) } /// Rotate task archive if the the newest archive file is older than `rotate_after`. -- 2.47.3