From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id DE35E1FF135 for ; Thu, 02 Jul 2026 11:23:54 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 10227214A3; Thu, 02 Jul 2026 11:23:52 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 11/15] task cache: use ArchiveFileWriter when creating new archive files Date: Thu, 2 Jul 2026 11:22:54 +0200 Message-ID: <20260702092258.174740-12-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260702092258.174740-1-l.wagner@proxmox.com> References: <20260702092258.174740-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: 1782984190610 X-SPAM-LEVEL: Spam detection results: 0 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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: T3CHXYWYNEQ5OQFDBZON2FTIUFIJ7T5N X-Message-ID-Hash: T3CHXYWYNEQ5OQFDBZON2FTIUFIJ7T5N 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 969a8124..3677de2c 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.finalize_and_replace()?; + + Ok(file) } /// Rotate task archive if the the newest archive file is older than `rotate_after`. -- 2.47.3