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

dev.sh fixups #2114

Merged
merged 8 commits into from
Feb 19, 2019
Merged

dev.sh fixups #2114

merged 8 commits into from
Feb 19, 2019

Conversation

ethomson
Copy link
Contributor

I cloned the azure-pipelines-agent to a directory name with a space in it and after doing so, dev.sh commands did not work; the bulk of these commits deal with that issue.

In particular, this starts quoting all variable strings to ensure that they're not wordsplit on spaces. Otherwise:

DIRECTORY="/home/ethomson/foo bar/asdf"
rm -rf $DIRECTORY

will remove both /home/ethomson/foo and bar asdf. Quoting as rm -rf "$DIRECTORY" will treat the entire path (with a space in it) as a single string, as expected.

This also adds some safety around rms to avoid accidentally coping with empty strings, similar to the problem that happened in ValveSoftware/steam-for-linux#3671. Otherwise, a cd into a directory followed by an rm becomes dangerous if the cd failed.

As a result, this enables set -e to avoid continuing when a cd or pushd (or any command) fails. (As would happen with an unquoted space in the path, or to a directory that doesn't exist.)

Similarly, using ${FOO:?}/* will ensure that if FOO is unset that the command fails instead of trying to rm /*.

After that I just ran shellcheck against the scripts and fixed up the remainder of warnings.

Instead of switching between windows and non-windows to determine how to
handle slashes for msbuild, use dashes instead of slashes to simplify
the calling.
Stop on errors, instead of continuing.  This prevents us from failing to
move through the directory space with `cd` / `pushd` / `popd` but still
running commands.  This is particularly dangerous when running commands
like `rm`.
Since directories may have a space in them, quote them to treat them as
a single entity instead of wordsplitting on a space.

Otherwise, if `FOO="a b c"` then `rm -rf $FOO` will remove files or
folders named `a`, b`, and `c` instead of removing the single entity
named `a b c`.
When expanding variables to pass to `rm`, make sure that the path
variable is set and fail if it is not.  This prevents an `rm` from
accidentally expanding to `rm ""/*` when the variable is unset:
ValveSoftware/steam-for-linux#3671

Using `${FOO:?}` syntax will fail when `FOO` is unset.
`$LastExitCode` is not a bash variable; to pass that string along to
PowerShell, it needs to be quoted.
The $(cmd) execution syntax is preferred over the legacy backtick
syntax.
Quote the variables for the directories so that we can properly work
with directories with spaces in their names.
@TingluoHuang
Copy link
Contributor

@ethomson Thanks! 🥇

@TingluoHuang TingluoHuang merged commit d3575d5 into microsoft:master Feb 19, 2019
@ethomson
Copy link
Contributor Author

Awesome, thanks @TingluoHuang! 😀

@ethomson ethomson deleted the devsh_fixups branch February 19, 2019 21:39
find "${LAYOUT_DIR}/bin" -type f -name '*.pdb' -delete

mkdir -p "$PACKAGE_DIR"
rm -Rf "${PACKAGE_DIR:?}/*"
Copy link

Choose a reason for hiding this comment

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

The * here got caught in the quotes.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 good catch, you want to create a PR? :)

Copy link

Choose a reason for hiding this comment

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

Thanks for the encouragement, but I'm afraid I care only enough to drop a drive-by comment. You can decide if it's actually worth fixing. :)

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.

3 participants