From 2dd508691689d4f5a9c39f411837300666f4dfc7 Mon Sep 17 00:00:00 2001 From: Stefan Melmuk Date: Wed, 12 Oct 2022 01:07:12 +0200 Subject: [PATCH] more verbose permission denied error be a bit more verbose about why a file could not be created when it is caused by a permission denied error. --- src/util.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/util.rs b/src/util.rs index bdbb564e..16c0fce5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,7 @@ // // Web Headers and caching // -use std::io::Cursor; +use std::io::{Cursor, ErrorKind}; use rocket::{ fairing::{Fairing, Info, Kind}, @@ -311,7 +311,16 @@ pub fn file_exists(path: &str) -> bool { pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> { use std::io::Write; - let mut f = File::create(path)?; + let mut f = match File::create(path) { + Ok(file) => file, + Err(e) => { + if e.kind() == ErrorKind::PermissionDenied { + error!("Can't create '{}': Permission denied", path); + } + return Err(From::from(e)); + } + }; + f.write_all(content)?; f.flush()?; Ok(())