summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/update.rs18
-rw-r--r--src/files.rs10
2 files changed, 16 insertions, 12 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs
index be15cfa..482e588 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -1,6 +1,6 @@
1use std::{io::{Error, ErrorKind}, fs::{rename, remove_file}}; 1use std::{io::{Error, ErrorKind}, fs::{rename, remove_file}};
2 2
3use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, userlist_add_disabled_versions, mods_change_versions}, List, input::Input, files::get_file_path, download_versions}; 3use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, userlist_add_disabled_versions, mods_change_versions}, List, input::Input, files::{get_file_path, delete_version}, download_versions};
4 4
5pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 5pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
6 6
@@ -73,7 +73,12 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error:
73 73
74 //Disable old versions 74 //Disable old versions
75 for ver in current_versions { 75 for ver in current_versions {
76 if input.delete_old { delete_old(current_list.clone(), ver.0, ver.1)? } else { disable_old(config.clone(), current_list.clone(), ver.0, ver.1)? }; 76 if input.delete_old {
77 println!("Deleting version {} for mod {}", ver.0, ver.1);
78 delete_version(current_list.clone(), ver.0)?;
79 } else {
80 disable_old(config.clone(), current_list.clone(), ver.0, ver.1)?
81 };
77 } 82 }
78 } 83 }
79 84
@@ -126,15 +131,6 @@ fn disable_old(config: Cfg, current_list: List, versionid: String, mod_id: Strin
126 Ok(()) 131 Ok(())
127} 132}
128 133
129fn delete_old(current_list: List, versionid: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> {
130 println!("Deleting version {} for mod {}", versionid, mod_id);
131 let file = get_file_path(current_list, String::from(&versionid))?;
132
133 remove_file(file)?;
134
135 Ok(())
136}
137
138#[tokio::test] 134#[tokio::test]
139async fn download_updates_test() { 135async fn download_updates_test() {
140 136
diff --git a/src/files.rs b/src/files.rs
index 1c0b13c..2c5994d 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -1,4 +1,4 @@
1use std::{fs::{File, read_dir}, io::Write, collections::HashMap}; 1use std::{fs::{File, read_dir, remove_file}, io::Write, collections::HashMap};
2use futures_util::StreamExt; 2use futures_util::StreamExt;
3use reqwest::Client; 3use reqwest::Client;
4 4
@@ -24,6 +24,14 @@ pub async fn download_file(url: String, path: String, name: String) -> Result<()
24 Ok(()) 24 Ok(())
25} 25}
26 26
27pub fn delete_version(list: List, version: String) -> Result<(), Box<dyn std::error::Error>> {
28 let file = get_file_path(list, version)?;
29
30 remove_file(file)?;
31
32 Ok(())
33}
34
27pub fn get_file_path(list: List, versionid: String) -> Result<String, Box<dyn std::error::Error>> { 35pub fn get_file_path(list: List, versionid: String) -> Result<String, Box<dyn std::error::Error>> {
28 let mut names: HashMap<String, String> = HashMap::new(); 36 let mut names: HashMap<String, String> = HashMap::new();
29 for file in read_dir(list.download_folder)? { 37 for file in read_dir(list.download_folder)? {