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 270471FF0E1 for ; Mon, 16 Nov 2026 02:29:57 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 917282169D; Mon, 16 Nov 2026 02:29:34 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 08/26] oci: explicitly set mtime of directories when extracting layer Date: Thu, 12 Nov 2026 15:10:35 +0100 Message-ID: <20261112141109.137298-9-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112141109.137298-1-f.schauer@proxmox.com> References: <20261112141109.137298-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794492819564 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.210 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_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record X-MailFrom: f.schauer@proxmox.com X-Mailman-Rule-Hits: administrivia X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header Message-ID-Hash: SZVJNSRELTZYA5WJMS3GWLONHGNWXZCX X-Message-ID-Hash: SZVJNSRELTZYA5WJMS3GWLONHGNWXZCX X-Mailman-Approved-At: Mon, 16 Nov 2026 02:29:32 +0100 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The tar crate doesn't set the mtime of directories when unpacking a TAR archive, even though preserving mtimes is enabled by default. Therefore set the mtime manually. Signed-off-by: Filip Schauer --- proxmox-oci/src/extract.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/proxmox-oci/src/extract.rs b/proxmox-oci/src/extract.rs index d9d5f1b4..b158c3be 100644 --- a/proxmox-oci/src/extract.rs +++ b/proxmox-oci/src/extract.rs @@ -1,9 +1,10 @@ use std::ffi::OsStr; -use std::fs::{read_dir, remove_dir_all, remove_file}; +use std::fs::{File, read_dir, remove_dir_all, remove_file}; use std::io::{self, ErrorKind, Read, Seek, SeekFrom}; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::str::FromStr; +use std::time::{Duration, UNIX_EPOCH}; use flate2::read::GzDecoder; use oci_spec::image::{ImageConfiguration, ImageManifest, MediaType}; @@ -249,14 +250,32 @@ fn extract_archive(reader: &mut R, target_path: &Path) -> io::Result<() // to avoid failure on restrictive parent directory permissions. directories.sort_by(|a, b| b.path_bytes().cmp(&a.path_bytes())); for mut dir in directories { + let dir_path = dir.path()?.into_owned(); + // Skip a directory replaced by a later entry, also to not apply it through a symlink. - if let Some(dir_path_abs) = resolve_in_target(target_path, &dir.path()?)? + if let Some(dir_path_abs) = resolve_in_target(target_path, &dir_path)? && dir_path_abs.symlink_metadata().is_ok_and(|m| !m.is_dir()) { continue; } - dir.unpack_in(target_path)?; + if !dir.unpack_in(target_path)? { + continue; + } + + // Manually set the mtime of the directory, since tar-rs doesn't do it. + if let Ok(mtime) = dir.header().mtime() + && let Some(dir_path_abs) = resolve_dir_in_target(target_path, &dir_path)? + { + let secs = mtime.cast_signed(); + let duration = Duration::from_secs(secs.unsigned_abs()); + let mtime = if secs > 0 { + UNIX_EPOCH + duration + } else { + UNIX_EPOCH - duration + }; + File::open(dir_path_abs)?.set_modified(mtime)?; + } } Ok(()) -- 2.47.3