diff --git a/src/web/executor.rs b/src/web/executor.rs index 646bb7e..596957e 100644 --- a/src/web/executor.rs +++ b/src/web/executor.rs @@ -1,4 +1,4 @@ -use std::{fs, io::Read, process::{Command, Stdio}}; +use std::{fs::{self, remove_file}, io::Read, process::{Command, Stdio}}; use rand::{distributions::Alphanumeric, Rng}; use serde::{Serialize, Deserialize}; @@ -31,10 +31,11 @@ async fn executor(_state: SharedState, data: ExecutorData) -> Result(); + let path = format!("/tmp/sandy-tmp/{name}"); - fs::write(format!("/tmp/sandy-tmp/{name}"), &data.code).unwrap(); + fs::write(path.clone(), &data.code).unwrap(); let mut out = Command::new("python") - .arg(format!("/tmp/sandy-tmp/{name}")) + .arg(path.clone()) .stdout(Stdio::piped()) .spawn() .unwrap(); @@ -53,6 +54,8 @@ async fn executor(_state: SharedState, data: ExecutorData) -> Result"); + + remove_file(path).unwrap(); Ok(Box::new(warp::reply::json(&stdout))) }