From 739069a18f027986f1e05ee67609710bdc20fb89 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 30 Jun 2024 08:45:17 -0400 Subject: [PATCH] feat: convert local file to memory file --- internal/executors/sandbox/convert.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/executors/sandbox/convert.go b/internal/executors/sandbox/convert.go index e5b786f..827dd15 100644 --- a/internal/executors/sandbox/convert.go +++ b/internal/executors/sandbox/convert.go @@ -1,6 +1,7 @@ package sandbox import ( + "log/slog" "os" "path/filepath" "strings" @@ -113,7 +114,12 @@ func convertPBFile(i stage.CmdFile) *pb.Request_File { i.Src = &absPath } } - return &pb.Request_File{File: &pb.Request_File_Local{Local: &pb.Request_LocalFile{Src: *i.Src}}} + s, err := os.ReadFile(*i.Src) + if err != nil { + s = []byte{} + slog.Error("read file error", "path", *i.Src, "error", err) + } + return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}} case i.Content != nil: s := strToBytes(*i.Content) return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}