run clippy fix

This commit is contained in:
Lennart K
2025-10-27 19:01:04 +01:00
parent 08041c60be
commit 0d071d3b92
94 changed files with 455 additions and 484 deletions

View File

@@ -138,26 +138,23 @@ impl SqliteAddressbookStore {
addressbook_id: &str,
use_trashbin: bool,
) -> Result<(), rustical_store::Error> {
match use_trashbin {
true => {
sqlx::query!(
r#"UPDATE addressbooks SET deleted_at = datetime() WHERE (principal, id) = (?, ?)"#,
principal, addressbook_id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
}
false => {
sqlx::query!(
r#"DELETE FROM addressbooks WHERE (principal, id) = (?, ?)"#,
principal,
addressbook_id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
};
if use_trashbin {
sqlx::query!(
r#"UPDATE addressbooks SET deleted_at = datetime() WHERE (principal, id) = (?, ?)"#,
principal, addressbook_id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
} else {
sqlx::query!(
r#"DELETE FROM addressbooks WHERE (principal, id) = (?, ?)"#,
principal,
addressbook_id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
Ok(())
}
@@ -208,8 +205,7 @@ impl SqliteAddressbookStore {
let new_synctoken = changes
.last()
.map(|&Row { synctoken, .. }| synctoken)
.unwrap_or(0);
.map_or(0, |&Row { synctoken, .. }| synctoken);
for Row { object_id, .. } in changes {
match Self::_get_object(&mut *conn, principal, addressbook_id, &object_id, false).await
@@ -259,7 +255,7 @@ impl SqliteAddressbookStore {
.fetch_all(executor)
.await.map_err(crate::Error::from)?
.into_iter()
.map(|row| row.try_into())
.map(std::convert::TryInto::try_into)
.collect()
}
@@ -325,28 +321,25 @@ impl SqliteAddressbookStore {
object_id: &str,
use_trashbin: bool,
) -> Result<(), rustical_store::Error> {
match use_trashbin {
true => {
sqlx::query!(
"UPDATE addressobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, addressbook_id, id) = (?, ?, ?)",
principal,
addressbook_id,
object_id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
}
false => {
sqlx::query!(
"DELETE FROM addressobjects WHERE addressbook_id = ? AND id = ?",
addressbook_id,
object_id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
};
if use_trashbin {
sqlx::query!(
"UPDATE addressobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, addressbook_id, id) = (?, ?, ?)",
principal,
addressbook_id,
object_id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
} else {
sqlx::query!(
"DELETE FROM addressobjects WHERE addressbook_id = ? AND id = ?",
addressbook_id,
object_id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
Ok(())
}
@@ -440,7 +433,7 @@ impl AddressbookStore for SqliteAddressbookStore {
})
{
error!("Push notification about deleted addressbook failed: {err}");
};
}
Ok(())
}
@@ -474,9 +467,9 @@ impl AddressbookStore for SqliteAddressbookStore {
let mut deleted_sizes = vec![];
for (size, deleted) in Self::_list_objects(&self.db, principal, addressbook_id).await? {
if deleted {
deleted_sizes.push(size)
deleted_sizes.push(size);
} else {
sizes.push(size)
sizes.push(size);
}
}
Ok(CollectionMetadata {
@@ -521,8 +514,8 @@ impl AddressbookStore for SqliteAddressbookStore {
Self::_put_object(
&mut *tx,
principal.to_owned(),
addressbook_id.to_owned(),
principal.clone(),
addressbook_id.clone(),
object,
overwrite,
)
@@ -548,7 +541,7 @@ impl AddressbookStore for SqliteAddressbookStore {
.push_topic,
}) {
error!("Push notification about deleted addressbook failed: {err}");
};
}
Ok(())
}
@@ -585,7 +578,7 @@ impl AddressbookStore for SqliteAddressbookStore {
.push_topic,
}) {
error!("Push notification about deleted addressbook failed: {err}");
};
}
Ok(())
}
@@ -619,7 +612,7 @@ impl AddressbookStore for SqliteAddressbookStore {
.push_topic,
}) {
error!("Push notification about deleted addressbook failed: {err}");
};
}
Ok(())
}

View File

@@ -22,7 +22,7 @@ impl TryFrom<CalendarObjectRow> for CalendarObject {
type Error = rustical_store::Error;
fn try_from(value: CalendarObjectRow) -> Result<Self, Self::Error> {
let object = CalendarObject::from_ics(value.ics)?;
let object = Self::from_ics(value.ics)?;
if object.get_id() != value.id {
return Err(rustical_store::Error::IcalError(
rustical_ical::Error::InvalidData(format!(
@@ -213,24 +213,21 @@ impl SqliteCalendarStore {
id: &str,
use_trashbin: bool,
) -> Result<(), Error> {
match use_trashbin {
true => sqlx::query!(
r#"UPDATE calendars SET deleted_at = datetime() WHERE (principal, id) = (?, ?)"#,
principal,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)?,
false => sqlx::query!(
r#"DELETE FROM calendars WHERE (principal, id) = (?, ?)"#,
principal,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)?,
};
if use_trashbin { sqlx::query!(
r#"UPDATE calendars SET deleted_at = datetime() WHERE (principal, id) = (?, ?)"#,
principal,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)? } else { sqlx::query!(
r#"DELETE FROM calendars WHERE (principal, id) = (?, ?)"#,
principal,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)? };
Ok(())
}
@@ -286,7 +283,7 @@ impl SqliteCalendarStore {
.fetch_all(executor)
.await.map_err(crate::Error::from)?
.into_iter()
.map(|row| row.try_into())
.map(std::convert::TryInto::try_into)
.collect()
}
@@ -320,7 +317,7 @@ impl SqliteCalendarStore {
.await
.map_err(crate::Error::from)?
.into_iter()
.map(|row| row.try_into())
.map(std::convert::TryInto::try_into)
.collect()
}
@@ -411,28 +408,25 @@ impl SqliteCalendarStore {
id: &str,
use_trashbin: bool,
) -> Result<(), Error> {
match use_trashbin {
true => {
sqlx::query!(
"UPDATE calendarobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, cal_id, id) = (?, ?, ?)",
principal,
cal_id,
id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
}
false => {
sqlx::query!(
"DELETE FROM calendarobjects WHERE cal_id = ? AND id = ?",
cal_id,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
};
if use_trashbin {
sqlx::query!(
"UPDATE calendarobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, cal_id, id) = (?, ?, ?)",
principal,
cal_id,
id
)
.execute(executor)
.await.map_err(crate::Error::from)?;
} else {
sqlx::query!(
"DELETE FROM calendarobjects WHERE cal_id = ? AND id = ?",
cal_id,
id
)
.execute(executor)
.await
.map_err(crate::Error::from)?;
}
Ok(())
}
@@ -484,8 +478,7 @@ impl SqliteCalendarStore {
let new_synctoken = changes
.last()
.map(|&Row { synctoken, .. }| synctoken)
.unwrap_or(0);
.map_or(0, |&Row { synctoken, .. }| synctoken);
for Row { object_id, .. } in changes {
match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await {
@@ -562,7 +555,7 @@ impl CalendarStore for SqliteCalendarStore {
})
{
error!("Push notification about deleted calendar failed: {err}");
};
}
Ok(())
}
@@ -627,9 +620,9 @@ impl CalendarStore for SqliteCalendarStore {
let mut deleted_sizes = vec![];
for (size, deleted) in Self::_list_objects(&self.db, principal, cal_id).await? {
if deleted {
deleted_sizes.push(size)
deleted_sizes.push(size);
} else {
sizes.push(size)
sizes.push(size);
}
}
Ok(CollectionMetadata {
@@ -680,8 +673,8 @@ impl CalendarStore for SqliteCalendarStore {
Self::_put_object(
&mut *tx,
principal.to_owned(),
cal_id.to_owned(),
principal.clone(),
cal_id.clone(),
object,
overwrite,
)
@@ -706,7 +699,7 @@ impl CalendarStore for SqliteCalendarStore {
.push_topic,
}) {
error!("Push notification about deleted calendar failed: {err}");
};
}
Ok(())
}
@@ -731,7 +724,7 @@ impl CalendarStore for SqliteCalendarStore {
topic: self.get_calendar(principal, cal_id, true).await?.push_topic,
}) {
error!("Push notification about deleted calendar failed: {err}");
};
}
Ok(())
}
@@ -756,7 +749,7 @@ impl CalendarStore for SqliteCalendarStore {
topic: self.get_calendar(principal, cal_id, true).await?.push_topic,
}) {
error!("Push notification about deleted calendar failed: {err}");
};
}
Ok(())
}

View File

@@ -15,16 +15,16 @@ pub enum Error {
impl From<sqlx::Error> for Error {
fn from(value: sqlx::Error) -> Self {
match value {
sqlx::Error::RowNotFound => Error::StoreError(rustical_store::Error::NotFound),
sqlx::Error::RowNotFound => Self::StoreError(rustical_store::Error::NotFound),
sqlx::Error::Database(err) => {
if err.is_unique_violation() {
warn!("{err:?}");
Error::StoreError(rustical_store::Error::AlreadyExists)
Self::StoreError(rustical_store::Error::AlreadyExists)
} else {
Error::SqlxError(sqlx::Error::Database(err))
Self::SqlxError(sqlx::Error::Database(err))
}
}
err => Error::SqlxError(err),
err => Self::SqlxError(err),
}
}
}

View File

@@ -26,7 +26,7 @@ pub struct SqliteStore {
}
impl SqliteStore {
pub fn new(db: SqlitePool) -> Self {
#[must_use] pub const fn new(db: SqlitePool) -> Self {
Self { db }
}
}

View File

@@ -25,7 +25,7 @@ impl TryFrom<PrincipalRow> for Principal {
type Error = Error;
fn try_from(value: PrincipalRow) -> Result<Self, Self::Error> {
Ok(Principal {
Ok(Self {
id: value.id,
displayname: value.displayname,
password: value.password_hash.map(Secret::from),