Update shippai

This commit is contained in:
Markus Unterwaditzer 2018-04-24 20:58:35 +02:00
parent a61d51bc8f
commit 12bf226a41
8 changed files with 93 additions and 81 deletions

26
rust/Cargo.lock generated
View file

@ -211,21 +211,21 @@ dependencies = [
[[package]]
name = "shippai"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"shippai_derive 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"shippai_derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "shippai_derive"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -265,6 +265,17 @@ dependencies = [
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synstructure"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempdir"
version = "0.3.7"
@ -307,7 +318,7 @@ dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"shippai 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"shippai 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"vobject 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -373,12 +384,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
"checksum sha2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7daca11f2fdb8559c4f6c588386bed5e2ad4b6605c1442935a7f08144a918688"
"checksum shippai 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c6f9aeb41e06c9d8079d36b997575dc0290b11066c27684c4fb868e429e01b90"
"checksum shippai_derive 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c7a8bd6070ae7fc692908ec3853348566e5c0576c6b9d1a683813430a19b4961"
"checksum shippai 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6bb8291e9995ea961d67fdedad78ca67a6ea2b14a69bdfddb012151e1c8b5ede"
"checksum shippai_derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7d00a1043d0e6407aa7312b3eb8c7dc7f63993e5060306d4a2cac0bf8b9d85e7"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "91b52877572087400e83d24b9178488541e3d535259e04ff17a63df1e5ceff59"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum synstructure 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "98cad891cd238c98e1f0aec9f7c0f620aa696e4e5f7daba56ac67b5e86a6b049"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"

View file

@ -11,7 +11,7 @@ crate-type = ["cdylib"]
vobject = "0.4.2"
sha2 = "0.7.0"
failure = "0.1"
shippai = "0.2"
shippai = "0.2.3"
atomicwrites = "0.2.0"
uuid = { version = "0.6", features = ["v4"] }
libc = "0.2"

View file

@ -5,49 +5,45 @@ pub type Fallible<T> = Result<T, failure::Error>;
shippai_export!();
#[derive(Debug, Fail, Shippai)]
#[fail(display = "The item cannot be parsed")]
pub struct ItemUnparseable;
pub enum Error {
#[fail(display = "The item cannot be parsed")]
ItemUnparseable,
#[derive(Debug, Fail, Shippai)]
#[fail(display = "Unexpected version {}, expected {}", found, expected)]
pub struct UnexpectedVobjectVersion {
pub found: String,
pub expected: String,
}
#[fail(display = "Unexpected version {}, expected {}", found, expected)]
UnexpectedVobjectVersion {
found: String,
expected: String,
},
#[derive(Debug, Fail, Shippai)]
#[fail(display = "Unexpected component {}, expected {}", found, expected)]
pub struct UnexpectedVobject {
pub found: String,
pub expected: String,
}
#[fail(display = "Unexpected component {}, expected {}", found, expected)]
UnexpectedVobject {
found: String,
expected: String,
},
#[derive(Debug, Fail, Shippai)]
#[fail(display = "Item '{}' not found", href)]
pub struct ItemNotFound {
pub href: String,
}
#[fail(display = "Item '{}' not found", href)]
ItemNotFound {
href: String,
},
#[derive(Debug, Fail, Shippai)]
#[fail(display = "The href '{}' is already taken", href)]
pub struct ItemAlreadyExisting {
pub href: String,
}
#[fail(display = "The href '{}' is already taken", href)]
ItemAlreadyExisting {
href: String,
},
#[derive(Debug, Fail, Shippai)]
#[fail(display = "A wrong etag for '{}' was provided. Another client's requests might \
conflict with vdirsyncer.",
href)]
pub struct WrongEtag {
pub href: String,
}
#[fail(display = "A wrong etag for '{}' was provided. Another client's requests might \
conflict with vdirsyncer.",
href)]
WrongEtag {
href: String,
},
#[derive(Debug, Fail, Shippai)]
#[fail(display = "The mtime for '{}' has unexpectedly changed. Please close other programs\
accessing this file.",
filepath)]
pub struct MtimeMismatch {
pub filepath: String,
#[fail(display = "The mtime for '{}' has unexpectedly changed. Please close other programs\
accessing this file.",
filepath)]
MtimeMismatch {
filepath: String,
},
}
pub unsafe fn export_result<V>(

View file

@ -47,7 +47,7 @@ impl Item {
change_uid(&mut new_component, uid);
Ok(Item::from_raw(vobject::write_component(&new_component)))
} else {
Err(ItemUnparseable.into())
Err(Error::ItemUnparseable.into())
}
}
@ -63,7 +63,7 @@ impl Item {
pub fn get_component(&self) -> Fallible<&vobject::Component> {
match *self {
Item::Parsed(ref component) => Ok(component),
_ => Err(ItemUnparseable.into()),
_ => Err(Error::ItemUnparseable.into()),
}
}
@ -71,7 +71,7 @@ impl Item {
pub fn into_component(self) -> Fallible<vobject::Component> {
match self {
Item::Parsed(component) => Ok(component),
_ => Err(ItemUnparseable.into()),
_ => Err(Error::ItemUnparseable.into()),
}
}
@ -81,7 +81,7 @@ impl Item {
if let Item::Parsed(ref component) = *self {
Ok(hash_component(component))
} else {
Err(ItemUnparseable.into())
Err(Error::ItemUnparseable.into())
}
}

View file

@ -66,10 +66,10 @@ impl FilesystemStorage {
#[inline]
fn handle_io_error(href: &str, e: io::Error) -> failure::Error {
match e.kind() {
io::ErrorKind::NotFound => ItemNotFound {
io::ErrorKind::NotFound => Error::ItemNotFound {
href: href.to_owned(),
}.into(),
io::ErrorKind::AlreadyExists => ItemAlreadyExisting {
io::ErrorKind::AlreadyExists => Error::ItemAlreadyExisting {
href: href.to_owned(),
}.into(),
_ => e.into(),
@ -190,7 +190,7 @@ impl Storage for FilesystemStorage {
};
let actual_etag = etag_from_file(&metadata);
if actual_etag != etag {
Err(WrongEtag {
Err(Error::WrongEtag {
href: href.to_owned(),
})?;
}
@ -210,7 +210,7 @@ impl Storage for FilesystemStorage {
};
let actual_etag = etag_from_file(&metadata);
if actual_etag != etag {
Err(WrongEtag {
Err(Error::WrongEtag {
href: href.to_owned(),
})?;
}

View file

@ -88,7 +88,7 @@ impl Storage for SinglefileStorage {
fn get(&mut self, href: &str) -> Fallible<(Item, String)> {
match self.get_items()?.get(href) {
Some(&(ref href, ref etag)) => Ok((href.clone(), etag.clone())),
None => Err(ItemNotFound {
None => Err(Error::ItemNotFound {
href: href.to_owned(),
})?,
}
@ -98,7 +98,7 @@ impl Storage for SinglefileStorage {
let hash = item.get_hash()?;
let href = item.get_ident()?;
match self.get_items()?.entry(href.clone()) {
Occupied(_) => Err(ItemAlreadyExisting { href: href.clone() })?,
Occupied(_) => Err(Error::ItemAlreadyExisting { href: href.clone() })?,
Vacant(vc) => vc.insert((item, hash.clone())),
};
self.write_back()?;
@ -113,12 +113,12 @@ impl Storage for SinglefileStorage {
oc.insert((item, hash.clone()));
hash
} else {
Err(WrongEtag {
Err(Error::WrongEtag {
href: href.to_owned(),
})?
}
}
Vacant(_) => Err(ItemNotFound {
Vacant(_) => Err(Error::ItemNotFound {
href: href.to_owned(),
})?,
};
@ -132,12 +132,12 @@ impl Storage for SinglefileStorage {
if oc.get().1 == etag {
oc.remove();
} else {
Err(WrongEtag {
Err(Error::WrongEtag {
href: href.to_owned(),
})?
}
}
Vacant(_) => Err(ItemNotFound {
Vacant(_) => Err(Error::ItemNotFound {
href: href.to_owned(),
})?,
}
@ -163,7 +163,7 @@ impl Storage for SinglefileStorage {
f.write_all(content.as_bytes())?;
let real_mtime = metadata(path)?.modified()?;
if mtime != real_mtime {
Err(MtimeMismatch {
Err(Error::MtimeMismatch {
filepath: path.to_string_lossy().into_owned(),
})?;
}
@ -192,14 +192,14 @@ fn split_collection(mut input: &str) -> Fallible<Vec<vobject::Component>> {
"VCARD" => rv.push(component),
"VADDRESSBOOK" => for vcard in component.subcomponents {
if vcard.name != "VCARD" {
Err(UnexpectedVobject {
Err(Error::UnexpectedVobject {
found: vcard.name.clone(),
expected: "VCARD".to_owned(),
})?;
}
rv.push(vcard);
},
_ => Err(UnexpectedVobject {
_ => Err(Error::UnexpectedVobject {
found: component.name.clone(),
expected: "VCALENDAR | VCARD | VADDRESSBOOK".to_owned(),
})?,
@ -227,7 +227,7 @@ fn split_vcalendar(mut vcalendar: vobject::Component) -> Fallible<Vec<vobject::C
timezones.insert(tzid, component);
}
"VTODO" | "VEVENT" | "VJOURNAL" => subcomponents.push(component),
_ => Err(UnexpectedVobject {
_ => Err(Error::UnexpectedVobject {
found: component.name.clone(),
expected: "VTIMEZONE | VTODO | VEVENT | VJOURNAL".to_owned(),
})?,
@ -290,7 +290,7 @@ fn join_collection<I: Iterator<Item = Item>>(item_iter: I) -> Fallible<String> {
let wrapper_name = match item_name.as_ref() {
"VCARD" => "VADDRESSBOOK",
"VCALENDAR" => "VCALENDAR",
_ => Err(UnexpectedVobject {
_ => Err(Error::UnexpectedVobject {
found: item_name.clone(),
expected: "VCARD | VCALENDAR".to_owned(),
})?,
@ -302,7 +302,7 @@ fn join_collection<I: Iterator<Item = Item>>(item_iter: I) -> Fallible<String> {
for item in items {
let mut c = item.into_component()?;
if c.name != item_name {
return Err(UnexpectedVobject {
return Err(Error::UnexpectedVobject {
found: c.name,
expected: item_name.clone(),
}.into());
@ -312,7 +312,7 @@ fn join_collection<I: Iterator<Item = Item>>(item_iter: I) -> Fallible<String> {
wrapper.subcomponents.extend(c.subcomponents.drain(..));
match (version.as_ref(), c.get_only("VERSION")) {
(Some(x), Some(y)) if x.raw_value != y.raw_value => {
return Err(UnexpectedVobjectVersion {
return Err(Error::UnexpectedVobjectVersion {
expected: x.raw_value.clone(),
found: y.raw_value.clone(),
}.into());

View file

@ -20,6 +20,20 @@ typedef struct {
const char *etag;
} VdirsyncerStorageUploadResult;
extern const uint8_t SHIPPAI_VARIANT_Error_ItemAlreadyExisting;
extern const uint8_t SHIPPAI_VARIANT_Error_ItemNotFound;
extern const uint8_t SHIPPAI_VARIANT_Error_ItemUnparseable;
extern const uint8_t SHIPPAI_VARIANT_Error_MtimeMismatch;
extern const uint8_t SHIPPAI_VARIANT_Error_UnexpectedVobject;
extern const uint8_t SHIPPAI_VARIANT_Error_UnexpectedVobjectVersion;
extern const uint8_t SHIPPAI_VARIANT_Error_WrongEtag;
void shippai_free_failure(ShippaiError *t);
void shippai_free_str(char *t);
@ -28,19 +42,9 @@ const char *shippai_get_debug(ShippaiError *t);
const char *shippai_get_display(ShippaiError *t);
bool shippai_is_error_ItemAlreadyExisting(ShippaiError *t);
uint8_t shippai_get_variant_Error(ShippaiError *t);
bool shippai_is_error_ItemNotFound(ShippaiError *t);
bool shippai_is_error_ItemUnparseable(ShippaiError *t);
bool shippai_is_error_MtimeMismatch(ShippaiError *t);
bool shippai_is_error_UnexpectedVobject(ShippaiError *t);
bool shippai_is_error_UnexpectedVobjectVersion(ShippaiError *t);
bool shippai_is_error_WrongEtag(ShippaiError *t);
bool shippai_is_error_Error(ShippaiError *t);
bool vdirsyncer_advance_storage_listing(VdirsyncerStorageListing *listing);

View file

@ -25,9 +25,9 @@ def get_error_pointer():
def check_error(e):
try:
errors.check_exception(e[0])
except errors.ItemNotFound as e:
except errors.Error.ItemNotFound as e:
raise exceptions.NotFoundError(e)
except errors.ItemAlreadyExisting as e:
except errors.Error.ItemAlreadyExisting as e:
raise exceptions.AlreadyExistingError(e)
except errors.WrongEtag as e:
except errors.Error.WrongEtag as e:
raise exceptions.WrongEtagError(e)