fix bug and also some other stuff that i dont remember
This commit is contained in:
parent
2a8cca37e5
commit
1912b7bcb8
|
@ -36,10 +36,12 @@ pub fn create_config(file: &str) -> bool {
|
|||
let mut paths = replaced.split('/').collect::<Vec<&str>>(); // split path by /
|
||||
paths.pop();
|
||||
let path = paths.join("/");
|
||||
|
||||
let file_path = std::path::Path::new(&path); // Path without the filename
|
||||
|
||||
if file_path.parent().is_some() {
|
||||
// if the file_path has a parent folder
|
||||
println!("lib::create_config: creating folder {path}");
|
||||
match fs::create_dir_all(&path) {
|
||||
Ok(var) => var,
|
||||
Err(why) => {
|
||||
|
@ -51,6 +53,7 @@ pub fn create_config(file: &str) -> bool {
|
|||
|
||||
if file_path.exists() && !Path::new(&replaced).exists() {
|
||||
let file_contents = "{\"latest_date\": \"20021104\",\"cache_folder\": \"~/.cache/ggg\"}";
|
||||
|
||||
match fs::write(replaced, file_contents) {
|
||||
Ok(var) => var,
|
||||
Err(why) => {
|
||||
|
@ -116,7 +119,8 @@ pub fn link_to_datestring(link: String) -> String {
|
|||
}
|
||||
|
||||
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() {
|
||||
match fs::create_dir_all(p) {
|
||||
Ok(var) => var,
|
||||
|
|
|
@ -22,5 +22,5 @@ async fn main() {
|
|||
let current_page = ggg::get_page(&config.latest_date).await;
|
||||
|
||||
println!("image url: {}\ncache folder: {}", ¤t_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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue