mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-25 02:30:15 -06:00
PR218: satisfy current CI clippy without changing import behavior
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -50,9 +50,8 @@ pub fn store(directory: &Path, data: &CatalogImport) -> Result<PathBuf, String>
|
||||
managed.sort_by_key(|entry| entry.index);
|
||||
|
||||
let temporary = temporary_path(directory)?;
|
||||
write_archive(&temporary, data).map_err(|error| {
|
||||
write_archive(&temporary, data).inspect_err(|_| {
|
||||
let _ = remove_managed_file(&temporary);
|
||||
error
|
||||
})?;
|
||||
|
||||
let recent = managed.iter().rev().take(MAX_MANAGED_ARCHIVES);
|
||||
@@ -351,7 +350,7 @@ fn retirement_set_protected(entries: &[Managed], protected: Option<&Path>) -> Re
|
||||
let mut total = ordered.iter().try_fold(0u64, |sum, entry| sum.checked_add(entry.size)).ok_or("archive size overflow")?;
|
||||
let mut retirees = Vec::new();
|
||||
while ordered.len() > MAX_MANAGED_ARCHIVES || total > MAX_TOTAL_ARCHIVE_BYTES {
|
||||
let Some(position) = ordered.iter().position(|entry| protected.map_or(true, |path| entry.path != path)) else {
|
||||
let Some(position) = ordered.iter().position(|entry| protected.is_none_or(|path| entry.path != path)) else {
|
||||
return Err("cannot satisfy archive retention limit".into());
|
||||
};
|
||||
let oldest = ordered.remove(position);
|
||||
|
||||
@@ -363,7 +363,7 @@ impl Reader {
|
||||
.iter()
|
||||
.zip(columns)
|
||||
.find_map(|(value, column)| {
|
||||
(column == "image").then(|| match value {
|
||||
(column == "image").then_some(match value {
|
||||
SqlValue::Integer(n) => *n,
|
||||
_ => 0,
|
||||
})
|
||||
@@ -628,7 +628,7 @@ pub fn read_with_progress(path: &Path, cancel: &AtomicBool, total: &AtomicUsize,
|
||||
return Err("catalog changed during reading; close Lightroom and retry".into());
|
||||
}
|
||||
let reader = Reader { tables: db.live_tables()?, db };
|
||||
let mut table = |name: &str, required: bool| -> Result<Vec<Row>, String> {
|
||||
let table = |name: &str, required: bool| -> Result<Vec<Row>, String> {
|
||||
ensure_read_active(cancel)?;
|
||||
let rows = reader.table(name, required)?;
|
||||
done.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
@@ -91,7 +91,7 @@ impl Database {
|
||||
}
|
||||
let page_size = sqlite_page_size(be_u16(main_header, 16)?)?;
|
||||
validate_header_fields(main_header, page_size)?;
|
||||
if main.len() < page_size || main.len() % page_size != 0 {
|
||||
if main.len() < page_size || !main.len().is_multiple_of(page_size) {
|
||||
return Err("SQLite image is not a whole number of pages".into());
|
||||
}
|
||||
let main_pages = u32::try_from(main.len() / page_size).map_err(|_| "SQLite image is too large")?;
|
||||
@@ -225,10 +225,8 @@ impl Database {
|
||||
if index >= values.len() {
|
||||
return Err("INTEGER PRIMARY KEY column is missing from record".into());
|
||||
}
|
||||
if matches!(values.get(index), Some(Value::Null)) {
|
||||
if let Some(value) = values.get_mut(index) {
|
||||
*value = Value::Integer(rowid);
|
||||
}
|
||||
if let Some(value @ Value::Null) = values.get_mut(index) {
|
||||
*value = Value::Integer(rowid);
|
||||
}
|
||||
}
|
||||
if state.out.len() >= MAX_ROWS {
|
||||
@@ -524,7 +522,7 @@ fn decode_text(bytes: &[u8], encoding: TextEncoding) -> Result<String, String> {
|
||||
match encoding {
|
||||
TextEncoding::Utf8 => String::from_utf8(bytes.to_vec()).map_err(|_| "invalid UTF-8 SQLite text".into()),
|
||||
TextEncoding::Utf16Le | TextEncoding::Utf16Be => {
|
||||
if bytes.len() % 2 != 0 {
|
||||
if !bytes.len().is_multiple_of(2) {
|
||||
return Err("odd-length UTF-16 SQLite text".into());
|
||||
}
|
||||
let units: Result<Vec<u16>, String> = bytes
|
||||
@@ -626,12 +624,12 @@ fn parse_create_table(sql: &str) -> Result<(Vec<String>, Option<usize>), String>
|
||||
if columns.is_empty() {
|
||||
return Err("CREATE TABLE has no columns".into());
|
||||
}
|
||||
if alias.is_none() {
|
||||
if let Some(primary) = table_primary {
|
||||
let key = primary.to_ascii_lowercase();
|
||||
if integer_columns.contains(&key) {
|
||||
alias = columns.iter().position(|column| column.eq_ignore_ascii_case(&primary));
|
||||
}
|
||||
if alias.is_none()
|
||||
&& let Some(primary) = table_primary
|
||||
{
|
||||
let key = primary.to_ascii_lowercase();
|
||||
if integer_columns.contains(&key) {
|
||||
alias = columns.iter().position(|column| column.eq_ignore_ascii_case(&primary));
|
||||
}
|
||||
}
|
||||
Ok((columns, alias))
|
||||
|
||||
Reference in New Issue
Block a user