Skip to content

Commit 86a6dc9

Browse files
author
Kevin Paulisse
committed
Create a properly named file inside a tempdir
1 parent a7865f9 commit 86a6dc9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/octocatalog-diff/util/scriptrunner.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require 'fileutils'
66
require 'open3'
77
require 'shellwords'
8-
require 'tempfile'
98

109
module OctocatalogDiff
1110
module Util
@@ -92,13 +91,12 @@ def log(priority, message, logger = @logger)
9291
# @return [String] Path to tempfile containing script
9392
def temp_script(script)
9493
raise Errno::ENOENT, "Script '#{script}' not found" unless File.file?(script)
95-
script_name, extension = script.split('.', 2)
96-
tempfile = ::Tempfile.new([File.basename(script_name), ".#{extension}"])
97-
tempfile.write(File.read(script))
98-
tempfile.close
99-
FileUtils.chmod 0o755, tempfile.path
100-
at_exit { FileUtils.rm_f tempfile.path }
101-
tempfile.path
94+
temp_dir = Dir.mktmpdir
95+
at_exit { FileUtils.remove_entry_secure temp_dir }
96+
temp_file = File.join(temp_dir, File.basename(script))
97+
File.open(temp_file, 'w') { |f| f.write(File.read(script)) }
98+
FileUtils.chmod 0o755, temp_file
99+
temp_file
102100
end
103101

104102
# PRIVATE: Determine the path to the script to execute, taking into account the default script

0 commit comments

Comments
 (0)