]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/backup/catalog.rs
add pbs-tools subcrate
[proxmox-backup.git] / src / backup / catalog.rs
index 4c72ba3a44f0e12d099b6708110b5e9568b2fa92..a307f9d81418af3f9cb6c34331f72ac2ed6dcf5c 100644 (file)
@@ -468,6 +468,32 @@ impl <R: Read + Seek> CatalogReader<R> {
         Ok(entry_list)
     }
 
+    /// Lookup a DirEntry from an absolute path
+    pub fn lookup_recursive(
+        &mut self,
+        path: &[u8],
+    ) -> Result<DirEntry, Error> {
+        let mut current = self.root()?;
+        if path == b"/" {
+            return Ok(current);
+        }
+
+        let components = if !path.is_empty() && path[0] == b'/' {
+            &path[1..]
+        } else {
+            path
+        }.split(|c| *c == b'/');
+
+        for comp in components {
+            if let Some(entry) = self.lookup(&current, comp)? {
+                current = entry;
+            } else {
+                bail!("path {:?} not found in catalog", String::from_utf8_lossy(&path));
+            }
+        }
+        Ok(current)
+    }
+
     /// Lockup a DirEntry inside a parent directory
     pub fn lookup(
         &mut self,
@@ -585,6 +611,7 @@ impl <R: Read + Seek> CatalogReader<R> {
 ///
 /// Stores 7 bits per byte, Bit 8 indicates the end of the sequence (when not set).
 /// If the value is negative, we end with a zero byte (0x00).
+#[allow(clippy::neg_multiply)]
 pub fn catalog_encode_i64<W: Write>(writer: &mut W, v: i64) -> Result<(), Error> {
     let mut enc = Vec::new();
 
@@ -617,6 +644,7 @@ pub fn catalog_encode_i64<W: Write>(writer: &mut W, v: i64) -> Result<(), Error>
 /// We currently read maximal 11 bytes, which give a maximum of 70 bits + sign.
 /// this method is compatible with catalog_encode_u64 iff the
 /// value encoded is <= 2^63 (values > 2^63 cannot be represented in an i64)
+#[allow(clippy::neg_multiply)]
 pub fn catalog_decode_i64<R: Read>(reader: &mut R) -> Result<i64, Error> {
 
     let mut v: u64 = 0;