π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Preserve known album ownership when metadata is unavailable
Manav Rathi0fb46afa5fb8
diff --git a/rust/apps/cli-next/src/photos/export/source.rs b/rust/apps/cli-next/src/photos/export/source.rsindex 557bf9393d..c2ca06e14a 100644--- a/rust/apps/cli-next/src/photos/export/source.rs+++ b/rust/apps/cli-next/src/photos/export/source.rs@@ -33,6 +33,7 @@ impl<'a> ReplicaSource<'a> {.or(name);CollectionEntry {id,+ owner_id: record.remote.owner.id,name,favorites,value,diff --git a/rust/apps/cli-next/tests/support/export_adoption.rs b/rust/apps/cli-next/tests/support/export_adoption.rsindex 592cc8678c..8a06f05e66 100644--- a/rust/apps/cli-next/tests/support/export_adoption.rs+++ b/rust/apps/cli-next/tests/support/export_adoption.rs@@ -658,7 +658,10 @@ fn adoption_relocates_an_unavailable_go_album_named_trash_without_inventing_natifs::write(root.join("Trash/user.txt"), b"keep").unwrap();}fs::write(root.join("Trash/Photo.jpg"), b"historical local edit").unwrap();- assert!(engine.run(true, &[]).unwrap().complete);+ let mut options = engine.options(true, &[]);+ options.exclude_shared = true;+ let export = engine.prepare(options).unwrap();+ assert!(engine.execute(export).unwrap().complete);assert_eq!(fs::read(root.join("Trash/Trash-1/Photo.jpg")).unwrap(),b"historical local edit"diff --git a/rust/apps/cli-next/tests/support/export_engine.rs b/rust/apps/cli-next/tests/support/export_engine.rsindex 7b72cb6317..b1b12d4683 100644--- a/rust/apps/cli-next/tests/support/export_engine.rs+++ b/rust/apps/cli-next/tests/support/export_engine.rs@@ -22,6 +22,7 @@ impl Catalog {let (shared, hidden) = self.categories.get(&id).copied().unwrap_or_default();CollectionEntry {id,+ owner_id: self.user + i64::from(shared),name: Some(name.clone()),favorites: false,value: Ok((diff --git a/rust/apps/cli-next/tests/support/export_media.rs b/rust/apps/cli-next/tests/support/export_media.rsindex 4e3c9bb82d..c201f26c44 100644--- a/rust/apps/cli-next/tests/support/export_media.rs+++ b/rust/apps/cli-next/tests/support/export_media.rs@@ -198,6 +198,24 @@ fn engine_category_filters_recheck_recovered_metadata() {fs::read(engine.root().join("Second/Photo.jpg")).unwrap(),b"original");+ engine.catalog.categories.insert(2, (true, false));+ engine.catalog.unreadable_album = Some(2);+ for disappeared in [false, true] {+ if disappeared {+ engine.catalog.albums.remove(&2);+ }+ let mut options = engine.options(false, &[]);+ options.exclude_shared = true;+ options.exclude_hidden = true;+ let export = engine.prepare(options).unwrap();+ assert!(engine.execute(export).unwrap().complete);+ assert!(engine.root().join("Second/Photo.jpg").exists());+ }+ let mut options = engine.options(false, &[]);+ options.exclude_hidden = true;+ let export = engine.prepare(options).unwrap();+ assert!(engine.execute(export).unwrap().complete);+ assert!(engine.root().join("Trash/Second/Photo.jpg").exists());fetched.assert();}diff --git a/rust/crates/photos-export/src/adopt.rs b/rust/crates/photos-export/src/adopt.rsindex 3940fd287a..914badc2ea 100644--- a/rust/crates/photos-export/src/adopt.rs+++ b/rust/crates/photos-export/src/adopt.rs@@ -228,13 +228,9 @@ fn parse_album(root: &Path, directory: &Path, retained: bool) -> Result<Option<A};let folder = directory.strip_prefix(root)?- .iter()- .map(|part| {- part.to_str()- .context("claimed Ente album path is not UTF-8")- })- .collect::<Result<Vec<_>>>()?- .join("/");+ .to_str()+ .context("claimed Ente album path is not UTF-8")?+ .replace(std::path::MAIN_SEPARATOR, "/");names::check(root, &format!("{folder}/metadata.json"))?;let id = parse_id(identity, "albumID")?;let name = record["title"]diff --git a/rust/crates/photos-export/src/lib.rs b/rust/crates/photos-export/src/lib.rsindex 71fab924bc..56b4d3ab6a 100644--- a/rust/crates/photos-export/src/lib.rs+++ b/rust/crates/photos-export/src/lib.rs@@ -191,22 +191,29 @@ impl Export {))})? {let (id, name, metadata) = row?;- store.recover_album(id, &name, serde_json::from_str(&metadata)?)?;+ store.recover_album(id, &name, serde_json::from_str(&metadata)?, None)?;}drop(albums);if let Some(index) = &index {- let mut albums = index.db.prepare("SELECT id,json_extract(record,'$.album.name'),json_extract(record,'$.json.value') FROM adoption_album ORDER BY retained")?;+ let mut albums = index.db.prepare("SELECT id,json_extract(record,'$.album.name'),json_extract(record,'$.json.value'),json_extract(record,'$.legacy.owner') FROM adoption_album ORDER BY retained")?;for row in albums.query_map([], |r| {Ok((r.get::<_, i64>(0)?,r.get::<_, String>(1)?,r.get::<_, Option<String>>(2)?,+ r.get::<_, Option<i64>>(3)?,))})? {- let (id, name, metadata) = row?;- if let Some(metadata) = metadata {- store.recover_album(id, &name, serde_json::from_str(&metadata)?)?;- }+ let (id, name, metadata, owner) = row?;+ store.recover_album(+ id,+ &name,+ metadata+ .map(|metadata| serde_json::from_str(&metadata))+ .transpose()?+ .unwrap_or(Value::Null),+ owner.map(|owner| owner != session.user_id),+ )?;store.db.execute("INSERT OR IGNORE INTO desired_albums(id,name) VALUES(?1,?2)",params![id, name],diff --git a/rust/crates/photos-export/src/source.rs b/rust/crates/photos-export/src/source.rsindex 9170faec91..d119305de2 100644--- a/rust/crates/photos-export/src/source.rs+++ b/rust/crates/photos-export/src/source.rs@@ -6,6 +6,7 @@ use ente_photos::{collections::Collection, files::File, source::Documents};pub struct CollectionEntry {pub id: i64,+ pub owner_id: i64,pub name: Option<String>,pub favorites: bool,pub value: Result<(Collection, Documents)>,diff --git a/rust/crates/photos-export/src/store.rs b/rust/crates/photos-export/src/store.rsindex fdacc9565b..975c32a4ec 100644--- a/rust/crates/photos-export/src/store.rs+++ b/rust/crates/photos-export/src/store.rs@@ -568,11 +568,7 @@ impl Store {}pub fn desired_album(&self, entry: &CollectionEntry, user_id: i64) -> Result<()> {- let shared = entry- .value- .as_ref()- .ok()- .map(|(album, _)| album.owner_id != user_id);+ let shared = entry.owner_id != user_id;let hidden = entry.value.as_ref()@@ -582,27 +578,30 @@ impl Store {"INSERT INTO desired_albums(id,name,present,favorites,shared,hidden) VALUES(?1,?2,1,?3,?4,?5) ON CONFLICT(id) DO UPDATE SET name=excluded.name,present=1,favorites=excluded.favorites,shared=excluded.shared,hidden=excluded.hidden",params![entry.id, entry.name, entry.favorites, shared, hidden],)?;- if let Ok((album, _)) = &entry.value {- let mut source: AlbumSource = json(- &self.db,- "SELECT record FROM album_sources WHERE id=?1",- [entry.id],- )?- .unwrap_or(AlbumSource {- name: album.name.clone(),- shared: None,- hidden: None,- metadata: Value::Null,- warnings: Vec::new(),- });- source.shared = shared;- source.hidden = hidden;- self.save_album_source(entry.id, &source)?;- }- Ok(())+ let mut source: AlbumSource = json(+ &self.db,+ "SELECT record FROM album_sources WHERE id=?1",+ [entry.id],+ )?+ .unwrap_or(AlbumSource {+ name: entry.name.clone().unwrap_or_default(),+ shared: None,+ hidden: None,+ metadata: Value::Null,+ warnings: Vec::new(),+ });+ source.shared = Some(shared);+ source.hidden = hidden.or(source.hidden);+ self.save_album_source(entry.id, &source)}- pub fn recover_album(&self, id: i64, name: &str, metadata: Value) -> Result<()> {+ pub fn recover_album(+ &self,+ id: i64,+ name: &str,+ metadata: Value,+ shared: Option<bool>,+ ) -> Result<()> {let mut source: AlbumSource = json(&self.db,"SELECT record FROM album_sources WHERE id=?1",@@ -615,6 +614,7 @@ impl Store {metadata: Value::Null,warnings: Vec::new(),});+ source.shared = source.shared.or(shared);source.hidden = source.hidden.or_else(|| {metadata["ente"]["visibility"].as_str()