Skip to content

Commit

Permalink
Merge branch 'stefan0xC-check-data-folder-permissions'
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed Oct 14, 2022
2 parents 736dbc9 + 46ec11d commit d1ff136
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ async fn check_data_folder() {
}
exit(1);
}
if !path.is_dir() {
error!("Data folder '{}' is not a directory.", data_folder);
exit(1);
}

if is_running_in_docker()
&& std::env::var("I_REALLY_WANT_VOLATILE_STORAGE").is_err()
Expand Down
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 @@ -326,7 +326,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 d1ff136

Please sign in to comment.