From 91d683f6ad7a818312e9dc37b88eccd916e3b4d0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 20 Feb 2018 17:13:19 +0100 Subject: WorkbenchImportWorker: Use `File.unlink` instead of `#unlink` I was getting this error when I removed the `rescue nil`s: Failures: 1) WorkbenchImportWorker foreign lines uploads the following entries: ["OFFRE_TRANSDEV_20170301122517", "OFFRE_TRANSDEV_20170301122519"] Failure/Error: eg_file.unlink NoMethodError: undefined method `unlink' for # # ./app/workers/workbench_import_worker.rb:81:in `upload_entry_group_stream' # ./app/workers/workbench_import_worker.rb:52:in `upload_entry_group' # ./app/services/zip_service.rb:61:in `<<' # ./app/services/zip_service.rb:61:in `finish_current_output' # ./app/services/zip_service.rb:35:in `add_entry' # ./app/services/zip_service.rb:27:in `block in _subdirs' # .../.gem/ruby/2.3.3/gems/rubyzip-1.2.1/lib/zip/entry_set.rb:38:in `block in each' # .../.gem/ruby/2.3.3/gems/rubyzip-1.2.1/lib/zip/entry_set.rb:37:in `each' # .../.gem/ruby/2.3.3/gems/rubyzip-1.2.1/lib/zip/entry_set.rb:37:in `each' # .../.gem/ruby/2.3.3/gems/rubyzip-1.2.1/lib/zip/central_directory.rb:182:in `each' # ./app/services/zip_service.rb:26:in `_subdirs' # .../.gem/ruby/2.3.3/gems/rubyzip-1.2.1/lib/zip/file.rb:133:in `open_buffer' # ./app/services/zip_service.rb:21:in `block in subdirs' # ./app/workers/workbench_import_worker.rb:39:in `each' # ./app/workers/workbench_import_worker.rb:39:in `each_with_index' # ./app/workers/workbench_import_worker.rb:39:in `upload' # ./app/workers/workbench_import_worker.rb:19:in `perform' # ./spec/workers/workbench_import_worker_spec.rb:68:in `block (4 levels) in ' # ./spec/workers/workbench_import_worker_spec.rb:68:in `block (3 levels) in ' # ./spec/workers/workbench_import_worker_spec.rb:13:in `instance_eval' # ./spec/workers/workbench_import_worker_spec.rb:13:in `block in expect_upload_with' # .../.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `load' # .../.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `block in load' # .../.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency' # .../.gem/ruby/2.3.3/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:268:in `load' # .../.gem/ruby/2.3.3/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call' # -e:1:in `
' Johan said that in his tests on his local machine, the temp files weren't getting deleted. When I try running the specs, the temp files do get deleted, so not sure what was going on. Figure it may be because of the `rescue nil`s, so I decided to remove those in the hopes of always ensuring we close and unlink the temp files. The trouble with doing that, however, was that it caused the error and thus test failures like the example above. I managed to fix the problem by using `File.unlink` instead of the instance method. Hopefully this works to ensure that the temp files are always deleted. Refs #4315 --- app/workers/workbench_import_worker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/workers/workbench_import_worker.rb b/app/workers/workbench_import_worker.rb index 7dae7d7e7..53cbb222a 100644 --- a/app/workers/workbench_import_worker.rb +++ b/app/workers/workbench_import_worker.rb @@ -76,8 +76,8 @@ class WorkbenchImportWorker raise StopIteration, result.body end ensure - eg_file.close rescue nil - eg_file.unlink rescue nil + eg_file.close + File.unlink(eg_file.path) end -- cgit v1.2.3