diff --git a/db/db.rs b/db/db.rs index 8ecafd7..bdd7568 100644 --- a/db/db.rs +++ b/db/db.rs @@ -826,8 +826,13 @@ impl LockedDatabase { None => bail!("stream {} has no directory!", stream_id), Some(d) => d, }; + let start = CompositeId::new(stream_id, 0); let end = CompositeId(l.id.0 + 1); - raw::delete_recordings(&tx, dir, CompositeId::new(stream_id, 0) .. end)?; + let n = raw::delete_recordings(&tx, dir, start .. end)? as usize; + if n != s.to_delete.len() { + bail!("Found {} rows in {} .. {}, expected {}: {:?}", + n, start, end, s.to_delete.len(), &s.to_delete); + } } } } diff --git a/db/raw.rs b/db/raw.rs index 6e839de..5c7b68a 100644 --- a/db/raw.rs +++ b/db/raw.rs @@ -122,9 +122,11 @@ pub(crate) fn insert_recording(tx: &rusqlite::Transaction, o: &db::Open, id: Com /// Tranfers the given recording range from the `recording` and `recording_playback` tables to the /// `garbage` table. `sample_file_dir_id` is assumed to be correct. +/// +/// Returns the number of recordings which were deleted. pub(crate) fn delete_recordings(tx: &rusqlite::Transaction, sample_file_dir_id: i32, ids: Range) - -> Result<(), Error> { + -> Result { let mut insert = tx.prepare_cached(r#" insert into garbage (sample_file_dir_id, composite_id) select @@ -148,7 +150,7 @@ pub(crate) fn delete_recordings(tx: &rusqlite::Transaction, sample_file_dir_id: :start <= composite_id and composite_id < :end "#)?; - insert.execute_named(&[ + let n = insert.execute_named(&[ (":sample_file_dir_id", &sample_file_dir_id), (":start", &ids.start.0), (":end", &ids.end.0), @@ -157,9 +159,15 @@ pub(crate) fn delete_recordings(tx: &rusqlite::Transaction, sample_file_dir_id: (":start", &ids.start.0), (":end", &ids.end.0), ]; - del1.execute_named(p)?; - del2.execute_named(p)?; - Ok(()) + let n1 = del1.execute_named(p)?; + if n1 != n { + bail!("inserted {} rows but deleted {} recording rows!", n, n1); + } + let n2 = del2.execute_named(p)?; + if n2 != n { + bail!("deleted {} recording rows but {} recording_playback rows!", n, n2); + } + Ok(n) } /// Marks the given sample files as deleted. This shouldn't be called until the files have