fix: disable double pulls.
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -1,7 +1,10 @@
|
||||
use crate::fetch_problem::{Fetcher, ProblemManager};
|
||||
use std::fs;
|
||||
use std::fs::exists;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use anyhow::anyhow;
|
||||
use serde::de::Error;
|
||||
|
||||
mod fetch_problem;
|
||||
|
||||
@@ -41,8 +44,13 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_file(file_name: &String, file_content: &String) -> std::io::Result<()> {
|
||||
fn write_file(file_name: &String, file_content: &String) -> anyhow::Result<()> {
|
||||
let file_path = Path::new("./src/problem").join(format!("{}.rs", file_name));
|
||||
|
||||
if exists(&file_path)? {
|
||||
println!("{} has pulled.", file_name);
|
||||
return Err(anyhow!("{} has pulled", file_name));
|
||||
}
|
||||
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.write(true)
|
||||
@@ -58,5 +66,6 @@ fn write_file(file_name: &String, file_content: &String) -> std::io::Result<()>
|
||||
.append(true)
|
||||
.open("./src/problem/mod.rs")?;
|
||||
|
||||
write!(mod_file, "\nmod {};", file_name)
|
||||
write!(mod_file, "\nmod {};", file_name)?;
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user