Simplify default Result generics.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-07-08 12:08:13 +00:00
parent 8244d78cb2
commit ae707ab465
42 changed files with 95 additions and 115 deletions

View File

@@ -165,7 +165,7 @@ impl Data {
}
#[inline]
pub(super) fn remove_url_preview(&self, url: &str) -> Result<()> {
pub(super) fn remove_url_preview(&self, url: &str) -> Result {
self.url_previews.remove(url.as_bytes());
Ok(())
}
@@ -175,7 +175,7 @@ impl Data {
url: &str,
data: &UrlPreviewData,
timestamp: Duration,
) -> Result<()> {
) -> Result {
let mut value = Vec::<u8>::new();
value.extend_from_slice(&timestamp.as_secs().to_be_bytes());
value.push(0xFF);

View File

@@ -18,7 +18,7 @@ use crate::Services;
/// Migrates a media directory from legacy base64 file names to sha2 file names.
/// All errors are fatal. Upon success the database is keyed to not perform this
/// again.
pub(crate) async fn migrate_sha256_media(services: &Services) -> Result<()> {
pub(crate) async fn migrate_sha256_media(services: &Services) -> Result {
let db = &services.db;
let config = &services.server.config;
@@ -57,7 +57,7 @@ pub(crate) async fn migrate_sha256_media(services: &Services) -> Result<()> {
/// - Going back and forth to non-sha256 legacy binaries (e.g. upstream).
/// - Deletion of artifacts in the media directory which will then fall out of
/// sync with the database.
pub(crate) async fn checkup_sha256_media(services: &Services) -> Result<()> {
pub(crate) async fn checkup_sha256_media(services: &Services) -> Result {
use crate::media::encode_key;
debug!("Checking integrity of media directory");
@@ -101,7 +101,7 @@ async fn handle_media_check(
key: &[u8],
new_path: &OsStr,
old_path: &OsStr,
) -> Result<()> {
) -> Result {
use crate::media::encode_key;
let (mediaid_file, mediaid_user) = dbs;

View File

@@ -68,7 +68,7 @@ impl crate::Service for Service {
}))
}
async fn worker(self: Arc<Self>) -> Result<()> {
async fn worker(self: Arc<Self>) -> Result {
self.create_media_dir().await?;
Ok(())
@@ -86,7 +86,7 @@ impl Service {
content_disposition: Option<&ContentDisposition>,
content_type: Option<&str>,
file: &[u8],
) -> Result<()> {
) -> Result {
// Width, Height = 0 if it's not a thumbnail
let key = self.db.create_file_metadata(
mxc,
@@ -104,7 +104,7 @@ impl Service {
}
/// Deletes a file in the database and from the media directory via an MXC
pub async fn delete(&self, mxc: &Mxc<'_>) -> Result<()> {
pub async fn delete(&self, mxc: &Mxc<'_>) -> Result {
match self.db.search_mxc_metadata_prefix(mxc).await {
| Ok(keys) => {
for key in keys {
@@ -341,12 +341,12 @@ impl Service {
Ok(deletion_count)
}
pub async fn create_media_dir(&self) -> Result<()> {
pub async fn create_media_dir(&self) -> Result {
let dir = self.get_media_dir();
Ok(fs::create_dir_all(dir).await?)
}
async fn remove_media_file(&self, key: &[u8]) -> Result<()> {
async fn remove_media_file(&self, key: &[u8]) -> Result {
let path = self.get_media_file(key);
let legacy = self.get_media_file_b64(key);
debug!(?key, ?path, ?legacy, "Removing media file");

View File

@@ -49,13 +49,13 @@ pub struct UrlPreviewData {
}
#[implement(Service)]
pub async fn remove_url_preview(&self, url: &str) -> Result<()> {
pub async fn remove_url_preview(&self, url: &str) -> Result {
// TODO: also remove the downloaded image
self.db.remove_url_preview(url)
}
#[implement(Service)]
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> {
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("valid system time");

View File

@@ -439,7 +439,7 @@ pub async fn fetch_remote_content_legacy(
}
#[implement(super::Service)]
fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result<()> {
fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result {
if self
.services
.server
@@ -463,7 +463,7 @@ fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result<()> {
}
#[implement(super::Service)]
fn check_legacy_freeze(&self) -> Result<()> {
fn check_legacy_freeze(&self) -> Result {
self.services
.server
.config

View File

@@ -44,7 +44,7 @@ async fn long_file_names_works() {
Ok(key)
}
fn delete_file_mxc(&self, _mxc: String) -> Result<()> { todo!() }
fn delete_file_mxc(&self, _mxc: String) -> Result { todo!() }
fn search_mxc_metadata_prefix(&self, _mxc: String) -> Result<Vec<Vec<u8>>> { todo!() }
@@ -59,14 +59,14 @@ async fn long_file_names_works() {
todo!()
}
fn remove_url_preview(&self, _url: &str) -> Result<()> { todo!() }
fn remove_url_preview(&self, _url: &str) -> Result { todo!() }
fn set_url_preview(
&self,
_url: &str,
_data: &UrlPreviewData,
_timestamp: std::time::Duration,
) -> Result<()> {
) -> Result {
todo!()
}

View File

@@ -35,7 +35,7 @@ impl super::Service {
content_type: Option<&str>,
dim: &Dim,
file: &[u8],
) -> Result<()> {
) -> Result {
let key =
self.db
.create_file_metadata(mxc, user, dim, content_disposition, content_type)?;