(fix) delete the file after its run
This commit is contained in:
parent
b390f74431
commit
1691684c78
|
@ -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<Box<dyn Rep
|
|||
.take(64)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
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<Box<dyn Rep
|
|||
}
|
||||
|
||||
let stdout = stdout.replace('\n', "<br>");
|
||||
|
||||
remove_file(path).unwrap();
|
||||
|
||||
Ok(Box::new(warp::reply::json(&stdout)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue