Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions aw-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,19 @@ fn sync_one(
info!(" = Synced {} new events", new_events_count);
} else {
info!(" ✓ Already up to date!");
// Resume-from-newest is one-way: events older than dest's newest are never
// fetched. If a short recent slice was imported first, a later pull of the
// complete history reports "up to date" while dest is missing most of it.
// Warn loudly so that case is diagnosable (ActivityWatch/aw-server-rust#683).
if resume_sync_at.is_some() {
let src_count = ds_from.get_event_count(bucket_from.id.as_str())?;
if src_count > eventcount_to_new {
warn!(
" ! Source bucket '{}' has {src_count} events but destination '{}' has {eventcount_to_new} after a resume-from-newest pull. Older history in the source was not imported. Delete the destination bucket and re-pull to recover.",
bucket_from.id, bucket_to.id
);
}
}
}

Ok(())
Expand Down
35 changes: 27 additions & 8 deletions aw-sync/src/sync_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use crate::sync::{sync_run, SyncMode, SyncSpec};
use aw_client_rust::blocking::AwClient;

pub fn pull_all(client: &AwClient) -> Result<(), Box<dyn Error>> {
let hostnames = crate::util::get_remotes()?;
for host in hostnames {
pull(&host, client)?
let sync_root = crate::dirs::get_sync_dir().map_err(|_| "Could not get sync dir")?;
let dbs = crate::util::list_remote_dbs(&sync_root)?;
let selected = crate::util::select_remote_dbs_by_device_id(dbs);
if selected.is_empty() {
info!("No remote databases found in {:?}", sync_root);
return Ok(());
}
info!(
"Pulling {} remote database(s): {:?}",
selected.len(),
selected
.iter()
.map(|d| d.path.display().to_string())
.collect::<Vec<_>>()
);
for remote in selected {
pull_db(client, &remote.hostname, &remote.path)?;
}
Ok(())
}

pub fn pull(host: &str, client: &AwClient) -> Result<(), Box<dyn Error>> {
client.wait_for_start()?;

// Path to the sync folder
// Sync folder is structured ./{hostname}/{device_id}/test.db
let sync_root_dir = crate::dirs::get_sync_dir().map_err(|_| "Could not get sync dir")?;
Expand Down Expand Up @@ -45,14 +58,20 @@ pub fn pull(host: &str, client: &AwClient) -> Result<(), Box<dyn Error>> {
.max_by_key(|entry| entry.metadata().map(|m| m.len()).unwrap_or(0))
.ok_or_else(|| format!("No db found in sync folder {:?}", sync_dir))?;

pull_db(client, host, &db.path())
}

fn pull_db(client: &AwClient, host: &str, db_path: &Path) -> Result<(), Box<dyn Error>> {
client.wait_for_start()?;
let sync_root_dir = crate::dirs::get_sync_dir().map_err(|_| "Could not get sync dir")?;
let sync_dir = sync_root_dir.join(host);
let sync_spec = SyncSpec {
path: sync_dir.clone(),
path_db: Some(db.path().clone()),
path: sync_dir,
path_db: Some(db_path.to_path_buf()),
buckets: None, // Sync all buckets by default
start: None,
};
sync_run(client, &sync_spec, SyncMode::Pull)?;

Ok(())
}

Expand Down
Loading
Loading