Satisfy rustfmt and clippy on the album and folder picker changes
rustfmt over the files the albums work touched, and the album merge's incoming row as a named struct rather than an eight-field tuple, which clippy's type_complexity refused.
This commit is contained in:
@@ -128,7 +128,12 @@ pub fn create(conn: &Connection, name: &str, place: &Place) -> Result<AlbumId, C
|
||||
tx.execute(
|
||||
"INSERT INTO albums(uuid, name, server_path, created, revision, modified)
|
||||
VALUES (?1, ?2, ?3, ?4, 1, ?4)",
|
||||
rusqlite::params![crate::collections::new_uuid(), name, server_path(place), now],
|
||||
rusqlite::params![
|
||||
crate::collections::new_uuid(),
|
||||
name,
|
||||
server_path(place),
|
||||
now
|
||||
],
|
||||
)?;
|
||||
let id = AlbumId(tx.last_insert_rowid() as u64);
|
||||
if let Place::Local(folder) = place {
|
||||
@@ -206,8 +211,14 @@ pub fn delete(conn: &Connection, id: AlbumId) -> Result<(), CatalogError> {
|
||||
if n == 0 {
|
||||
return Err(CatalogError::NoSuchAlbum(id.0));
|
||||
}
|
||||
tx.execute("DELETE FROM album_exports WHERE album_id = ?1", [id.0 as i64])?;
|
||||
tx.execute("DELETE FROM album_folders WHERE album_id = ?1", [id.0 as i64])?;
|
||||
tx.execute(
|
||||
"DELETE FROM album_exports WHERE album_id = ?1",
|
||||
[id.0 as i64],
|
||||
)?;
|
||||
tx.execute(
|
||||
"DELETE FROM album_folders WHERE album_id = ?1",
|
||||
[id.0 as i64],
|
||||
)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -424,7 +435,11 @@ mod tests {
|
||||
record_exports(
|
||||
conn,
|
||||
album,
|
||||
&[(a, "a.jpg".into()), (a, "a (1).jpg".into()), (b, "b.jpg".into())],
|
||||
&[
|
||||
(a, "a.jpg".into()),
|
||||
(a, "a (1).jpg".into()),
|
||||
(b, "b.jpg".into()),
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -490,9 +505,11 @@ mod tests {
|
||||
let album = create(conn, "Web", &Place::Local("/out".into())).unwrap();
|
||||
rename(conn, album, "Website").unwrap();
|
||||
let rev: i64 = conn
|
||||
.query_row("SELECT revision FROM albums WHERE id = ?1", [album.0 as i64], |r| {
|
||||
r.get(0)
|
||||
})
|
||||
.query_row(
|
||||
"SELECT revision FROM albums WHERE id = ?1",
|
||||
[album.0 as i64],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(rev, 2);
|
||||
}
|
||||
|
||||
@@ -239,7 +239,19 @@ fn merge_albums_within(tx: &Connection, report: &mut MergeReport) -> Result<(),
|
||||
}
|
||||
crate::albums::ensure_tables(tx)?;
|
||||
|
||||
let rows: Vec<(String, String, Option<String>, i64, i64, i64, bool, MergeVerdict)> = {
|
||||
/// One album as the remote has it, and what the verdict made of it.
|
||||
struct IncomingAlbum {
|
||||
uuid: String,
|
||||
name: String,
|
||||
server_path: Option<String>,
|
||||
created: i64,
|
||||
revision: i64,
|
||||
modified: i64,
|
||||
deleted: bool,
|
||||
verdict: MergeVerdict,
|
||||
}
|
||||
|
||||
let rows: Vec<IncomingAlbum> = {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT r.uuid, r.name, r.server_path, r.created, r.revision, r.modified,
|
||||
r.deleted, l.revision, l.modified
|
||||
@@ -253,16 +265,16 @@ fn merge_albums_within(tx: &Connection, report: &mut MergeReport) -> Result<(),
|
||||
let deleted: bool = r.get::<_, i64>(6)? != 0;
|
||||
let local_rev: Option<i64> = r.get(7)?;
|
||||
let local_mod: Option<i64> = r.get(8)?;
|
||||
Ok((
|
||||
r.get(0)?,
|
||||
r.get(1)?,
|
||||
r.get(2)?,
|
||||
r.get(3)?,
|
||||
Ok(IncomingAlbum {
|
||||
uuid: r.get(0)?,
|
||||
name: r.get(1)?,
|
||||
server_path: r.get(2)?,
|
||||
created: r.get(3)?,
|
||||
revision,
|
||||
modified,
|
||||
deleted,
|
||||
verdict(local_rev.zip(local_mod), (revision, modified), deleted),
|
||||
))
|
||||
verdict: verdict(local_rev.zip(local_mod), (revision, modified), deleted),
|
||||
})
|
||||
})?
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
rows
|
||||
@@ -289,29 +301,35 @@ fn merge_albums_within(tx: &Connection, report: &mut MergeReport) -> Result<(),
|
||||
"DELETE FROM main.album_folders
|
||||
WHERE album_id = (SELECT id FROM main.albums WHERE uuid = ?1)",
|
||||
)?;
|
||||
for (uuid, name, server_path, created, revision, modified, deleted, v) in rows {
|
||||
if v == MergeVerdict::KeptLocal {
|
||||
for row in rows {
|
||||
if row.verdict == MergeVerdict::KeptLocal {
|
||||
report.albums_kept_local += 1;
|
||||
continue;
|
||||
}
|
||||
take.execute(rusqlite::params![
|
||||
uuid, name, server_path, created, revision, modified, deleted as i64
|
||||
row.uuid,
|
||||
row.name,
|
||||
row.server_path,
|
||||
row.created,
|
||||
row.revision,
|
||||
row.modified,
|
||||
row.deleted as i64
|
||||
])?;
|
||||
if deleted {
|
||||
forget.execute([&uuid])?;
|
||||
unfold.execute([&uuid])?;
|
||||
} else if server_path.is_some() {
|
||||
if row.deleted {
|
||||
forget.execute([&row.uuid])?;
|
||||
unfold.execute([&row.uuid])?;
|
||||
} else if row.server_path.is_some() {
|
||||
// Another device moved the album to the server with the newer
|
||||
// revision; a local folder chosen here is no longer where it
|
||||
// goes.
|
||||
unfold.execute([&uuid])?;
|
||||
unfold.execute([&row.uuid])?;
|
||||
}
|
||||
report.albums_taken += 1;
|
||||
}
|
||||
}
|
||||
|
||||
report.album_exports_added =
|
||||
tx.execute(ALBUM_EXPORTS_BY_FILE_ID, [])? + tx.execute(ALBUM_EXPORTS_BY_CONTENT_HASH, [])?;
|
||||
report.album_exports_added = tx.execute(ALBUM_EXPORTS_BY_FILE_ID, [])?
|
||||
+ tx.execute(ALBUM_EXPORTS_BY_CONTENT_HASH, [])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user