Report which email failed to import when the blob is too large (fixes #22)
This commit is contained in:
@@ -27,6 +27,18 @@ pub fn blob_bytes(conn: &Connection, id: i64) -> Result<Option<Vec<u8>>, rusqlit
|
||||
.optional()
|
||||
}
|
||||
|
||||
pub fn blob_len(conn: &Connection, id: i64) -> Result<Option<u64>, rusqlite::Error> {
|
||||
conn.query_row(
|
||||
"SELECT length(data) FROM blobs WHERE id = ?1",
|
||||
params![id],
|
||||
|row| {
|
||||
let len: i64 = row.get(0)?;
|
||||
Ok(len.max(0) as u64)
|
||||
},
|
||||
)
|
||||
.optional()
|
||||
}
|
||||
|
||||
pub fn gc_orphan_blobs(conn: &Connection) -> Result<usize, rusqlite::Error> {
|
||||
conn.execute(
|
||||
"DELETE FROM blobs WHERE id NOT IN (
|
||||
@@ -77,6 +89,14 @@ mod tests {
|
||||
assert_eq!(blob_bytes(&c, 9999).unwrap(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blob_len_reports_byte_length() {
|
||||
let c = mem();
|
||||
let id = intern_blob(&c, b"payload").unwrap();
|
||||
assert_eq!(blob_len(&c, id).unwrap(), Some(7));
|
||||
assert_eq!(blob_len(&c, 9999).unwrap(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gc_keeps_referenced_and_reaps_orphans() {
|
||||
let c = mem();
|
||||
|
||||
Reference in New Issue
Block a user