target detailed checks of @flub

This commit is contained in:
B. Petersen
2019-10-04 22:53:23 +02:00
parent 2317518e5e
commit 9cae075b6f
7 changed files with 29 additions and 42 deletions

View File

@@ -287,7 +287,7 @@ impl Chat {
if self.typ == Chattype::Group || self.typ == Chattype::VerifiedGroup {
if self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
self.param.remove(Param::Unpromoted);
self.update_param(context).unwrap_or_default();
self.update_param(context)?;
}
}
}
@@ -663,7 +663,7 @@ fn prepare_msg_common(context: &Context, chat_id: u32, msg: &mut Message) -> Res
msg.type_0
);
let mut path_filename = path_filename.unwrap_or_default().to_string();
let mut path_filename = path_filename.unwrap().to_string();
if msg.state == MessageState::OutPreparing && !dc_is_blobdir_path(context, &path_filename) {
bail!("Files must be created in the blob-directory.");
@@ -1367,7 +1367,7 @@ pub(crate) fn add_contact_to_chat_ex(
}
if from_handshake && chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
chat.param.remove(Param::Unpromoted);
chat.update_param(context).unwrap_or_default();
chat.update_param(context)?;
}
let self_addr = context
.get_config(Config::ConfiguredAddr)
@@ -1502,7 +1502,7 @@ pub fn remove_contact_from_chat(
if chat.is_promoted() {
msg.type_0 = Viewtype::Text;
if contact.id == DC_CONTACT_ID_SELF {
set_group_explicitly_left(context, chat.grpid).unwrap_or_default();
set_group_explicitly_left(context, chat.grpid)?;
msg.text = Some(context.stock_system_msg(
StockMessage::MsgGroupLeft,
"",
@@ -1711,7 +1711,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result<
let mut created_db_entries = Vec::new();
let mut curr_timestamp: i64;
unarchive(context, chat_id).unwrap_or_default();
unarchive(context, chat_id)?;
if let Ok(mut chat) = Chat::load_from_db(context, chat_id) {
curr_timestamp = dc_create_smeared_timestamps(context, msg_ids.len());
let idsstr = msg_ids
@@ -1721,18 +1721,15 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result<
(if i == 0 { acc } else { acc + "," }) + &n.to_string()
});
let ids = context
.sql
.query_map(
format!(
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
idsstr
),
params![],
|row| row.get::<_, i32>(0),
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
)
.unwrap_or_default(); // TODO: better error handling
let ids = context.sql.query_map(
format!(
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
idsstr
),
params![],
|row| row.get::<_, i32>(0),
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
)?;
for id in ids {
let src_msg_id = id;
@@ -1740,7 +1737,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[u32], chat_id: u32) -> Result<
if msg.is_err() {
break;
}
let mut msg = msg.unwrap_or_default();
let mut msg = msg.unwrap();
let original_param = msg.param.clone();
if msg.from_id != DC_CONTACT_ID_SELF {
msg.param.set_int(Param::Forwarded, 1);
@@ -1870,7 +1867,7 @@ mod tests {
fn test_get_draft_no_draft() {
let t = dummy_context();
let chat_id = create_by_contact_id(&t.ctx, DC_CONTACT_ID_SELF).unwrap();
let draft = get_draft(&t.ctx, chat_id).unwrap_or_default();
let draft = get_draft(&t.ctx, chat_id).unwrap();
assert!(draft.is_none());
}

View File

@@ -290,12 +290,7 @@ impl Chatlist {
{
ret.text2 = Some(context.stock_str(StockMessage::NoMessages).to_string());
} else {
ret.fill(
&mut lastmsg.unwrap_or_default(),
chat,
lastcontact.as_ref(),
context,
);
ret.fill(&mut lastmsg.unwrap(), chat, lastcontact.as_ref(), context);
}
ret

View File

@@ -79,12 +79,7 @@ impl Context {
let value = match key {
Config::Selfavatar => {
let rel_path = self.sql.get_raw_config(self, key);
rel_path.map(|p| {
dc_get_abs_path(self, &p)
.to_str()
.unwrap_or_default()
.to_string()
})
rel_path.map(|p| dc_get_abs_path(self, &p).to_string_lossy().into_owned())
}
Config::SysVersion => Some((&*DC_VERSION_STR).clone()),
Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)),
@@ -118,7 +113,7 @@ impl Context {
pub fn set_config(&self, key: Config, value: Option<&str>) -> Result<(), Error> {
match key {
Config::Selfavatar if value.is_some() => {
let rel_path = std::fs::canonicalize(value.unwrap_or_default())?;
let rel_path = std::fs::canonicalize(value.unwrap())?;
self.sql
.set_raw_config(self, key, Some(&rel_path.to_string_lossy()))
}

View File

@@ -40,7 +40,7 @@ pub unsafe fn moz_autoconfigure(
free(xml_raw as *mut libc::c_void);
return None;
}
let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap_or_default());
let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap());
let in_emaildomain = &in_emaildomain[1..];
let mut reader = quick_xml::Reader::from_str(as_str(xml_raw));

View File

@@ -1030,7 +1030,7 @@ fn split_address_book(book: &str) -> Vec<(&str, &str)> {
.chunks(2)
.into_iter()
.filter_map(|mut chunk| {
let name = chunk.next().unwrap_or_default();
let name = chunk.next().unwrap();
let addr = match chunk.next() {
Some(a) => a,
None => return None,

View File

@@ -581,7 +581,7 @@ unsafe fn add_parts(
);
// unarchive chat
chat::unarchive(context, *chat_id).unwrap_or_default();
chat::unarchive(context, *chat_id)?;
// if the mime-headers should be saved, find out its size
// (the mime-header ends with an empty line)

View File

@@ -330,13 +330,13 @@ fn encode_66bits_as_base64(v1: u32, v2: u32, fill: u32) -> String {
let mut wrapped_writer = Vec::new();
{
let mut enc = base64::write::EncoderWriter::new(&mut wrapped_writer, base64::URL_SAFE);
enc.write_u32::<BigEndian>(v1).unwrap_or_default();
enc.write_u32::<BigEndian>(v2).unwrap_or_default();
enc.write_u8(((fill & 0x3) as u8) << 6).unwrap_or_default();
enc.finish().unwrap_or_default();
enc.write_u32::<BigEndian>(v1).unwrap();
enc.write_u32::<BigEndian>(v2).unwrap();
enc.write_u8(((fill & 0x3) as u8) << 6).unwrap();
enc.finish().unwrap();
}
assert_eq!(wrapped_writer.pop(), Some(b'A')); // Remove last "A"
String::from_utf8(wrapped_writer).unwrap_or_default()
String::from_utf8(wrapped_writer).unwrap()
}
pub(crate) fn dc_create_incoming_rfc724_mid(
@@ -386,7 +386,7 @@ pub(crate) fn dc_extract_grpid_from_rfc724_mid(mid: &str) -> Option<&str> {
if let Some(grpid_len) = mid_without_offset.find('.') {
/* strict length comparison, the 'Gr.' magic is weak enough */
if grpid_len == 11 || grpid_len == 16 {
return Some(mid_without_offset.get(0..grpid_len).unwrap_or_default());
return Some(mid_without_offset.get(0..grpid_len).unwrap());
}
}
}
@@ -892,7 +892,7 @@ fn as_path_unicode<'a>(s: *const libc::c_char) -> &'a std::path::Path {
pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.unwrap()
.as_secs() as i64
}