fix bug and also some other stuff that i dont remember

This commit is contained in:
SadlyNotSappho 2023-08-30 12:19:13 -07:00
parent 2a8cca37e5
commit 1912b7bcb8
2 changed files with 6 additions and 2 deletions

View File

@ -36,10 +36,12 @@ pub fn create_config(file: &str) -> bool {
let mut paths = replaced.split('/').collect::<Vec<&str>>(); // split path by / let mut paths = replaced.split('/').collect::<Vec<&str>>(); // split path by /
paths.pop(); paths.pop();
let path = paths.join("/"); let path = paths.join("/");
let file_path = std::path::Path::new(&path); // Path without the filename let file_path = std::path::Path::new(&path); // Path without the filename
if file_path.parent().is_some() { if file_path.parent().is_some() {
// if the file_path has a parent folder // if the file_path has a parent folder
println!("lib::create_config: creating folder {path}");
match fs::create_dir_all(&path) { match fs::create_dir_all(&path) {
Ok(var) => var, Ok(var) => var,
Err(why) => { Err(why) => {
@ -51,6 +53,7 @@ pub fn create_config(file: &str) -> bool {
if file_path.exists() && !Path::new(&replaced).exists() { if file_path.exists() && !Path::new(&replaced).exists() {
let file_contents = "{\"latest_date\": \"20021104\",\"cache_folder\": \"~/.cache/ggg\"}"; let file_contents = "{\"latest_date\": \"20021104\",\"cache_folder\": \"~/.cache/ggg\"}";
match fs::write(replaced, file_contents) { match fs::write(replaced, file_contents) {
Ok(var) => var, Ok(var) => var,
Err(why) => { Err(why) => {
@ -116,7 +119,8 @@ pub fn link_to_datestring(link: String) -> String {
} }
pub fn ensure_exists(path: &str) { pub fn ensure_exists(path: &str) {
let p = Path::new(path); let replaced = path.replace('~', &get_home()[..]);
let p = Path::new(&replaced);
if !p.exists() { if !p.exists() {
match fs::create_dir_all(p) { match fs::create_dir_all(p) {
Ok(var) => var, Ok(var) => var,

View File

@ -22,5 +22,5 @@ async fn main() {
let current_page = ggg::get_page(&config.latest_date).await; let current_page = ggg::get_page(&config.latest_date).await;
println!("image url: {}\ncache folder: {}", &current_page.image, &config.cache_folder); println!("image url: {}\ncache folder: {}", &current_page.image, &config.cache_folder);
cache::download_image(&config.cache_folder, current_page.image, format!("{}.jpg", current_page.date)).await; cache::download_image(&config.cache_folder.replace('~', &ggg::get_home()[..]), current_page.image, format!("{}.jpg", current_page.date)).await;
} }