Skip to content

Commit

Permalink
Fix empty log filename bug
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted committed Mar 31, 2018
1 parent 3b1316c commit 06044bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-g"
version = "0.1.0"
version = "0.1.1"
authors = ["Bjorn Neergaard <bjorn@neersighted.com>"]

[lib]
Expand Down
9 changes: 6 additions & 3 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn write(filename: &str, data: String) -> Result<(), io::Error> {
FILE_MAP.with(|cell| {
let path = Path::new(filename);
let filename = path.file_name()
.unwrap()
.expect("invalid filename passed to write()")
.to_string_lossy()
.into_owned();

Expand All @@ -30,7 +30,7 @@ fn write(filename: &str, data: String) -> Result<(), io::Error> {
Occupied(elem) => elem.into_mut(),
Vacant(elem) => {
match path.parent() {
Some(p) => fs::create_dir_all(p)?,
Some(parent) => fs::create_dir_all(parent)?,
None => {},
};
let file = OpenOptions::new()
Expand All @@ -54,8 +54,11 @@ fn close() {
}

byond_function! { log_write(filename, line) {
let line = timestamped(line);
if filename.is_empty() {
return Some("no logfile specified!".to_string())
}

let line = timestamped(line);
match write(filename, line) {
Ok(_) => None,
Err(err) => Some(err.to_string()),
Expand Down

0 comments on commit 06044bb

Please sign in to comment.