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::{
collections::HashMap,
fs::{create_dir_all, remove_file, symlink_metadata, File},
fs::{remove_file, symlink_metadata, File},
io::prelude::*,
net::{IpAddr, ToSocketAddrs},
sync::{Arc, RwLock},
@ -14,7 +14,7 @@ use rocket::{http::ContentType, response::Content, Route};
use crate::{
error::Error,
util::{get_reqwest_client_builder, Cached},
util::{get_reqwest_client_builder, write_file, Cached},
CONFIG,
};
@ -705,13 +705,8 @@ fn download_icon(domain: &str) -> Result<(Vec<u8>, Option<&str>), Error> {
}
fn save_icon(path: &str, icon: &[u8]) {
match File::create(path) {
Ok(mut f) => {
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");
}
match write_file(path, icon) {
Ok(_) => (),
Err(e) => {
warn!("Icon save error: {:?}", e);
}

6
src/config.rs

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

Loading…
Cancel
Save