Avoid filename conflicts and cleanup files after

This commit is contained in:
1computer1 2019-05-14 20:21:34 -04:00
parent 808066db94
commit 82eff621bf
21 changed files with 87 additions and 3 deletions

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.sh
bash program.sh
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.c
gcc program.c -o program && ./program
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.clj
clojure program.clj
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.cpp
g++ program.cpp -o program && ./program
cd .. && rm -rf "$COUNT"

View file

@ -1,6 +1,10 @@
if [ "$EVAL_EXPR" = "true" ]; then
csharp -e "$1"
else
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.cs
csc program.cs >/dev/null && mono program.exe
cd .. && rm -rf "$COUNT"
fi

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.exs
elixir program.exs
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.fs
fsharpc --optimize- program.fs >/dev/null && mono program.exe
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.go
go run program.go
cd .. && rm -rf "$COUNT"

View file

@ -1,6 +1,13 @@
if [ "$EVAL_EXPR" = "true" ]; then
ghc -e "$1"
else
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.hs
ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program
ghc -O0 -j +RTS -A128m -n2m -RTS \
-no-keep-o-files -no-keep-hi-files \
program.hs >/dev/null \
&& ./program
cd .. && rm -rf "$COUNT"
fi

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > Main.java
javac Main.java && java Main
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.lua
lua5.3 program.lua
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.ml
ocamlopt -cclib --static -o program program.ml && ./program
cd .. && rm -rf "$COUNT"

View file

@ -1,3 +1,5 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.pas
# fpc does not use stderr, ld however does, capture both
@ -9,3 +11,5 @@ else
echo "$res"
exit 1
fi
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.pl
perl program.pl
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.pl
swipl --quiet program.pl
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.py
python program.py
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.py
python program.py
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.rkt
racket program.rkt
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.rb
ruby program.rb
cd .. && rm -rf "$COUNT"

View file

@ -1,2 +1,6 @@
mkdir "$COUNT" && cd "$COUNT"
echo "$1" > program.rs
rustc -C opt-level=0 --color never program.rs && ./program
cd .. && rm -rf "$COUNT"

View file

@ -74,7 +74,7 @@ class LanguageHandler extends AkairoHandler {
try {
await this.handleSpawn(proc);
this.containers.set(id, { name });
this.containers.set(id, { name, count: 0 });
return this.containers.get(id);
} catch (err) {
throw err;
@ -83,9 +83,10 @@ class LanguageHandler extends AkairoHandler {
async evalCode({ language, code, options }) {
const { id = language.id, env = {} } = language.runWith(options);
const { name } = await this.setupContainer(id);
const { name, count } = await this.setupContainer(id);
const proc = childProcess.spawn('docker', [
'exec',
`-eCOUNT=${count}`,
...Object.entries(env).map(([k, v]) => `-e${k}=${v}`),
name, '/bin/sh', '/var/run/run.sh', code
]);