💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Share CLI location data between accounts
laurenspriem56f0f9cc3fd1
diff --git a/docs/docs/cli/accounts.md b/docs/docs/cli/accounts.mdindex 29782d23eb..2ab1887b78 100644--- a/docs/docs/cli/accounts.md+++ b/docs/docs/cli/accounts.md@@ -114,7 +114,7 @@ Prints `Logged out of Ente Auth for "[email protected]".` Without `--app`, the C## CLI home-The CLI home is the directory where the CLI keeps its data: an encrypted vault with your accounts and keys, a database per account with synced metadata and, once you use places, the location data they need. Learn more in [Photos](./photos.md#find-files-by-place).+The CLI home is the directory where the CLI keeps its data: an encrypted vault with your accounts and keys, a database per account with synced metadata and, once you use places, location data shared by all accounts. Learn more in [Photos](./photos.md#find-files-by-place).| System | CLI home || ------- | ---------------------------------------------------------------------- |diff --git a/docs/docs/cli/photos.md b/docs/docs/cli/photos.mdindex dd15499b81..15c9b3e785 100644--- a/docs/docs/cli/photos.md+++ b/docs/docs/cli/photos.md@@ -120,7 +120,7 @@ ente photos file list --country JP --type video`--place` keeps files taken in a city whose name contains the given text. When one of the cities `place list` shows for the same `--album` has exactly that name, only cities with that name match, so `--place nice` leaves out Venice. `--country` takes a two-letter code such as `PT`, or a full English country name, which matches only that country, so `--country niger` leaves out Nigeria; other text matches every country whose name contains it. `UK` also works for the United Kingdom, whose code is `GB`, and an unknown two-letter code is an error. Both ignore case and accent marks, and combine with the other filters. Type letters such as ł or ø as `place list` shows them: `--place wrocław` finds Wrocław, but `--place wroclaw` does not.-The first time you use places, the CLI downloads about 7 MB of location data from Ente (`assets.ente.com`) and keeps it with the account's local data. After that, places work with `--offline`. The location data is adapted from [GeoNames](https://www.geonames.org/) and the European Commission Joint Research Centre's [GHS-UCDB R2024A](https://doi.org/10.2905/1a338be6-7eaf-480c-9664-3a8ade88cbcd), both under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), and from [Natural Earth](https://www.naturalearthdata.com/), which is in the public domain.+The first time you use places, the CLI downloads about 7 MB of location data from Ente (`assets.ente.com`) and keeps it in the CLI home, where all your accounts share it. After that, places work with `--offline`. The location data is adapted from [GeoNames](https://www.geonames.org/) and the European Commission Joint Research Centre's [GHS-UCDB R2024A](https://doi.org/10.2905/1a338be6-7eaf-480c-9664-3a8ade88cbcd), both under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), and from [Natural Earth](https://www.naturalearthdata.com/), which is in the public domain.## Check storage and file countdiff --git a/rust/apps/cli/src/args.rs b/rust/apps/cli/src/args.rsindex 8028db9ea5..ead3d1057e 100644--- a/rust/apps/cli/src/args.rs+++ b/rust/apps/cli/src/args.rs@@ -688,7 +688,7 @@ Groups files by their location and lists the most files first. Files without a lor whose location matches no city (or with --countries, no country), are not counted.--country uses the groups --countries shows, which can differ from a city's country:photos in French Guiana count under France.-On first use, downloads about 7 MB of location data and keeps it with the account's local data.+On first use, downloads about 7 MB of location data and keeps it in the CLI home for all accounts.With --json, returns an array. City fields: name, country, countryCode (strings);latitude, longitude of the city (numbers); fileCount (integer). With --countries: name, code (strings); fileCount (integer).";diff --git a/rust/apps/cli/src/home.rs b/rust/apps/cli/src/home.rsindex a796188d33..114dd5f49b 100644--- a/rust/apps/cli/src/home.rs+++ b/rust/apps/cli/src/home.rs@@ -48,6 +48,13 @@ pub fn application_home() -> Result<PathBuf> {.join("ente-cli"))}+pub fn lock_assets() -> Result<File> {+ let lock = open_lock(&application_home()?.join("assets.lock"))+ .context("cannot open the assets lock")?;+ lock.lock().context("cannot lock the assets")?;+ Ok(lock)+}+pub fn create(path: &Path) -> io::Result<()> {#[cfg(unix)]use std::os::unix::fs::DirBuilderExt;diff --git a/rust/apps/cli/src/photos/mod.rs b/rust/apps/cli/src/photos/mod.rsindex c94b4ec96a..f8480ff8a5 100644--- a/rust/apps/cli/src/photos/mod.rs+++ b/rust/apps/cli/src/photos/mod.rs@@ -58,26 +58,10 @@ pub async fn run(command: PhotosCommand, selected: Option<&str>, options: &OptioPhotosCommand::Api(_) | PhotosCommand::Export(_) | PhotosCommand::Usage => unreachable!(),PhotosCommand::Album { command } => album(command, &replica, options),PhotosCommand::File { album, command } => {- file(- command,- album.as_deref(),- &session,- &mut replica,- &home.path,- options,- )- .await+ file(command, album.as_deref(), &session, &mut replica, options).await}PhotosCommand::Place { album, command } => {- place(- command,- album.as_deref(),- &session,- &mut replica,- &home.path,- options,- )- .await+ place(command, album.as_deref(), &session, &mut replica, options).await}}}@@ -182,13 +166,12 @@ async fn file(album: Option<&str>,session: &Session,replica: &mut Replica<'_>,- home: &Path,options: &Options,) -> Result<()> {let (album_id, mut incomplete) = sync_files(album, session, replica, options).await?;let placed = match &command {FileCommand::List { query, .. } if query.place.is_some() || query.country.is_some() => {- let index = places::open(home, options.offline).await?;+ let index = places::open(options.offline).await?;let located = located(replica, album_id, |_, _| {})?;Some(places::matching(&index, query, &located)?)}@@ -306,12 +289,11 @@ async fn place(album: Option<&str>,session: &Session,replica: &mut Replica<'_>,- home: &Path,options: &Options,) -> Result<()> {let (album_id, mut incomplete) = sync_files(album, session, replica, options).await?;let PlaceCommand::List { countries, list } = command;- let index = places::open(home, options.offline).await?;+ let index = places::open(options.offline).await?;let located = located(replica, album_id, |id, error| {eprintln!("file {id}: {error:#}");incomplete = true;diff --git a/rust/apps/cli/src/photos/places.rs b/rust/apps/cli/src/photos/places.rsindex 6b2e0f95fe..0851d588d8 100644--- a/rust/apps/cli/src/photos/places.rs+++ b/rust/apps/cli/src/photos/places.rs@@ -1,4 +1,4 @@-use std::{collections::HashSet, path::Path};+use std::collections::HashSet;use anyhow::{Context, Result, ensure};use ente_location::{Coordinate, CountryCode, normalize_search_text};@@ -6,18 +6,25 @@ use ente_photos::{files::File, location::LocationIndex};use crate::{args::{FileQuery, ListArgs},+ home,output::{self, CityView, CountryView},};-pub async fn open(home: &Path, offline: bool) -> Result<LocationIndex> {- let root = home.join("assets");- if !LocationIndex::is_downloaded(&root) {+pub async fn open(offline: bool) -> Result<LocationIndex> {+ let root = home::application_home()?.join("assets");+ let _download = if LocationIndex::is_downloaded(&root) {+ None+ } else {ensure!(!offline,"location data has not been downloaded; run the command online first");- eprintln!("Downloading location data.");- }+ let lock = home::lock_assets()?;+ if !LocationIndex::is_downloaded(&root) {+ eprintln!("Downloading location data.");+ }+ Some(lock)+ };LocationIndex::open(&root).await.context("cannot load location data")diff --git a/rust/apps/cli/tests/cli/museum.rs b/rust/apps/cli/tests/cli/museum.rsindex 82ca0d491d..39e713f641 100644--- a/rust/apps/cli/tests/cli/museum.rs+++ b/rust/apps/cli/tests/cli/museum.rs@@ -688,6 +688,44 @@ fn places_group_files_by_city_and_country() -> TestResult {})}+#[test]+fn accounts_share_one_location_download() -> TestResult {+ Museum::run_async(|origin| async move {+ let home = TestHome::new();+ let accounts = ["first", "second"];+ for name in accounts {+ let email = format!("places-{name}-{}@example.org", Uuid::new_v4());+ create_account(&origin, &email).await;+ login(+ &home,+ "photos",+ &email,+ &["--host", &origin, "--account", name],+ );+ }+ let commands = accounts.map(|name| {+ home.command(&["photos", "place", "list", "--account", name])+ .spawn()+ .unwrap()+ });+ let downloads = commands+ .into_iter()+ .map(|command| success(command.wait_with_output().unwrap()))+ .filter(|output| {+ String::from_utf8_lossy(&output.stderr).contains("Downloading location data.")+ })+ .count();+ assert_eq!(downloads, 1);+ assert!(+ home.dir+ .path()+ .join("assets/location/v2/cities.bin")+ .is_file()+ );+ Ok(())+ })+}+async fn exercise(origin: String) -> TestResult {let alice_email = format!("alice-{}@example.org", Uuid::new_v4());let bob_email = format!("bob-{}@example.org", Uuid::new_v4());