r/programminghorror • u/Scotty_scoodie • Jan 12 '26
It will be fine right?
Even this is in else condition. I'm not entirely sure that we should be running these code on Production (ubuntu server btw). I might as well commit the "sudo rm -rf /*" in the next change.
59
Upvotes
7
u/veritron Jan 12 '26
you're really better off not deleting files that you don't have access rights to in a script like this. who owns the files?
4
u/ferrybig Jan 13 '26
Looks fineish, it is an
rm -f, not anrm -rf. If you pass in/it will refuse to delete it since it is an directory. it also uses proper escaoeshellargs, so iforiginl_localis-r test,rmwill just sayrm: invalid option -- ' '18
u/deux3xmachina Jan 12 '26
It's usually a bad idea to use
sudo(8)in scripts, so unless there's somesudoers(5)magic involved we can't see, this is mostly saved by the lack of the-rflag. Might be fun to see if you can sneak in a target file like'-r -- /*'on a test machine.Should be pretty easy to limit the issues further too, but that'd require knowing more about the system as a whole. Low hanging fruit would be changing the command template to
sudo -- rm -vf -- "${sanitized_target}".Edit: secondary horror is the comments noting line numbers for the
elseclauses being closed by braces, rather than the conditions they're checking for, assuming they're needed at all.2
u/Geilokowski Jan 13 '26
The line numbers behind closing brackets scare me even more… i guess you could auto generate them on save but still, just imagine you have to do this nonsense manually and update 50 line numbers after every code change. Or is this related to accessibility?
3
u/traplords8n Jan 14 '26
I hate function_exists() lmao
Mainly because the last programmer in my role wouldn't organize his code in a standard way, and instead of including the correct files consistently, he just checked if the functions existed before using them.
For what purpose? I don't fucking know. Now I'm just trained to see that function and automatically assume it's bad code.
Is there a genuinely good use for that function?
1
u/Tricky-Confusion-157 Jan 16 '26
Why are 83-84 required if you delete the file as su?