Commit 656d800f8c72bc6bb97700b7289a2d5eebc4e42f

Authored by Jacob Vosmaer
1 parent 3ada8f45

Use Tempfile.open for automatic cleanup

Showing 1 changed file with 1 additions and 6 deletions   Show diff stats
app/models/key.rb
... ... @@ -56,15 +56,10 @@ class Key < ActiveRecord::Base
56 56 def generate_fingerpint
57 57 cmd_status = 0
58 58 cmd_output = ''
59   - file = Tempfile.new('gitlab_key_file')
60   -
61   - begin
  59 + Tempfile.open('gitlab_key_file') do |file|
62 60 file.puts key
63 61 file.rewind
64 62 cmd_output, cmd_status = popen("ssh-keygen -lf #{file.path}", '/tmp')
65   - ensure
66   - file.close
67   - file.unlink # deletes the temp file
68 63 end
69 64  
70 65 if cmd_status.zero?
... ...