Skip to content

Commit

Permalink
more verbose permission denied error
Browse files Browse the repository at this point in the history
be a bit more verbose about why a file could not be created when it is
caused by a permission denied error.
  • Loading branch information
stefan0xC committed Oct 11, 2022
1 parent 7532072 commit 2dd5086
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Web Headers and caching
//
use std::io::Cursor;
use std::io::{Cursor, ErrorKind};

use rocket::{
fairing::{Fairing, Info, Kind},
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 2dd5086

Please sign in to comment.