Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
harmony7 opened this issue Jul 28, 2024 · 0 comments · Fixed by #1349
Assignees
Labels
bug Something isn't working

Comments

@harmony7
Copy link
Member

harmony7 commented Jul 28, 2024

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.

@harmony7 harmony7 added the bug Something isn't working label Jul 28, 2024
@harmony7 harmony7 changed the title init command fails if file (or directory) with same name as the starter kit already exists in current directory init command with -p fails if file (or directory) with same name as the starter kit already exists in current directory Jul 28, 2024
@harmony7 harmony7 self-assigned this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant