mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 11:42:25 +00:00
Remove RwLock around stores, locking shall be the responsibility of the store implementation
This commit is contained in:
@@ -10,19 +10,19 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
||||
async fn get_addressbooks(&self, principal: &str) -> Result<Vec<Addressbook>, Error>;
|
||||
|
||||
async fn update_addressbook(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
id: String,
|
||||
addressbook: Addressbook,
|
||||
) -> Result<(), Error>;
|
||||
async fn insert_addressbook(&mut self, addressbook: Addressbook) -> Result<(), Error>;
|
||||
async fn insert_addressbook(&self, addressbook: Addressbook) -> Result<(), Error>;
|
||||
async fn delete_addressbook(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
name: &str,
|
||||
use_trashbin: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn restore_addressbook(&mut self, principal: &str, name: &str) -> Result<(), Error>;
|
||||
async fn restore_addressbook(&self, principal: &str, name: &str) -> Result<(), Error>;
|
||||
|
||||
async fn sync_changes(
|
||||
&self,
|
||||
@@ -43,20 +43,21 @@ pub trait AddressbookStore: Send + Sync + 'static {
|
||||
object_id: &str,
|
||||
) -> Result<AddressObject, Error>;
|
||||
async fn put_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
addressbook_id: String,
|
||||
object: AddressObject,
|
||||
overwrite: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn delete_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
object_id: &str,
|
||||
use_trashbin: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn restore_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
object_id: &str,
|
||||
|
||||
@@ -9,19 +9,19 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
||||
|
||||
async fn update_calendar(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
id: String,
|
||||
calendar: Calendar,
|
||||
) -> Result<(), Error>;
|
||||
async fn insert_calendar(&mut self, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn delete_calendar(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
name: &str,
|
||||
use_trashbin: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn restore_calendar(&mut self, principal: &str, name: &str) -> Result<(), Error>;
|
||||
async fn restore_calendar(&self, principal: &str, name: &str) -> Result<(), Error>;
|
||||
|
||||
async fn sync_changes(
|
||||
&self,
|
||||
@@ -42,20 +42,21 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
object_id: &str,
|
||||
) -> Result<CalendarObject, Error>;
|
||||
async fn put_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
cal_id: String,
|
||||
object: CalendarObject,
|
||||
overwrite: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn delete_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
use_trashbin: bool,
|
||||
) -> Result<(), Error>;
|
||||
async fn restore_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
|
||||
@@ -3,8 +3,11 @@ pub enum Error {
|
||||
#[error("Not found")]
|
||||
NotFound,
|
||||
|
||||
#[error("Invalid ics input: {0}")]
|
||||
InvalidIcs(String),
|
||||
#[error("Resource already exists and overwrite=false")]
|
||||
AlreadyExists,
|
||||
|
||||
#[error("Invalid ics/vcf input: {0}")]
|
||||
InvalidData(String),
|
||||
|
||||
#[error(transparent)]
|
||||
SqlxError(sqlx::Error),
|
||||
|
||||
@@ -68,7 +68,7 @@ impl CalendarObject {
|
||||
let mut parser = ical::IcalParser::new(BufReader::new(ics.as_bytes()));
|
||||
let cal = parser.next().ok_or(Error::NotFound)??;
|
||||
if parser.next().is_some() {
|
||||
return Err(Error::InvalidIcs(
|
||||
return Err(Error::InvalidData(
|
||||
"multiple calendars, only one allowed".to_owned(),
|
||||
));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ impl CalendarObject {
|
||||
!= 1
|
||||
{
|
||||
// https://datatracker.ietf.org/doc/html/rfc4791#section-4.1
|
||||
return Err(Error::InvalidIcs(
|
||||
return Err(Error::InvalidData(
|
||||
"iCalendar object is only allowed to have exactly one component".to_owned(),
|
||||
));
|
||||
}
|
||||
@@ -114,7 +114,7 @@ impl CalendarObject {
|
||||
});
|
||||
}
|
||||
|
||||
Err(Error::InvalidIcs(
|
||||
Err(Error::InvalidData(
|
||||
"iCalendar component type not supported :(".to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn update_addressbook(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
id: String,
|
||||
addressbook: Addressbook,
|
||||
@@ -123,7 +123,7 @@ impl AddressbookStore for SqliteStore {
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn insert_addressbook(&mut self, addressbook: Addressbook) -> Result<(), Error> {
|
||||
async fn insert_addressbook(&self, addressbook: Addressbook) -> Result<(), Error> {
|
||||
sqlx::query!(
|
||||
r#"INSERT INTO addressbooks (principal, id, displayname, description)
|
||||
VALUES (?, ?, ?, ?)"#,
|
||||
@@ -139,7 +139,7 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn delete_addressbook(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
use_trashbin: bool,
|
||||
@@ -168,7 +168,7 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn restore_addressbook(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
) -> Result<(), Error> {
|
||||
@@ -264,10 +264,12 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn put_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
addressbook_id: String,
|
||||
object: AddressObject,
|
||||
// TODO: implement
|
||||
overwrite: bool,
|
||||
) -> Result<(), Error> {
|
||||
let mut tx = self.db.begin().await?;
|
||||
|
||||
@@ -298,7 +300,7 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn delete_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
object_id: &str,
|
||||
@@ -341,7 +343,7 @@ impl AddressbookStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn restore_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
object_id: &str,
|
||||
|
||||
@@ -98,7 +98,7 @@ impl CalendarStore for SqliteStore {
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn insert_calendar(&mut self, calendar: Calendar) -> Result<(), Error> {
|
||||
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> {
|
||||
sqlx::query!(
|
||||
r#"INSERT INTO calendars (principal, id, displayname, description, "order", color, timezone)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)"#,
|
||||
@@ -117,7 +117,7 @@ impl CalendarStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn update_calendar(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
id: String,
|
||||
calendar: Calendar,
|
||||
@@ -144,7 +144,7 @@ impl CalendarStore for SqliteStore {
|
||||
// Does not actually delete the calendar but just disables it
|
||||
#[instrument]
|
||||
async fn delete_calendar(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
id: &str,
|
||||
use_trashbin: bool,
|
||||
@@ -172,7 +172,7 @@ impl CalendarStore for SqliteStore {
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn restore_calendar(&mut self, principal: &str, id: &str) -> Result<(), Error> {
|
||||
async fn restore_calendar(&self, principal: &str, id: &str) -> Result<(), Error> {
|
||||
sqlx::query!(
|
||||
r"UPDATE calendars SET deleted_at = NULL WHERE (principal, id) = (?, ?)",
|
||||
principal,
|
||||
@@ -223,10 +223,12 @@ impl CalendarStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn put_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: String,
|
||||
cal_id: String,
|
||||
object: CalendarObject,
|
||||
// TODO: implement
|
||||
overwrite: bool,
|
||||
) -> Result<(), Error> {
|
||||
let mut tx = self.db.begin().await?;
|
||||
|
||||
@@ -257,7 +259,7 @@ impl CalendarStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn delete_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
id: &str,
|
||||
@@ -300,7 +302,7 @@ impl CalendarStore for SqliteStore {
|
||||
|
||||
#[instrument]
|
||||
async fn restore_object(
|
||||
&mut self,
|
||||
&self,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
|
||||
@@ -92,7 +92,7 @@ impl CalDateTime {
|
||||
if let Ok(tz) = olson_name.parse::<Tz>() {
|
||||
Some(tz)
|
||||
} else {
|
||||
return Err(Error::InvalidIcs(format!(
|
||||
return Err(Error::InvalidData(format!(
|
||||
"Timezone has X-LIC-LOCATION property to specify a timezone from the Olson database, however it's value {olson_name} is invalid"
|
||||
)));
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl CalDateTime {
|
||||
}
|
||||
} else {
|
||||
// TZID refers to timezone that does not exist
|
||||
return Err(Error::InvalidIcs(format!(
|
||||
return Err(Error::InvalidData(format!(
|
||||
"No timezone specified with TZID={tzid}"
|
||||
)));
|
||||
}
|
||||
@@ -167,7 +167,7 @@ impl From<CalDateTime> for DateTime<Utc> {
|
||||
pub fn parse_duration(string: &str) -> Result<Duration, Error> {
|
||||
let captures = RE_DURATION
|
||||
.captures(string)
|
||||
.ok_or(Error::InvalidIcs("Invalid duration format".to_owned()))?;
|
||||
.ok_or(Error::InvalidData("Invalid duration format".to_owned()))?;
|
||||
|
||||
let mut duration = Duration::zero();
|
||||
if let Some(weeks) = captures.name("W") {
|
||||
|
||||
Reference in New Issue
Block a user