From: "Eregon (Benoit Daloze)" Date: 2012-08-17T02:12:31+09:00 Subject: [ruby-core:47224] [ruby-trunk - Bug #6884][Open] test_fileutils.rb might end up rm -rf the whole current directory Issue #6884 has been reported by Eregon (Benoit Daloze). ---------------------------------------- Bug #6884: test_fileutils.rb might end up rm -rf the whole current directory https://bugs.ruby-lang.org/issues/6884 Author: Eregon (Benoit Daloze) Status: Open Priority: Normal Assignee: Category: test Target version: 2.0.0 ruby -v: ruby 2.0.0dev (2012-08-15 trunk 36709) [x86_64-darwin10.8.0] Hi, I was preparing r36709 and launching `make test-all` and I interrupted it (Ctrl+C) as I forgot something. The next thing I saw is that my repository was deleted, as well as almost half the files. I think I don't need to tell you how that is fun. Hopefully I had a recent backup. So, the culprit seems the fileutils tests coupled with #teardown being in an ensure clause. You can see this behavior in https://gist.github.com/ab7d5ea2ae68eda6398b (if you press Ctrl+C within 2 seconds or not), and in test/fileutils/test_fileutils.rb lines 97-111. If #setup is interrupted, then #teardown is still run, because it is called an ensure block (in lib/minitest/unit.rb line 1074). What probably happened in my case is #setup did not yet Dir.chdir'd, and thus Dir.pwd in #teardown was the original current directory, and it happily rm -rf'd that at line 110. The fix for fileutils tests is obvious, Dir.pwd should not be used there. I'll fix them unless objection. But I'm worried about #teardown always being run (due to the ensure clause). Is that safe in the general case? It means the code must handle any part of #setup which was ran, which is increasingly complex. Sorry for the story-telling style, but I think it might better represent the danger in this issue. -- http://bugs.ruby-lang.org/