1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-26 05:50:29 +01:00

Merge pull request #710 from BlackDex/issue-709

Fixed issue #709 creating icon_cache directory.
Dieser Commit ist enthalten in:
Daniel García 2019-11-06 21:35:04 +01:00 committet von GitHub
Commit 948798a84f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 23 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -112,7 +112,9 @@ fn get_icon(domain: &str) -> Vec<u8> {
} }
Err(e) => { Err(e) => {
error!("Error downloading icon: {:?}", e); error!("Error downloading icon: {:?}", e);
mark_negcache(&path); let miss_indicator = path + ".miss";
let empty_icon = Vec::new();
save_icon(&miss_indicator, &empty_icon);
FALLBACK_ICON.to_vec() FALLBACK_ICON.to_vec()
} }
} }
@ -168,11 +170,6 @@ fn icon_is_negcached(path: &str) -> bool {
} }
} }
fn mark_negcache(path: &str) {
let miss_indicator = path.to_owned() + ".miss";
File::create(&miss_indicator).expect("Error creating negative cache marker");
}
fn icon_is_expired(path: &str) -> bool { fn icon_is_expired(path: &str) -> bool {
let expired = file_is_expired(path, CONFIG.icon_cache_ttl()); let expired = file_is_expired(path, CONFIG.icon_cache_ttl());
expired.unwrap_or(true) expired.unwrap_or(true)
@ -395,11 +392,17 @@ fn download_icon(domain: &str) -> Result<Vec<u8>, Error> {
} }
fn save_icon(path: &str, icon: &[u8]) { fn save_icon(path: &str, icon: &[u8]) {
create_dir_all(&CONFIG.icon_cache_folder()).expect("Error creating icon cache"); match File::create(path) {
Ok(mut f) => {
if let Ok(mut f) = File::create(path) {
f.write_all(icon).expect("Error writing icon file"); 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) => {
info!("Icon save error: {:?}", e);
}
}
} }
fn _header_map() -> HeaderMap { fn _header_map() -> HeaderMap {

Datei anzeigen

@ -25,6 +25,7 @@ extern crate num_derive;
use std::{ use std::{
path::Path, path::Path,
process::{exit, Command}, process::{exit, Command},
fs::create_dir_all,
}; };
#[macro_use] #[macro_use]
@ -52,6 +53,8 @@ fn main() {
check_web_vault(); check_web_vault();
migrations::run_migrations(); migrations::run_migrations();
create_icon_cache_folder();
launch_rocket(); launch_rocket();
} }
@ -129,8 +132,7 @@ fn check_db() {
let path = Path::new(&url); let path = Path::new(&url);
if let Some(parent) = path.parent() { if let Some(parent) = path.parent() {
use std::fs; if create_dir_all(parent).is_err() {
if fs::create_dir_all(parent).is_err() {
error!("Error creating database directory"); error!("Error creating database directory");
exit(1); exit(1);
} }
@ -148,6 +150,11 @@ fn check_db() {
db::get_connection().expect("Can't connect to DB"); db::get_connection().expect("Can't connect to DB");
} }
fn create_icon_cache_folder() {
// Try to create the icon cache folder, and generate an error if it could not.
create_dir_all(&CONFIG.icon_cache_folder()).expect("Error creating icon cache directory");
}
fn check_rsa_keys() { fn check_rsa_keys() {
// If the RSA keys don't exist, try to create them // If the RSA keys don't exist, try to create them
if !util::file_exists(&CONFIG.private_rsa_key()) || !util::file_exists(&CONFIG.public_rsa_key()) { if !util::file_exists(&CONFIG.private_rsa_key()) || !util::file_exists(&CONFIG.public_rsa_key()) {