scan enum, Source property missing if fatal

This commit is contained in:
Quaternions 2023-09-11 19:18:55 -07:00
parent 06384f1086
commit ffb4b09e77

View File

@ -78,6 +78,11 @@ fn download(map_list: Vec<u64>) -> Result<(), Box<dyn std::error::Error>>{
} }
Ok(()) Ok(())
} }
enum Scan{
Passed,
Blocked,
}
fn scan() -> Result<(), Box<dyn std::error::Error>>{ fn scan() -> Result<(), Box<dyn std::error::Error>>{
let mut id = 0u32; let mut id = 0u32;
match std::fs::read_to_string("id"){ match std::fs::read_to_string("id"){
@ -106,15 +111,15 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
let scripts = get_scripts(dom); let scripts = get_scripts(dom);
//check scribb //check scribb
let mut any_failed=false; let mut fail_count=0;
let mut fail_type=Scan::Passed;
for script in scripts.iter() { for script in scripts.iter() {
if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") { if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") {
if allowed_set.contains(s) { if allowed_set.contains(s) {
println!("pass");
continue; continue;
}else{ }else{
println!("fail"); fail_type=Scan::Blocked;//no need to check for Flagged, it breaks the loop.
any_failed=true; fail_count+=1;
if !blocked.contains(s) { if !blocked.contains(s) {
blocked.insert(s.clone());//all fixed! just clone! blocked.insert(s.clone());//all fixed! just clone!
std::fs::write(format!("scripts/blocked/{}.lua",id),s)?; std::fs::write(format!("scripts/blocked/{}.lua",id),s)?;
@ -122,18 +127,18 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
} }
} }
}else{ }else{
println!("failed to get source"); panic!("FATAL: failed to get source for {:?}",file_thing.file_name());
any_failed=true;
} }
} }
if any_failed { let mut dest=match fail_type {
println!("One or more scripts are not allowed."); Scan::Passed => std::path::PathBuf::from("maps/processed"),
}else{ Scan::Blocked => {
let mut dest=std::path::PathBuf::from("maps/processed"); println!("{:?} - {} {} not allowed.",file_thing.file_name(),fail_count,if fail_count==1 {"script"}else{"scripts"});
dest.set_file_name(file_thing.file_name()); std::path::PathBuf::from("maps/purgatory")
dest.set_extension("rbxl");//extension is always rbxl even if source file is extensionless }
std::fs::rename(file_thing.path(), dest)?; };
} dest.push(file_thing.file_name());
std::fs::rename(file_thing.path(), dest)?;
} }
std::fs::write("id",id.to_string())?; std::fs::write("id",id.to_string())?;
Ok(()) Ok(())