I do not know what the code does, but I remember some years ago when I
wrote a ruby app, my supervisor asked me if it is dangerous to run the
code. He was quite scared of a problem because he was running as
superuser usually, and he was in charge of the local bioinformatics
cluster of the company - at that point I also got a bit nervous, so I
looked through the code I wrote and I did not see anything where it
screw up. But rm_rf actions CAN be scary - always pay good attention to
them! They scare me more than simply file-delete actions.
And I also realized that, when it comes to delete actions, in particular
removing directories, things can be really, really scary. While it was
mentioned to “do not run as superuser”, it being a valid comment, let’s
face it - people may be lazy or also do mistakes. It happens.
Ronald F. already gave one example how proper code could handle
it - e. g. ask interactively whether you are sure to delete a directory
In my own code, I also make sure that ‘/’ can never become a target.
(I have no code that would ever warrant getting rid of ‘/’ but I
do actually remember that I once, many years ago, also wiped out
my hdd; but this was via bash, when I was hitting tab complete
but was too swift with the space-character and then hitting enter,
I ended up having something like “rm /foo / bar” or something like
that. Since that day I usually do backups regularly. :D)
Anyway, I think that the code at:
is bad in general.
Or perhaps it is just so very different from how I would write this.
I would always use a generic delete/remove method, and inside of
that method, handle any additional checks. Such as querying for
file permissions and doing any other safeguards. I found that
this is usually a lot better than just directly calling
FileUtils.rm_rf() which sounds scary.
Last but not least, I would recommend you to also look at how many
issues a project has; sometimes the more issues that are CLOSED
the better, more people to look at a project AND also have a look
at rubygems.org - if a project has had lots of releases, it may
be that it is of quite good quality.
By the way, since you contacted the dude, this actually gave him
the possibility to also learn. I am sorry for the loss of your
data but I think this also shows that making backups is really
important. I don’t even trust myself or my own code fully, even
though I try to make it as good as possible.
One day we will be replaced by computers and they will write
much better code. Until then, we will write disaster code!