From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A509666B91 for ; Tue, 28 Jul 2020 12:33:56 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9E7BF237B6 for ; Tue, 28 Jul 2020 12:33:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1261723750 for ; Tue, 28 Jul 2020 12:33:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D1121433C9 for ; Tue, 28 Jul 2020 12:33:22 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Tue, 28 Jul 2020 12:33:16 +0200 Message-Id: <20200728103321.16843-3-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200728103321.16843-1-w.bumiller@proxmox.com> References: <20200728103321.16843-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.036 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [create.rs, tools.rs, metadata.rs, fuse.rs] Subject: [pbs-devel] [PATCH backup] update to pxar 0.3 to support negative timestamps X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 10:33:56 -0000 Signed-off-by: Wolfgang Bumiller --- Cargo.toml | 2 +- src/pxar/create.rs | 9 ++++----- src/pxar/fuse.rs | 17 ++++++----------- src/pxar/metadata.rs | 18 ++++++------------ src/pxar/tools.rs | 6 ++---- 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 258a9bb2..23063956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ proxmox = { version = "0.2.1", features = [ "sortable-macro", "api-macro", "webs #proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] } #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro", "websocket" ] } proxmox-fuse = "0.1.0" -pxar = { version = "0.2.1", features = [ "tokio-io", "futures-io" ] } +pxar = { version = "0.3.0", features = [ "tokio-io", "futures-io" ] } #pxar = { path = "../pxar", features = [ "tokio-io", "futures-io" ] } regex = "1.2" rustyline = "6" diff --git a/src/pxar/create.rs b/src/pxar/create.rs index f0831526..d0c5ae81 100644 --- a/src/pxar/create.rs +++ b/src/pxar/create.rs @@ -1,5 +1,4 @@ use std::collections::{HashSet, HashMap}; -use std::convert::TryFrom; use std::ffi::{CStr, CString, OsStr}; use std::fmt; use std::io::{self, Read, Write}; @@ -696,16 +695,16 @@ fn get_metadata(fd: RawFd, stat: &FileStat, flags: Flags, fs_magic: i64) -> Resu // required for some of these let proc_path = Path::new("/proc/self/fd/").join(fd.to_string()); - let mtime = u64::try_from(stat.st_mtime * 1_000_000_000 + stat.st_mtime_nsec) - .map_err(|_| format_err!("file with negative mtime"))?; - let mut meta = Metadata { stat: pxar::Stat { mode: u64::from(stat.st_mode), flags: 0, uid: stat.st_uid, gid: stat.st_gid, - mtime, + mtime: pxar::format::StatxTimestamp { + secs: stat.st_mtime, + nanos: stat.st_mtime_nsec as u32, + }, }, ..Default::default() }; diff --git a/src/pxar/fuse.rs b/src/pxar/fuse.rs index 1534ff29..652b9219 100644 --- a/src/pxar/fuse.rs +++ b/src/pxar/fuse.rs @@ -673,11 +673,6 @@ fn to_stat(inode: u64, entry: &pxar::Entry) -> Result { let metadata = entry.metadata(); - let time = i64::try_from(metadata.stat.mtime) - .map_err(|_| format_err!("mtime does not fit into a signed 64 bit integer"))?; - let sec = time / 1_000_000_000; - let nsec = time % 1_000_000_000; - let mut stat: libc::stat = unsafe { mem::zeroed() }; stat.st_ino = inode; stat.st_nlink = nlink; @@ -687,11 +682,11 @@ fn to_stat(inode: u64, entry: &pxar::Entry) -> Result { .map_err(|err| format_err!("size does not fit into st_size field: {}", err))?; stat.st_uid = metadata.stat.uid; stat.st_gid = metadata.stat.gid; - stat.st_atime = sec; - stat.st_atime_nsec = nsec; - stat.st_mtime = sec; - stat.st_mtime_nsec = nsec; - stat.st_ctime = sec; - stat.st_ctime_nsec = nsec; + stat.st_atime = metadata.stat.mtime.secs; + stat.st_atime_nsec = metadata.stat.mtime.nanos as _; + stat.st_mtime = metadata.stat.mtime.secs; + stat.st_mtime_nsec = metadata.stat.mtime.nanos as _; + stat.st_ctime = metadata.stat.mtime.secs; + stat.st_ctime_nsec = metadata.stat.mtime.nanos as _; Ok(stat) } diff --git a/src/pxar/metadata.rs b/src/pxar/metadata.rs index 2cbed756..6df00230 100644 --- a/src/pxar/metadata.rs +++ b/src/pxar/metadata.rs @@ -37,26 +37,20 @@ fn allow_notsupp_remember(err: E, not_supp: &mut bool) -> Result<() } } -fn nsec_to_update_timespec(mtime_nsec: u64) -> [libc::timespec; 2] { +fn timestamp_to_update_timespec(mtime: &pxar::format::StatxTimestamp) -> [libc::timespec; 2] { // restore mtime const UTIME_OMIT: i64 = (1 << 30) - 2; - const NANOS_PER_SEC: i64 = 1_000_000_000; - let sec = (mtime_nsec as i64) / NANOS_PER_SEC; - let nsec = (mtime_nsec as i64) % NANOS_PER_SEC; - - let times: [libc::timespec; 2] = [ + [ libc::timespec { tv_sec: 0, tv_nsec: UTIME_OMIT, }, libc::timespec { - tv_sec: sec, - tv_nsec: nsec, + tv_sec: mtime.secs, + tv_nsec: mtime.nanos as _, }, - ]; - - times + ] } // @@ -130,7 +124,7 @@ pub fn apply(flags: Flags, metadata: &Metadata, fd: RawFd, file_name: &CStr) -> libc::utimensat( libc::AT_FDCWD, c_proc_path.as_ptr(), - nsec_to_update_timespec(metadata.stat.mtime).as_ptr(), + timestamp_to_update_timespec(&metadata.stat.mtime).as_ptr(), 0, ) }); diff --git a/src/pxar/tools.rs b/src/pxar/tools.rs index ec5c13b2..0fdb033d 100644 --- a/src/pxar/tools.rs +++ b/src/pxar/tools.rs @@ -120,8 +120,7 @@ pub fn format_single_line_entry(entry: &Entry) -> String { let mode_string = mode_string(entry); let meta = entry.metadata(); - let mtime = meta.mtime_as_duration(); - let mtime = chrono::Local.timestamp(mtime.as_secs() as i64, mtime.subsec_nanos()); + let mtime = chrono::Local.timestamp(meta.stat.mtime.secs, meta.stat.mtime.nanos); let (size, link) = match entry.kind() { EntryKind::File { size, .. } => (format!("{}", *size), String::new()), @@ -148,8 +147,7 @@ pub fn format_multi_line_entry(entry: &Entry) -> String { let mode_string = mode_string(entry); let meta = entry.metadata(); - let mtime = meta.mtime_as_duration(); - let mtime = chrono::Local.timestamp(mtime.as_secs() as i64, mtime.subsec_nanos()); + let mtime = chrono::Local.timestamp(meta.stat.mtime.secs, meta.stat.mtime.nanos); let (size, link, type_name) = match entry.kind() { EntryKind::File { size, .. } => (format!("{}", *size), String::new(), "file"), -- 2.20.1