Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Reuse name allocation for occupied Trash folders

Manav Rathib3c119b0b70c
diff --git a/rust/crates/photos-export/src/names.rs b/rust/crates/photos-export/src/names.rs
index 7f14595b20..3da164e3c1 100644
--- a/rust/crates/photos-export/src/names.rs
+++ b/rust/crates/photos-export/src/names.rs
@@ -1,4 +1,5 @@
use std::{
+ collections::HashSet,
fs,
path::{Component, Path},
};
@@ -174,12 +175,18 @@ pub fn allocate(
kind: &str,
extensions: Option<(&str, &str)>,
owner: &str,
+ occupied: &HashSet<String>,
) -> Result<Vec<String>> {
for suffix in 0u64.. {
let Some(candidates) = candidates(name, kind == "album", extensions, suffix)? else {
continue;
};
- if available(store, folder, &candidates, owner, kind)? {
+ if (occupied.is_empty()
+ || candidates
+ .iter()
+ .all(|name| !occupied.contains(&folded(name))))
+ && available(store, folder, &candidates, owner, kind)?
+ {
return Ok(candidates);
}
}
diff --git a/rust/crates/photos-export/src/reconcile.rs b/rust/crates/photos-export/src/reconcile.rs
index cb72fac776..c62d49bab7 100644
--- a/rust/crates/photos-export/src/reconcile.rs
+++ b/rust/crates/photos-export/src/reconcile.rs
@@ -818,19 +818,8 @@ impl Run<'_> {
&& names::available(&store, parent, &[name.to_owned()], &owner, "album")?
{
vec![name.to_owned()]
- } else if !occupied.is_empty() {
- let mut suffix = 0;
- loop {
- if let Some(candidates) = names::candidates(name, true, None, suffix)?
- && !occupied.contains(&names::folded(&candidates[0]))
- && names::available(&store, parent, &candidates, &owner, "album")?
- {
- break candidates;
- }
- suffix += 1;
- }
} else {
- names::allocate(&store, parent, name, "album", None, &owner)?
+ names::allocate(&store, parent, name, "album", None, &owner, &occupied)?
};
let target = Pending {
owner,
@@ -1035,6 +1024,7 @@ impl Run<'_> {
None
},
&owner,
+ &HashSet::new(),
)?
};
let target = Pending {
@@ -1474,6 +1464,7 @@ impl Run<'_> {
&placement.kind,
extensions,
&placement.id,
+ &HashSet::new(),
)?;
let target = Pending {
owner: placement.id,