Skip to content

init command with -p fails if file (or directory) with same name as the starter kit already exists in current directory #1255

@harmony7

Description

@harmony7

Version

Fastly CLI version v10.12.3 (f0fe32f4)
Built with go version go1.22.4 linux/amd64 (2024-07-28)
Viceroy version: viceroy 0.10.2

What happened

% cd ./my-app
% fastly compute init -p ./my-app
Creating a new Compute project.

Press ^C at any time to quit.

  ... (skipping lines of output) ...

Starter kit:
[1] Default starter for JavaScript
    A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules.
    https://github.com/fastly/compute-starter-kit-javascript-default
[2] Empty starter for JavaScript
    An empty application template for the Fastly Compute environment which returns a 200 OK response.
    https://github.com/fastly/compute-starter-kit-javascript-empty
[3] Default starter for TypeScript
    A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules.
    https://github.com/fastly/compute-starter-kit-typescript

INFO: For a complete list of Starter Kits:
    https://www.fastly.com/documentation/solutions/starters

Choose option or paste git URL: [1] 1

✗ Fetching package template

ERROR: failed to create local compute-starter-kit-javascript-default archive: open compute-starter-kit-javascript-default: is a directory.

If you believe this error is the result of a bug, please file an issue: https://github.com/fastly/cli/issues/new?labels=bug&template=bug_report.md
%

This occurs when a directory called compute-starter-kit-javascript-default already exists in the current directory.

The problem seems to arise from

filename := filepath.Base(c.CloneFrom)
ext := filepath.Ext(filename)
// gosec flagged this:
// G304 (CWE-22): Potential file inclusion via variable
//
// Disabling as we require a user to configure their own environment.
/* #nosec */
f, err := os.Create(filename)
where the file is created in the current directory, rather than using something like os.TempDir().

My current workaround is to forego the -p argument and switch to my-app directory first before running the command.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions