diff --git a/src/util.rs b/src/util.rs index d113fa5..e994e2e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -56,22 +56,20 @@ pub async fn generate_media_ids( }; // upload media to Mastodon - let mastodon_media = - match mastodon.media(Cow::from(local_tweet_media_path.to_owned())) { - Ok(l) => l, - Err(e) => { - remove_file(&local_tweet_media_path).await.unwrap(); - return Err(ScootalooError::new(&format!( - "Attachment {} cannot be uploaded to Mastodon Instance: {}", - &local_tweet_media_path, e - ))); - } - }; - + let mastodon_media = mastodon.media(Cow::from(local_tweet_media_path.to_owned())); // at this point, we can safely erase the original file - if let Err(e) = remove_file(&local_tweet_media_path).await { - ScootalooError::new(&format!("Attachment {} has been uploaded but I’m unable to remove the existing file: {}", &local_tweet_media_path, e)); - } + // it doesn’t matter if we can’t remove, cache_media fn is idempotent + remove_file(&local_tweet_media_path).await.ok(); + + let mastodon_media = match mastodon_media { + Ok(m) => m, + Err(e) => { + return Err(ScootalooError::new(&format!( + "Attachment {} cannot be uploaded to Mastodon Instance: {}", + &local_tweet_media_path, e + ))) + } + }; Ok((i, mastodon_media.id)) });