From 6c878de46ec072336f8ae1e5bac999eff566863a Mon Sep 17 00:00:00 2001 From: sosthene-nitrokey Date: Mon, 16 Dec 2024 11:03:06 +0000 Subject: [PATCH] deploy: 1b6222063b15119f94ef3b6c8cb511a8219175c7 --- src/trussed/store.rs.html | 58 ++++++++++++++++++++-- trussed/store/fn.delete.html | 2 +- trussed/store/fn.exists.html | 2 +- trussed/store/fn.metadata.html | 2 +- trussed/store/fn.remove_dir.html | 2 +- trussed/store/fn.remove_dir_all_where.html | 2 +- trussed/store/fn.rename.html | 2 +- trussed/store/index.html | 2 +- 8 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/trussed/store.rs.html b/src/trussed/store.rs.html index 9910f06c0a2..d09ce2b7cea 100644 --- a/src/trussed/store.rs.html +++ b/src/trussed/store.rs.html @@ -641,7 +641,32 @@ 640 641 642 -643
//! `store` presents a combined interface to three littlefs2 filesystems:
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
+654
+655
+656
+657
+658
+659
+660
+661
+662
+663
+664
+665
+666
+667
+668
//! `store` presents a combined interface to three littlefs2 filesystems:
 //! internal flash, external flash, volatile/RAM.
 //!
 //! It covers two usecases:
@@ -715,7 +740,7 @@
 //! - Alternative: subdirectory <==> RP hash, everything else in flat files
 //! - In any case need to "list dirs excluding . and .." or similar
 
-use littlefs2::{driver::Storage, fs::Filesystem};
+use littlefs2::{driver::Storage, fs::Filesystem, path};
 
 use crate::error::Error;
 use crate::types::{Bytes, Location};
@@ -1197,8 +1222,33 @@
 #[inline(never)]
 pub fn delete(store: impl Store, location: Location, path: &Path) -> bool {
     debug_now!("deleting {}", &path);
-    store.fs(location).remove(path).is_ok()
-}
+    let fs = store.fs(location);
+    if fs.remove(path).is_err() {
+        return false;
+    }
+
+    // Only delete ancestors for volatile FS
+    if location != Location::Volatile {
+        return true;
+    }
+    // first ancestor is the file itself
+    for parent in path.ancestors().skip(1) {
+        if &*parent == path!("/") {
+            break;
+        }
+        let Ok(meta) = fs.metadata(&parent) else {
+            return false;
+        };
+        if meta.is_dir() && meta.is_empty() {
+            if fs.remove_dir(&parent).is_err() {
+                return false;
+            }
+        } else {
+            break;
+        }
+    }
+    true
+}
 
 #[inline(never)]
 pub fn exists(store: impl Store, location: Location, path: &Path) -> bool {
diff --git a/trussed/store/fn.delete.html b/trussed/store/fn.delete.html
index c10b57e0f3a..fb5b3cd8cd4 100644
--- a/trussed/store/fn.delete.html
+++ b/trussed/store/fn.delete.html
@@ -1 +1 @@
-delete in trussed::store - Rust
trussed::store

Function delete

source
pub fn delete(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file +delete in trussed::store - Rust
trussed::store

Function delete

source
pub fn delete(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file diff --git a/trussed/store/fn.exists.html b/trussed/store/fn.exists.html index 339ea76048c..4462aecf741 100644 --- a/trussed/store/fn.exists.html +++ b/trussed/store/fn.exists.html @@ -1 +1 @@ -exists in trussed::store - Rust
trussed::store

Function exists

source
pub fn exists(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file +exists in trussed::store - Rust
trussed::store

Function exists

source
pub fn exists(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file diff --git a/trussed/store/fn.metadata.html b/trussed/store/fn.metadata.html index b992d426bad..9abb08f48ac 100644 --- a/trussed/store/fn.metadata.html +++ b/trussed/store/fn.metadata.html @@ -1,4 +1,4 @@ -metadata in trussed::store - Rust
trussed::store

Function metadata

source
pub fn metadata(
+metadata in trussed::store - Rust
trussed::store

Function metadata

source
pub fn metadata(
     store: impl Store,
     location: Location,
     path: &Path,
diff --git a/trussed/store/fn.remove_dir.html b/trussed/store/fn.remove_dir.html
index d2b0d30462b..f0880083827 100644
--- a/trussed/store/fn.remove_dir.html
+++ b/trussed/store/fn.remove_dir.html
@@ -1 +1 @@
-remove_dir in trussed::store - Rust
trussed::store

Function remove_dir

source
pub fn remove_dir(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file +remove_dir in trussed::store - Rust
trussed::store

Function remove_dir

source
pub fn remove_dir(store: impl Store, location: Location, path: &Path) -> bool
\ No newline at end of file diff --git a/trussed/store/fn.remove_dir_all_where.html b/trussed/store/fn.remove_dir_all_where.html index febf87b4d8d..f6cb8c94d2a 100644 --- a/trussed/store/fn.remove_dir_all_where.html +++ b/trussed/store/fn.remove_dir_all_where.html @@ -1,4 +1,4 @@ -remove_dir_all_where in trussed::store - Rust
trussed::store

Function remove_dir_all_where

source
pub fn remove_dir_all_where(
+remove_dir_all_where in trussed::store - Rust
trussed::store

Function remove_dir_all_where

source
pub fn remove_dir_all_where(
     store: impl Store,
     location: Location,
     path: &Path,
diff --git a/trussed/store/fn.rename.html b/trussed/store/fn.rename.html
index 8a8447e5f86..bfb0d333a1b 100644
--- a/trussed/store/fn.rename.html
+++ b/trussed/store/fn.rename.html
@@ -1,4 +1,4 @@
-rename in trussed::store - Rust
trussed::store

Function rename

source
pub fn rename(
+rename in trussed::store - Rust
trussed::store

Function rename

source
pub fn rename(
     store: impl Store,
     location: Location,
     from: &Path,
diff --git a/trussed/store/index.html b/trussed/store/index.html
index c6030e51d2b..c463b5d3340 100644
--- a/trussed/store/index.html
+++ b/trussed/store/index.html
@@ -1,4 +1,4 @@
-trussed::store - Rust
trussed

Module store

source
Expand description

store presents a combined interface to three littlefs2 filesystems: +trussed::store - Rust

trussed

Module store

source
Expand description

store presents a combined interface to three littlefs2 filesystems: internal flash, external flash, volatile/RAM.

It covers two usecases: