Browse Source

Use `write_file` util everywhere

Removed creating icon cache dir as it's done on startup
pull/1842/head
Jake Howard 4 years ago
parent
commit
2c0ec4cdd3
No known key found for this signature in database GPG Key ID: 57AFB45680EDD477
  1. 13
      src/api/icons.rs
  2. 6
      src/config.rs

13
src/api/icons.rs

@ -1,6 +1,6 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::{create_dir_all, remove_file, symlink_metadata, File}, fs::{remove_file, symlink_metadata, File},
io::prelude::*, io::prelude::*,
net::{IpAddr, ToSocketAddrs}, net::{IpAddr, ToSocketAddrs},
sync::{Arc, RwLock}, sync::{Arc, RwLock},
@ -14,7 +14,7 @@ use rocket::{http::ContentType, response::Content, Route};
use crate::{ use crate::{
error::Error, error::Error,
util::{get_reqwest_client_builder, Cached}, util::{get_reqwest_client_builder, write_file, Cached},
CONFIG, CONFIG,
}; };
@ -705,13 +705,8 @@ fn download_icon(domain: &str) -> Result<(Vec<u8>, Option<&str>), Error> {
} }
fn save_icon(path: &str, icon: &[u8]) { fn save_icon(path: &str, icon: &[u8]) {
match File::create(path) { match write_file(path, icon) {
Ok(mut f) => { Ok(_) => (),
f.write_all(icon).expect("Error writing icon file");
}
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
create_dir_all(&CONFIG.icon_cache_folder()).expect("Error creating icon cache");
}
Err(e) => { Err(e) => {
warn!("Icon save error: {:?}", e); warn!("Icon save error: {:?}", e);
} }

6
src/config.rs

@ -8,7 +8,7 @@ use reqwest::Url;
use crate::{ use crate::{
db::DbConnType, db::DbConnType,
error::Error, error::Error,
util::{get_env, get_env_bool}, util::{get_env, get_env_bool, write_file},
}; };
static CONFIG_FILE: Lazy<String> = Lazy::new(|| { static CONFIG_FILE: Lazy<String> = Lazy::new(|| {
@ -691,9 +691,7 @@ impl Config {
} }
//Save to file //Save to file
use std::{fs::File, io::Write}; write_file(&CONFIG_FILE, config_str.as_bytes())?;
let mut file = File::create(&*CONFIG_FILE)?;
file.write_all(config_str.as_bytes())?;
Ok(()) Ok(())
} }

Loading…
Cancel
Save