fix: disable double pulls.

This commit is contained in:
2025-01-27 11:32:14 +08:00
parent 9aefd4a30c
commit 70883c231b
3 changed files with 22 additions and 58 deletions

View File

@@ -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(())
}