From 2cef21906b9bd3c2e92925d7c93d3c8053b52ade Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 29 Jul 2025 16:27:18 +0100 Subject: =?UTF-8?q?=F0=9F=94=A7refactor:=20move=20the=20rest=20of=20the=20?= =?UTF-8?q?indexing=20relating=20logic=20to=20Index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/index.rs b/src/index.rs index e543b1d..069068a 100644 --- a/src/index.rs +++ b/src/index.rs @@ -9,6 +9,16 @@ impl Index { pub fn new() -> Self { Self {} } + pub async fn get(&self, appname: &str) -> Result> { + 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 async fn add( &self, appimage: &AppImage, @@ -21,6 +31,12 @@ impl Index { let json = serde_json::to_string_pretty(appimage)?; fs::write(index_file, json).await?; + Ok(()) + } + pub async fn remove(&self, appname: &str) -> Result<(), Box> { + let index_file_path = index_dir().join(format!("{appname}.json")); + fs::remove_file(index_file_path).await?; + Ok(()) } } -- cgit v1.2.3