(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 rand::{distributions::Alphanumeric, Rng};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
@ -31,10 +31,11 @@ async fn executor(_state: SharedState, data: ExecutorData) -> Result<Box<dyn Rep
|
||||||
.take(64)
|
.take(64)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect::<String>();
|
.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")
|
let mut out = Command::new("python")
|
||||||
.arg(format!("/tmp/sandy-tmp/{name}"))
|
.arg(path.clone())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -54,6 +55,8 @@ async fn executor(_state: SharedState, data: ExecutorData) -> Result<Box<dyn Rep
|
||||||
|
|
||||||
let stdout = stdout.replace('\n', "<br>");
|
let stdout = stdout.replace('\n', "<br>");
|
||||||
|
|
||||||
|
remove_file(path).unwrap();
|
||||||
|
|
||||||
Ok(Box::new(warp::reply::json(&stdout)))
|
Ok(Box::new(warp::reply::json(&stdout)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue