summaryrefslogtreecommitdiff
path: root/src/index.rs
diff options
context:
space:
mode:
authorNaz <ndpm13@ch-naseem.com>2025-08-03 10:08:45 +0100
committerNaz <ndpm13@ch-naseem.com>2025-08-03 10:08:45 +0100
commit57ffe6ff51a8f3ccc41607f18dcf3c9039e85d94 (patch)
tree7ab8e10bf2fce88ca3cdfb2a6b13c0717c638407 /src/index.rs
parent6b3f5d37fbce2e880a454e66d8fbd78269f1c867 (diff)
parentdc0ee6ce99a0480b7a6c228492936b16ceaf60cd (diff)
Merge pull request 'Add comprehensive error types' (#12) from feat/issue-5 into main
Reviewed-on: https://git.ch-naseem.com/ndpm13/zap-rs/pulls/12
Diffstat (limited to 'src/index.rs')
-rw-r--r--src/index.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/index.rs b/src/index.rs
index 069068a..8f2521a 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -1,6 +1,6 @@
use tokio::fs;
-use crate::{AppImage, index_dir};
+use crate::{AppImage, Result, index_dir};
#[derive(Debug, Default)]
pub struct Index {}
@@ -9,32 +9,28 @@ impl Index {
pub fn new() -> Self {
Self {}
}
- pub async fn get(&self, appname: &str) -> Result<AppImage, Box<dyn std::error::Error>> {
- let index_file_path = index_dir().join(format!("{appname}.json"));
+ pub async fn get(&self, appname: &str) -> Result<AppImage> {
+ let index_file_path = index_dir()?.join(format!("{appname}.json"));
let index_file_content = fs::read_to_string(&index_file_path).await?;
let appimage: AppImage = serde_json::from_str(&index_file_content)?;
Ok(appimage)
}
- pub fn exists(&self, executable: &str) -> bool {
- index_dir().join(format!("{}.json", &executable)).exists()
+ pub fn exists(&self, executable: &str) -> Result<bool> {
+ Ok(index_dir()?.join(format!("{}.json", &executable)).exists())
}
- pub async fn add(
- &self,
- appimage: &AppImage,
- appname: &str,
- ) -> Result<(), Box<dyn std::error::Error>> {
- fs::create_dir_all(&index_dir()).await?;
+ pub async fn add(&self, appimage: &AppImage, appname: &str) -> Result<()> {
+ fs::create_dir_all(&index_dir()?).await?;
- let index_file = &index_dir().join(format!("{appname}.json"));
+ let index_file = &index_dir()?.join(format!("{appname}.json"));
let json = serde_json::to_string_pretty(appimage)?;
fs::write(index_file, json).await?;
Ok(())
}
- pub async fn remove(&self, appname: &str) -> Result<(), Box<dyn std::error::Error>> {
- let index_file_path = index_dir().join(format!("{appname}.json"));
+ pub async fn remove(&self, appname: &str) -> Result<()> {
+ let index_file_path = index_dir()?.join(format!("{appname}.json"));
fs::remove_file(index_file_path).await?;
Ok(())