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

Fix style #5648

Merged
merged 2 commits into from
Jul 26, 2023
Merged

Fix style #5648

merged 2 commits into from
Jul 26, 2023

Conversation

MetRonnie
Copy link
Member

Follow-up to #5639

@MetRonnie MetRonnie added this to the cylc-8.2.1 milestone Jul 25, 2023
@MetRonnie MetRonnie requested a review from hjoliver July 25, 2023 16:01
@MetRonnie MetRonnie self-assigned this Jul 25, 2023
@hjoliver
Copy link
Member

Sorry, didn't realize we were style checking under etc! 🤦

etc/bin/swarm Outdated
@@ -204,7 +204,7 @@ append_config () {
if prompt "Write \"$LINE\" to \"$LOC\"?"; then
if [[ "$POS" == top ]]; then
# ... at the top of the file
echo -e "${LINE}\n$(cat ${LOC})" > "$LOC"
echo -e "${LINE}\n$(cat "$LOC")" > temp && mv temp "$LOC"
Copy link
Member

@hjoliver hjoliver Jul 25, 2023

Choose a reason for hiding this comment

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

I get the quoting, but is the temp file necessary?

cat foo > foo wipes out foo, but the echo here makes it safe. (I confess I'm unsure of exactly why though!)

[Update]

In cat foo > foo, the file foo is opened in truncation mode before the command is executed, ready to receive the output of the command, so the content is lost.

In echo -e "$(cat foo)" > foo, the command substitution is done first (because it is used to construct the final command) before the file is opened in truncation mode, so this is safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

Funny, shellcheck was complaining about SC2094 locally

Make sure not to read and write the same file in the same pipeline

But apparently not on GH Actions?

Copy link
Member

@hjoliver hjoliver Jul 26, 2023

Choose a reason for hiding this comment

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

Ah OK, my local shellcheck must be outdated, didn't see that. However, going by my logic above, SC2094 should not apply for this particular construct.

etc/bin/swarm Outdated Show resolved Hide resolved
@hjoliver hjoliver merged commit de07f86 into cylc:8.2.x Jul 26, 2023
@MetRonnie MetRonnie deleted the style-fix branch July 26, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants