Skip to content

Commit 4b9b7b3

Browse files
committed
fix: fail on static directories
1 parent 1c1b9d2 commit 4b9b7b3

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

cmd/functions.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ var (
5454

5555
useApi bool
5656
useDocker bool
57-
noVerifyJWT = new(bool)
5857
useLegacyBundle bool
58+
noVerifyJWT = new(bool)
5959
importMapPath string
6060

6161
functionsDeployCmd = &cobra.Command{
@@ -67,6 +67,9 @@ var (
6767
if !cmd.Flags().Changed("no-verify-jwt") {
6868
noVerifyJWT = nil
6969
}
70+
if useApi {
71+
useDocker = false
72+
}
7073
return deploy.Run(cmd.Context(), args, useDocker, noVerifyJWT, importMapPath, afero.NewOsFs())
7174
},
7275
}
@@ -126,14 +129,14 @@ func init() {
126129
functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
127130
functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
128131
deployFlags := functionsDeployCmd.Flags()
129-
deployFlags.BoolVar(&useApi, "use-api", true, "Use Management API to bundle functions.")
130-
deployFlags.BoolVar(&useDocker, "use-docker", false, "Use Docker to bundle functions.")
131-
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker")
132+
deployFlags.BoolVar(&useApi, "use-api", false, "Use Management API to bundle functions.")
133+
deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
134+
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
135+
functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
136+
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
132137
deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
133138
deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
134-
deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
135139
deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
136-
cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
137140
functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
138141
functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
139142
functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")

internal/functions/deploy/upload.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func upload(ctx context.Context, param api.V1DeployAFunctionParams, meta api.Fun
7979
defer w.Close()
8080
defer form.Close()
8181
if err := writeForm(form, meta, fsys); err != nil {
82+
// Since we are streaming files to the POST request body, any errors
83+
// should be propagated to the request context to cancel the upload.
8284
cancel(err)
8385
}
8486
}()
@@ -111,8 +113,7 @@ func writeForm(form *multipart.Writer, meta api.FunctionDeployMetadata, fsys afe
111113
if fi, err := f.Stat(); err != nil {
112114
return errors.Errorf("failed to stat file: %w", err)
113115
} else if fi.IsDir() {
114-
fmt.Fprintln(os.Stderr, "Skipping directory:", srcPath)
115-
return nil
116+
return errors.New("file path is a directory: " + srcPath)
116117
}
117118
fmt.Fprintln(os.Stderr, "Uploading asset:", srcPath)
118119
r := io.TeeReader(f, w)

internal/functions/deploy/upload_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ func TestWriteForm(t *testing.T) {
120120
// Check error
121121
assert.ErrorIs(t, err, os.ErrNotExist)
122122
})
123+
124+
t.Run("throws error on directory path", func(t *testing.T) {
125+
var buf bytes.Buffer
126+
form := multipart.NewWriter(&buf)
127+
require.NoError(t, form.SetBoundary("test"))
128+
// Setup in-memory fs
129+
fsys := afero.NewMemMapFs()
130+
// Run test
131+
err := writeForm(form, api.FunctionDeployMetadata{
132+
StaticPatterns: cast.Ptr([]string{"testdata"}),
133+
}, fsys)
134+
// Check error
135+
assert.ErrorContains(t, err, "file path is a directory:")
136+
})
123137
}
124138

125139
func TestDeployAll(t *testing.T) {

0 commit comments

Comments
 (0)