aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/exec.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-08 21:17:13 +0900
committernsfisis <nsfisis@gmail.com>2024-08-08 21:17:13 +0900
commita100dc8ba76aaeda2229940c1743c33cc0ef84b5 (patch)
treee2e48d8d92e2601d65e3ce7d794d8727026c14e0 /worker/exec.go
parentbb62b6ff19d9f8008458d1c0ad0b8b76090f091e (diff)
parent3b13a61123becc63823ab0c0941aaff2048b020e (diff)
downloadiosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.tar.gz
iosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.tar.zst
iosdc-japan-2024-albatross-a100dc8ba76aaeda2229940c1743c33cc0ef84b5.zip
Merge branch 'feat/code-hash'
Diffstat (limited to 'worker/exec.go')
-rw-r--r--worker/exec.go23
1 files changed, 8 insertions, 15 deletions
diff --git a/worker/exec.go b/worker/exec.go
index bd49162..9e937f7 100644
--- a/worker/exec.go
+++ b/worker/exec.go
@@ -3,7 +3,6 @@ package main
import (
"bytes"
"context"
- "crypto/md5"
"fmt"
"os"
"os/exec"
@@ -36,10 +35,6 @@ func prepareDirectories() error {
return nil
}
-func calcHash(code string) string {
- return fmt.Sprintf("%x", md5.Sum([]byte(code)))
-}
-
func calcFilePath(hash, ext string) string {
return fmt.Sprintf("%s/%s/%s.%s", dataRootDir, ext, hash, ext)
}
@@ -85,11 +80,11 @@ func convertCommandErrorToResultType(err error) string {
func execSwiftCompile(
ctx context.Context,
code string,
+ codeHash string,
maxDuration time.Duration,
) swiftCompileResponseData {
- hash := calcHash(code)
- inPath := calcFilePath(hash, "swift")
- outPath := calcFilePath(hash, "wasm")
+ inPath := calcFilePath(codeHash, "swift")
+ outPath := calcFilePath(codeHash, "wasm")
if err := os.WriteFile(inPath, []byte(code), 0644); err != nil {
return swiftCompileResponseData{
@@ -122,12 +117,11 @@ func execSwiftCompile(
func execWasmCompile(
ctx context.Context,
- code string,
+ codeHash string,
maxDuration time.Duration,
) wasmCompileResponseData {
- hash := calcHash(code)
- inPath := calcFilePath(hash, "wasm")
- outPath := calcFilePath(hash, "cwasm")
+ inPath := calcFilePath(codeHash, "wasm")
+ outPath := calcFilePath(codeHash, "cwasm")
stdout, stderr, err := execCommandWithTimeout(
ctx,
@@ -154,12 +148,11 @@ func execWasmCompile(
func execTestRun(
ctx context.Context,
- code string,
+ codeHash string,
stdin string,
maxDuration time.Duration,
) testRunResponseData {
- hash := calcHash(code)
- inPath := calcFilePath(hash, "cwasm")
+ inPath := calcFilePath(codeHash, "cwasm")
stdout, stderr, err := execCommandWithTimeout(
ctx,