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

Make the install script a little bit safer when being piped #352

Merged
merged 1 commit into from
May 10, 2023

Conversation

glenjamin
Copy link
Contributor

If the connection cut out midway through, the script would partially execute.

Wrapping in a function ensures that nothing will be executed unless the file is fully downloaded

@glenjamin glenjamin requested a review from a team as a code owner November 28, 2019 18:15
@codecov
Copy link

codecov bot commented Nov 28, 2019

Codecov Report

Patch coverage has no change and project coverage change: -0.41 ⚠️

Comparison is base (bf399b8) 28.00% compared to head (f1cd9e8) 27.59%.

❗ Current head f1cd9e8 differs from pull request most recent head be8c3cc. Consider uploading reports for the commit be8c3cc to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #352      +/-   ##
===========================================
- Coverage    28.00%   27.59%   -0.41%     
===========================================
  Files           42       21      -21     
  Lines         4795     2732    -2063     
===========================================
- Hits          1343      754     -589     
+ Misses        3267     1892    -1375     
+ Partials       185       86      -99     

see 43 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@eric-hu eric-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restating how this works to make sure I'm understanding it right.

With the function wrapping everything, trap would exit the install function on an ERR signal from any command within install. Without the the install wrapper, trap would call error after a command like curl raised an ERR signal, but the next line of code would still execute. Does that match what happened before and after?

@glenjamin
Copy link
Contributor Author

This shouldn't make a difference to trap - I did a local test of making a command fail and it printed the error as before.

The main difference now is that when you run the script as curl <url> | bash, if the download aborts halfway through, the part of the script downloaded so far would still be passed to bash.

Wrapping in a function like this ensures that instead of executing half of the commands, we only define half of a function - nothing will be executed.

Copy link
Contributor

@taxonomic-blackfish taxonomic-blackfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing it out there that you now how nested functions which feels like an anti-pattern. I think should just shuffle this a bit to move error above install and also get consistent indentation so it's obvious the rest belongs in the function. And, a pedantic nit, but I prefer such "do all the things" functions to be called main to really capture intention.

@corinnesollows corinnesollows requested a review from a team as a code owner August 24, 2022 18:16
@am-bui
Copy link
Contributor

am-bui commented Aug 25, 2022

@glenjamin have you had a chance to consider @taxonomic-blackfish 's suggestions? We'd like to pick this pr back up but would also like to make sure the logic is up to date and applicable.

@rlegan rlegan changed the base branch from main to develop May 10, 2023 12:43
@rlegan rlegan requested a review from a team as a code owner May 10, 2023 12:43
@rlegan rlegan force-pushed the safer-pipe-install branch from c0af73d to be8c3cc Compare May 10, 2023 12:48
@rlegan rlegan force-pushed the safer-pipe-install branch from be8c3cc to 15acfb8 Compare May 10, 2023 12:53
@rlegan rlegan merged commit f3f5e9b into develop May 10, 2023
@rlegan rlegan deleted the safer-pipe-install branch May 10, 2023 13:11
@christian-stephen
Copy link
Contributor

Perhaps this is platform/shell specific, but this seems to introduce a bug because of a name collision with the install function and the system's install command. When I pipe the script into bash, it loops indefinitely as the install function recursively calls itself:

Starting installation.
Installing CircleCI CLI v0.1.26646
Installing to /usr/local/bin
Starting installation.
Installing CircleCI CLI v0.1.26646
Installing to /usr/local/bin
Starting installation.
Installing CircleCI CLI v0.1.26646
^C⏎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants