From 1691684c783380c18fd1fc5df30e4d61eb09b3d7 Mon Sep 17 00:00:00 2001 From: b1ek Date: Sun, 18 Feb 2024 02:51:27 +1000 Subject: [PATCH] (fix) delete the file after its run --- src/web/executor.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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))) }