`FileUtils.rm_r` with secure option throws `Errno::ENOTEMPTY`
We have been using FileUtils.rm_r with secure option (FileUtils.rm_r(path, :secure => true)) and as per documentation, FileUtils.rm_r removes the root entries recursively, removes the root at the end. However, somehow we are sometimes (now always) getting Errno::ENOTEMPTY ("Directory not empty") exception with FileUtils.rm_r on the environment: Logstash with ruby 2.6.8, Windows OS (x86_64-mswin32). When checked the directory path, there were no files found in it, means empty dir.
:backtrace=>[
"org/jruby/RubyDir.java:471:in `rmdir'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:1459:in `block in remove_dir1'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:1473:in `platform_support'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:1458:in `remove_dir1'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:1451:in `remove'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:780:in `block in remove_entry'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:1508:in `postorder_traverse'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:778:in `remove_entry'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:698:in `remove_entry_secure'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:628:in `block in rm_r'", "org/jruby/RubyArray.java:1865:in `each'",
"C:/Program Files/logstash/vendor/jruby/lib/ruby/stdlib/fileutils.rb:626:in `rm_r'",
"C:/Program Files/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/outputs/s3/temporary_file.rb:54:in `delete!'",
"C:/Program Files/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/outputs/s3.rb:383:in `clean_temporary_file'", "org/jruby/RubyMethod.java:120:in `call'",
"C:/Program Files/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/outputs/s3/uploader.rb:60:in `upload'",
"C:/Program Files/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-integration-aws-7.0.1/lib/logstash/outputs/s3/uploader.rb:30:in `block in upload_async'",
"C:/Program Files/logstash/vendor/bundle/jruby/2.6.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb:79:in `run'"]
We wonder what would be a cause. Thanks.
Hello!
I think you're running into the issue fixed by https://github.com/ruby/fileutils/commit/ec5d3b84ea1e1d1b13c7dcb5bbe6cd5208c20a49. If you upgrade to fileutils 1.7.0 or higher, you should get a better error!
We have applied the 1.7.0 version in Logstash after multiple testing, will re-open if we still face.