Browse Source

🚸 DL JSON to tmp file to always have a clean one

master
n0m1s 6 years ago
parent
commit
c3fdc9d623
Signed by: nomis GPG Key ID: BC0454CAD76FE803
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      src/gitmoji.rs

+ 11
- 2
src/gitmoji.rs View File

@ -2,7 +2,7 @@ extern crate git2;
extern crate curl;
extern crate derive_more;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::io::Write;
use std::fs::File;
@ -93,7 +93,14 @@ pub fn update(url: &Url, repo_path: &Path, json_path: &Path) -> Result<(), Retri
return Ok(());
}
let mut file = File::create(&json_path)?;
let mut json_tmp_path = PathBuf::new();
json_tmp_path.push(json_path);
json_tmp_path.set_extension("json.new");
let json_tmp_path = json_tmp_path;
println!("tmp: \"{}\", path: \"{}\"", json_tmp_path.display(), json_path.display());
let mut file = File::create(&json_tmp_path)?;
let mut curl = Easy::new();
curl.url(&url.json_url)?;
@ -105,5 +112,7 @@ pub fn update(url: &Url, repo_path: &Path, json_path: &Path) -> Result<(), Retri
})?;
transfer.perform()?;
std::fs::rename(json_tmp_path, json_path)?;
Ok(())
}

Loading…
Cancel
Save