Skip to content

Commit 573db08

Browse files
committed
Fixes an issue in utils/untar.go
1 parent d27abcf commit 573db08

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

docs/writing-functions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ WASI platform in Python at the following [link](https://github.com/brettcannon/c
6969

7070
Serverledge assumes the structure of the `python.tar` file to be the following:
7171

72-
- `func.py`: this can also be in a sub-directory and is specified in the
73-
`handler` argument of the function creation
72+
- `func.py`: this can also be in a sub-directory and is specified in the `handler` argument of the function creation
7473
- `python.wasm`
7574
- `lib/`
7675

internal/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func CreateFunction(c echo.Context) error {
152152
if f.Runtime != container.CUSTOM_RUNTIME && f.Runtime != container.WASI_RUNTIME {
153153
_, ok := container.RuntimeToInfo[f.Runtime]
154154
if !ok {
155+
log.Printf("Creation request with invalid runtime: %s\n", f.Runtime)
155156
return c.JSON(http.StatusNotFound, "Invalid runtime.")
156157
}
157158
}

internal/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func create(cmd *cobra.Command, args []string) {
198198
if runtime != "custom" {
199199
var srcContent []byte
200200
u, err := url.ParseRequestURI(src)
201+
fmt.Println(u)
201202
if err == nil && u.Scheme != "" && u.Host != "" {
202203
// src is a URL
203204
srcContent = []byte(src)

utils/untar.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package utils
22

33
import (
44
"archive/tar"
5+
"fmt"
56
"io"
67
"os"
78
"path/filepath"
8-
"strings"
99
)
1010

1111
// Modified from: https://github.com/golang/build/blob/master/internal/untar/untar.go
@@ -24,15 +24,7 @@ func Untar(r io.Reader, dir string) (err error) {
2424
return err
2525
}
2626

27-
// Strip the first component from the header name
28-
components := strings.SplitN(header.Name, "/", 2)
29-
var target string
30-
31-
if len(components) > 1 {
32-
target = filepath.Join(dir, components[1]) // Skip the first component
33-
} else {
34-
target = filepath.Join(dir, header.Name) // No components to strip
35-
}
27+
target := filepath.Join(dir, header.Name)
3628

3729
// Check the file type
3830
switch header.Typeflag {
@@ -42,6 +34,14 @@ func Untar(r io.Reader, dir string) (err error) {
4234
return err
4335
}
4436
case tar.TypeReg:
37+
38+
// check if parent dirs exist
39+
parentDir := filepath.Dir(target)
40+
err := os.MkdirAll(parentDir, os.ModePerm) // os.ModePerm = 0777
41+
if err != nil {
42+
return fmt.Errorf("failed to create parent directories: %w", err)
43+
}
44+
4545
// Create file
4646
file, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
4747
if err != nil {

0 commit comments

Comments
 (0)