[pbs-devel] [PATCH backup] update to pxar 0.3 to support negative timestamps
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Jul 28 12:33:16 CEST 2020
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
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<libc::stat, Error> {
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<libc::stat, Error> {
.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<E: SysError>(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
More information about the pbs-devel
mailing list