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 769C1753F5 for ; Wed, 21 Apr 2021 15:24:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6DC84FA7C for ; Wed, 21 Apr 2021 15:24:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 C1D62FA55 for ; Wed, 21 Apr 2021 15:24:04 +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 3CD7244D34 for ; Wed, 21 Apr 2021 15:18:18 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 21 Apr 2021 15:18:08 +0200 Message-Id: <20210421131809.22607-4-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210421131809.22607-1-s.reiter@proxmox.com> References: <20210421131809.22607-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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. [api.rs, helpers.rs, proxmox-file-restore.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup 3/4] file-restore: Add 'v' (Virtual) ArchiveEntry type 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: Wed, 21 Apr 2021 13:24:36 -0000 Encoded as "None", to avoid cluttering DirEntryAttribute, where it wouldn't make any sense to have. Signed-off-by: Stefan Reiter --- src/api2/helpers.rs | 2 +- src/api2/types/mod.rs | 13 ++++++++----- src/bin/proxmox-file-restore.rs | 9 +++++++-- src/bin/proxmox_restore_daemon/api.rs | 9 +++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/api2/helpers.rs b/src/api2/helpers.rs index 41391b77..52f80bad 100644 --- a/src/api2/helpers.rs +++ b/src/api2/helpers.rs @@ -48,7 +48,7 @@ pub fn list_dir_content( let mut components = path.clone(); components.push(b'/'); components.extend(&direntry.name); - let mut entry = ArchiveEntry::new(&components, &direntry.attr); + let mut entry = ArchiveEntry::new(&components, Some(&direntry.attr)); if let DirEntryAttribute::File { size, mtime } = direntry.attr { entry.size = size.into(); entry.mtime = mtime.into(); diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 19186ea2..9d1bd301 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -1354,19 +1354,22 @@ pub struct ArchiveEntry { } impl ArchiveEntry { - pub fn new(filepath: &[u8], entry_type: &DirEntryAttribute) -> Self { + pub fn new(filepath: &[u8], entry_type: Option<&DirEntryAttribute>) -> Self { Self { filepath: base64::encode(filepath), text: String::from_utf8_lossy(filepath.split(|x| *x == b'/').last().unwrap()) .to_string(), - entry_type: CatalogEntryType::from(entry_type).to_string(), - leaf: !matches!(entry_type, DirEntryAttribute::Directory { .. }), + entry_type: match entry_type { + Some(entry_type) => CatalogEntryType::from(entry_type).to_string(), + None => "v".to_owned(), + }, + leaf: !matches!(entry_type, None | Some(DirEntryAttribute::Directory { .. })), size: match entry_type { - DirEntryAttribute::File { size, .. } => Some(*size), + Some(DirEntryAttribute::File { size, .. }) => Some(*size), _ => None }, mtime: match entry_type { - DirEntryAttribute::File { mtime, .. } => Some(*mtime), + Some(DirEntryAttribute::File { mtime, .. }) => Some(*mtime), _ => None }, } diff --git a/src/bin/proxmox-file-restore.rs b/src/bin/proxmox-file-restore.rs index 36fdd391..7799a76d 100644 --- a/src/bin/proxmox-file-restore.rs +++ b/src/bin/proxmox-file-restore.rs @@ -174,8 +174,13 @@ async fn list( continue; } let path = format!("/{}", file.filename); - let attr = DirEntryAttribute::Directory { start: 0 }; - entries.push(ArchiveEntry::new(path.as_bytes(), &attr)); + let attr = if file.filename.ends_with(".pxar.didx") { + // a pxar file is a file archive, so it's root is also a directory root + Some(&DirEntryAttribute::Directory { start: 0 }) + } else { + None + }; + entries.push(ArchiveEntry::new(path.as_bytes(), attr)); } Ok(entries) diff --git a/src/bin/proxmox_restore_daemon/api.rs b/src/bin/proxmox_restore_daemon/api.rs index 7ac70278..82ead647 100644 --- a/src/bin/proxmox_restore_daemon/api.rs +++ b/src/bin/proxmox_restore_daemon/api.rs @@ -148,7 +148,7 @@ fn list( match root_entry { DirEntryAttribute::File { .. } => { // list on file, return details - res.push(ArchiveEntry::new(¶m_path, &root_entry)); + res.push(ArchiveEntry::new(¶m_path, Some(&root_entry))); } DirEntryAttribute::Directory { .. } => { // list on directory, return all contained files/dirs @@ -176,7 +176,7 @@ fn list( if let Ok(entry) = entry { res.push(ArchiveEntry::new( full_path.as_os_str().as_bytes(), - &entry, + Some(&entry), )); } } @@ -192,7 +192,7 @@ fn list( t_path.extend(t.as_bytes()); res.push(ArchiveEntry::new( &t_path[..], - &DirEntryAttribute::Directory { start: 0 }, + None, )); } } @@ -203,7 +203,8 @@ fn list( c_path.extend(c.as_bytes()); res.push(ArchiveEntry::new( &c_path[..], - &DirEntryAttribute::Directory { start: 0 }, + // this marks the beginning of a filesystem, i.e. '/', so this is a Directory + Some(&DirEntryAttribute::Directory { start: 0 }), )); } } -- 2.20.1