genpolicy: Fix clippy manual_unwrap_or_default

Manually fix `manual_unwrap_or_default` clippy warning reported by rust
1.85.1.

```console
error: if let can be simplified with `.unwrap_or_default()`
   --> src/registry.rs:619:37
    |
619 |       let mut data: Vec<ImageLayer> = if let Ok(vec) = serde_json::from_reader(read_file) {
    |  _____________________________________^
620 | |         vec
621 | |     } else {
...   |
624 | |     };
    | |_____^ help: replace it with: `serde_json::from_reader(read_file).unwrap_or_default()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
    = note: `-D clippy::manual-unwrap-or-default` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or_default)]`
```

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He
2025-06-05 12:04:53 +00:00
parent a71a77bfa3
commit 366d293141

View File

@@ -575,12 +575,8 @@ pub fn add_verity_and_users_to_store(
.truncate(false)
.open(cache_file)?;
let mut data: Vec<ImageLayer> = if let Ok(vec) = serde_json::from_reader(read_file) {
vec
} else {
// Delete the malformed file here if it's present
Vec::new()
};
// Return empty vector if the file is malformed
let mut data: Vec<ImageLayer> = serde_json::from_reader(read_file).unwrap_or_default();
// Add new data to the deserialized JSON
data.push(ImageLayer {