public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-backup v2 4/5] file-restore: factor out 'list_files'
Date: Tue, 26 Apr 2022 12:13:57 +0200	[thread overview]
Message-ID: <20220426101401.3216096-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20220426101401.3216096-1-d.csapak@proxmox.com>

we'll want to reuse that in a later patch

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox-file-restore/src/main.rs | 156 +++++++++++++++++--------------
 1 file changed, 84 insertions(+), 72 deletions(-)

diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs
index ab50c636..4b327f6b 100644
--- a/proxmox-file-restore/src/main.rs
+++ b/proxmox-file-restore/src/main.rs
@@ -26,7 +26,7 @@ use pbs_client::tools::{
     },
     REPO_URL_SCHEMA,
 };
-use pbs_client::{BackupReader, RemoteChunkReader};
+use pbs_client::{BackupReader, BackupRepository, RemoteChunkReader};
 use pbs_config::key_config::decrypt_key;
 use pbs_datastore::catalog::{ArchiveEntry, CatalogReader, DirEntryAttribute};
 use pbs_datastore::dynamic_index::{BufferedDynamicReader, LocalDynamicReadAt};
@@ -92,6 +92,84 @@ fn keyfile_path(param: &Value) -> Option<String> {
     None
 }
 
+async fn list_files(
+    repo: BackupRepository,
+    snapshot: BackupDir,
+    path: ExtractPath,
+    crypt_config: Option<Arc<CryptConfig>>,
+    keyfile: Option<String>,
+    driver: Option<BlockDriverType>,
+) -> Result<Vec<ArchiveEntry>, Error> {
+    let client = connect(&repo)?;
+    let client = BackupReader::start(
+        client,
+        crypt_config.clone(),
+        repo.store(),
+        snapshot.group.ty,
+        &snapshot.group.id,
+        snapshot.time,
+        true,
+    )
+    .await?;
+
+    let (manifest, _) = client.download_manifest().await?;
+    manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref))?;
+
+    match path {
+        ExtractPath::ListArchives => {
+            let mut entries = vec![];
+            for file in manifest.files() {
+                if !file.filename.ends_with(".pxar.didx") && !file.filename.ends_with(".img.fidx") {
+                    continue;
+                }
+                let path = format!("/{}", file.filename);
+                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_with_size(
+                    path.as_bytes(),
+                    attr,
+                    Some(file.size),
+                ));
+            }
+
+            Ok(entries)
+        }
+        ExtractPath::Pxar(file, mut path) => {
+            let index = client
+                .download_dynamic_index(&manifest, CATALOG_NAME)
+                .await?;
+            let most_used = index.find_most_used_chunks(8);
+            let file_info = manifest.lookup_file_info(CATALOG_NAME)?;
+            let chunk_reader = RemoteChunkReader::new(
+                client.clone(),
+                crypt_config,
+                file_info.chunk_crypt_mode(),
+                most_used,
+            );
+            let reader = BufferedDynamicReader::new(index, chunk_reader);
+            let mut catalog_reader = CatalogReader::new(reader);
+
+            let mut fullpath = file.into_bytes();
+            fullpath.append(&mut path);
+
+            catalog_reader.list_dir_contents(&fullpath)
+        }
+        ExtractPath::VM(file, path) => {
+            let details = SnapRestoreDetails {
+                manifest,
+                repo,
+                snapshot,
+                keyfile,
+            };
+            data_list(driver, details, file, path).await
+        }
+    }
+}
+
 #[api(
    input: {
        properties: {
@@ -163,78 +241,12 @@ async fn list(snapshot: String, path: String, base64: bool, param: Value) -> Res
         }
     };
 
-    let client = connect(&repo)?;
-    let client = BackupReader::start(
-        client,
-        crypt_config.clone(),
-        repo.store(),
-        snapshot.group.ty,
-        &snapshot.group.id,
-        snapshot.time,
-        true,
-    )
-    .await?;
-
-    let (manifest, _) = client.download_manifest().await?;
-    manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref))?;
-
-    let result = match path {
-        ExtractPath::ListArchives => {
-            let mut entries = vec![];
-            for file in manifest.files() {
-                if !file.filename.ends_with(".pxar.didx") && !file.filename.ends_with(".img.fidx") {
-                    continue;
-                }
-                let path = format!("/{}", file.filename);
-                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_with_size(
-                    path.as_bytes(),
-                    attr,
-                    Some(file.size),
-                ));
-            }
-
-            Ok(entries)
-        }
-        ExtractPath::Pxar(file, mut path) => {
-            let index = client
-                .download_dynamic_index(&manifest, CATALOG_NAME)
-                .await?;
-            let most_used = index.find_most_used_chunks(8);
-            let file_info = manifest.lookup_file_info(CATALOG_NAME)?;
-            let chunk_reader = RemoteChunkReader::new(
-                client.clone(),
-                crypt_config,
-                file_info.chunk_crypt_mode(),
-                most_used,
-            );
-            let reader = BufferedDynamicReader::new(index, chunk_reader);
-            let mut catalog_reader = CatalogReader::new(reader);
-
-            let mut fullpath = file.into_bytes();
-            fullpath.append(&mut path);
+    let driver: Option<BlockDriverType> = match param.get("driver") {
+        Some(drv) => Some(serde::Deserialize::deserialize(drv)?),
+        None => None,
+    };
 
-            catalog_reader.list_dir_contents(&fullpath)
-        }
-        ExtractPath::VM(file, path) => {
-            let details = SnapRestoreDetails {
-                manifest,
-                repo,
-                snapshot,
-                keyfile,
-            };
-            let driver: Option<BlockDriverType> = match param.get("driver") {
-                Some(drv) => Some(serde::Deserialize::deserialize(drv)?),
-                None => None,
-            };
-            data_list(driver, details, file, path).await
-        }
-    }?;
+    let result = list_files(repo, snapshot, path, crypt_config, keyfile, driver).await?;
 
     let options = default_table_format_options()
         .sortby("type", false)
-- 
2.30.2





  parent reply	other threads:[~2022-04-26 10:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 10:13 [pve-devel] [PATCH proxmox-backup/common/storage/wt v2] improve file-restore timeout behaviour Dominik Csapak
2022-04-26 10:13 ` [pve-devel] [PATCH proxmox-backup v2 1/5] restore-daemon: start disk initialization in parallel to the api Dominik Csapak
2022-04-26 10:13 ` [pve-devel] [PATCH proxmox-backup v2 2/5] restore-daemon: put blocking code into 'block_in_place' Dominik Csapak
2022-04-26 10:13 ` [pve-devel] [PATCH proxmox-backup v2 3/5] restore-daemon: avoid auto-mounting zpools Dominik Csapak
2022-04-26 10:13 ` Dominik Csapak [this message]
2022-04-26 10:13 ` [pve-devel] [PATCH proxmox-backup v2 5/5] file-restore: add 'timeout' and 'json-error' parameter Dominik Csapak
2022-04-26 10:13 ` [pve-devel] [PATCH common v2 1/1] PBSClient: file_restore_list: add json-error and timeout parameter Dominik Csapak
2022-04-26 10:14 ` [pve-devel] [PATCH storage v2 1/1] api: FileRestore: decode and return proper error with new file-restore params Dominik Csapak
2022-04-26 10:14 ` [pve-devel] [PATCH widget-toolkit v2 1/1] window/FileBrowser: try reload again when getting a 503 error Dominik Csapak
2022-04-27 17:43 ` [pve-devel] partiall-applied: [PATCH proxmox-backup/common/storage/wt v2] improve file-restore timeout behaviour Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220426101401.3216096-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal