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.
Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user
31–40 of 280 posts
Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user
#32Here'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...
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.
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
#34Note 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?
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.
Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user
#36Note 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?
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
#37What is this magic doing? $(cd "${0%/*}")
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
#38Earlier 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.
Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user
#39# 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]
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
#40Here'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…