Skip to content

Commit

Permalink
fix: file didn't get truncated before writing replaced version
Browse files Browse the repository at this point in the history
  • Loading branch information
zetok committed Jun 10, 2016
1 parent 2065189 commit 15eac85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sterminator"
version = "0.0.0"
version = "0.0.1"
authors = ["Zetok Zalbavar <zetok@openmailbox.org>"]

[dependencies]
Expand Down
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ fn main() {

let mut www = String::new();
drop(web_file.read_to_string(&mut www));

for (original, translation) in json.as_object()
.expect(&format!("JSON {} is not an object!", json))
{
let tr = translation.as_string()
.expect(&format!("{:?} is not a string!", translation));
// use original if not string
let tr = translation.as_string().unwrap_or(original);

// Replaces `[[[String]]]` with supplied `String`.
//
//
// If there is no matching `[[[String]]]`, there's no change.
if tr.is_empty() {
www = www.replace(&format!("[[[{}]]]", original), original);
Expand All @@ -120,7 +120,9 @@ fn main() {
}

// write the file down
drop(web_file.set_len(0).expect(
&format!("Failed to truncate file {:?}", web_file)));
web_file.write_all(www.as_bytes())
.expect(&format!("Failed to write to file {:?}", web_file));
println!("{} done.", &args[1]);
println!("Done: {}", &args[1]);
}

0 comments on commit 15eac85

Please sign in to comment.