Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Dec 15, 2023
1 parent 4a3e612 commit bd3d9af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mbtiles/src/bin/mbtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ enum Commands {
/// Value to set, or nothing if the key should be deleted.
value: Option<String>,
},
#[command(name = "diff")]
Diff{
/// MBTiles file to read from
src_file: PathBuf,
/// MBTiles file to write to
dst_file: PathBuf,
/// MBTiles file to write diff to
diff_file: PathBuf,
},
/// Copy tiles from one mbtiles file to another.
#[command(name = "copy", alias = "cp")]
Copy(MbtilesCopier),
Expand Down Expand Up @@ -138,6 +147,10 @@ async fn main_int() -> anyhow::Result<()> {
println!("MBTiles file summary for {mbt}");
println!("{}", mbt.summary(&mut conn).await?);
}
Commands::Diff { src_file, dst_file, diff_file } => {
let src = Mbtiles::new(src_file)?;
src.diff(dst_file, diff_file).await?;
},
}

Ok(())
Expand Down
29 changes: 29 additions & 0 deletions mbtiles/src/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::{path::PathBuf, str::FromStr};

use crate::{Mbtiles, MbtError, MbtResult, is_empty_database};

impl Mbtiles {
pub async fn diff(&self, dst_path: PathBuf, diff_path: PathBuf) -> MbtResult<()>{
let src_path = PathBuf::from_str(self.filepath()).unwrap();

if src_path == dst_path {
return Err(MbtError::SameSourceAndDestination(dst_path.clone()));
}
if src_path == diff_path || dst_path == diff_path {
return Err(MbtError::SameDiffAndSourceOrDestination(diff_path.clone()));
}

let dst_mbt = Mbtiles::new(&dst_path)?;

let mut dst_conn = dst_mbt.open_or_new().await?;

let is_empty_db = is_empty_database(&mut dst_conn).await?;
if !is_empty_db {
return Err(MbtError::NonEmptyTargetFile(dst_path.clone()));
}

self.attach_to(&mut dst_conn, "sourceDb").await?;

todo!()
}
}
1 change: 1 addition & 0 deletions mbtiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub use sqlx;

mod copier;
mod diff;
pub use copier::{CopyDuplicateMode, MbtilesCopier};

mod errors;
Expand Down

0 comments on commit bd3d9af

Please sign in to comment.