diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-08 21:17:06 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-08 21:17:06 +0900 |
| commit | 3b13a61123becc63823ab0c0941aaff2048b020e (patch) | |
| tree | e2e48d8d92e2601d65e3ce7d794d8727026c14e0 /worker/exec.go | |
| parent | d94c9eb68e65d53f09bf3dd26ec4d61d245882ad (diff) | |
| download | iosdc-japan-2025-albatross-3b13a61123becc63823ab0c0941aaff2048b020e.tar.gz iosdc-japan-2025-albatross-3b13a61123becc63823ab0c0941aaff2048b020e.tar.zst iosdc-japan-2025-albatross-3b13a61123becc63823ab0c0941aaff2048b020e.zip | |
feat(backend/worker): calculate code hash in api-server
Diffstat (limited to 'worker/exec.go')
| -rw-r--r-- | worker/exec.go | 23 |
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, |
