Live data from Hacker News

Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

github.com

31–40 of 280 posts

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#31
For those of you worried about important files, chattr +i is a useful defence. No easy way of applying this automatically.

Long ago I had a kernel hack that would kill any process that attempted to delete a canary file. Worked OK but no chance of it ever going mainstream.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#32
post #3

Here's the offending shell script code: # figure out the absolute path to the script being run a bit # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the # specified directory, then uses $PWD to figure out where that # directory lives - and all this in a subshell, so we don't affect # $PWD STEAMROOT="$(cd "${0%/*}" && echo $PWD)" [...] # Scary! rm -rf "$STEAMROOT/"* The programmer knew the danger and di…

Would this have stopped things getting deleted? if [ -z "$STEAMROOT" ] # something isnt right...

Not if the previous line was:

    STEAMROOT=$SOME_OTHER_UNSET_VARIABLE/
"rm -r " is a code smell, as much as "cc -o myprog .c" is. You should always know what files make up your system, and track them in a MANIFEST file. There's rarely a good reason to use wildcards when a program is dealing with its own files.

    xargs rm -df -- 
fixes this.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#33

# Scary! rm -rf "$STEAMROOT/"* Anybody who writes a line like this deserves their software engineer license revoked. This isn't the first time I've seen shit like this (I've seen it in scripts expected to be run as root, no less); it makes my blood boil. Seriously. "xargs rm -df -- EDIT: I shouldn't be so harsh, if it weren't for the comment admitting knowing how poor an idea this line is.

There's nothing wrong with that line as long as you know "$STEAMROOT" contains a directory that you wish to nuke.

The issue is that this particular script did not set up $STEAMROOT correctly.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#34
post #24

Note to all, prepend all your bash script with "set -o errexit -o nounset -o pipefail" It'll save you headaches.

Can you at least explain what this is doing, outside of saving me headaches?

http://redsymbol.net/articles/unofficial-bash-strict-mode/

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#35

# Scary! rm -rf "$STEAMROOT/"* Anybody who writes a line like this deserves their software engineer license revoked. This isn't the first time I've seen shit like this (I've seen it in scripts expected to be run as root, no less); it makes my blood boil. Seriously. "xargs rm -df -- EDIT: I shouldn't be so harsh, if it weren't for the comment admitting knowing how poor an idea this line is.

The programmer committed a cardinal sin to be sure. But, so did everyone on the code review that let it slide.

You're right, but I don't retract my statement, because we know the dev knew how dangerous this line was thanks to his "Scary!" comment.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#36
post #24

Note to all, prepend all your bash script with "set -o errexit -o nounset -o pipefail" It'll save you headaches.

Can you at least explain what this is doing, outside of saving me headaches?

-errexit: exit the script when a command fails -nounset: fail when referencing an unset variable -pipefail: fail when the any command in a pipeline fails, not just the last one

The last option is unfortunately harder to use, since some programs misbehave in pipelines.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#37

What is this magic doing? $(cd "${0%/*}")

Assuming the shell script is for Bash, that incantation removes the shortest matching suffix which matches the pattern "/*". So it is attempting to remove the filename component from a pathname string in the "0" positional parameter.

Since $0 is usually the name of the shellscript itself, this would be trying to obtain the directory path of the shellscript.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#38

Earlier quoted context omitted.

Would this have stopped things getting deleted? if [ -z "$STEAMROOT" ] # something isnt right...

Not if the previous line was: STEAMROOT=$SOME_OTHER_UNSET_VARIABLE/ "rm -r " is a code smell, as much as "cc -o myprog .c" is. You should always know what files make up your system, and track them in a MANIFEST file. There's rarely a good reason to use wildcards when a program is dealing with its own files. xargs rm -df -- fixes this.

What if you somehow wound up with a single line of / in the MANIFEST, though?

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#39
post #15

# Scary! rm -rf "$STEAMROOT/"* Anybody who writes a line like this deserves their software engineer license revoked. This isn't the first time I've seen shit like this (I've seen it in scripts expected to be run as root, no less); it makes my blood boil. Seriously. "xargs rm -df -- EDIT: I shouldn't be so harsh, if it weren't for the comment admitting knowing how poor an idea this line is.

[deleted]

No, I'm a developer who pays attention to his code, knows what he doesn't know, double-checks what he thinks he knows, and isn't too lazy to ask for help when he isn't sure about something.

Not to mention I've worked with someone before who wrote code exactly like this, despite my protestation, and after he managed to delete half the (thankfully backed-up) file share in an unrelated incident.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#40
post #3

Here's the offending shell script code: # figure out the absolute path to the script being run a bit # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the # specified directory, then uses $PWD to figure out where that # directory lives - and all this in a subshell, so we don't affect # $PWD STEAMROOT="$(cd "${0%/*}" && echo $PWD)" [...] # Scary! rm -rf "$STEAMROOT/"* The programmer knew the danger and di…

I thought I was a bad programmer until I saw this thread. How did this make it to prod?
Post reply on HN