convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp

This commit is contained in:
Bob Showalter 2008-07-29 15:59:43 -04:00 committed by Ryan McGeary
parent 630ce17443
commit abc3aa73a4
1 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,8 @@
#!/usr/bin/env ruby
require 'fileutils'
require 'tmpdir'
TMP = Dir::tmpdir
def usage(msg = nil)
puts "Error: #{msg}" if msg
@ -18,16 +21,16 @@ def usage(msg = nil)
puts " ..."
puts " end"
puts
puts "A copy of the old file will be left under /tmp/ in case this script just seriously screws up"
puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up"
puts
exit (msg ? 2 : 0)
end
usage("Wrong number of arguments.") unless ARGV.size == 1
usage("This system doesn't have a /tmp directory. wtf?") unless File.directory?('/tmp')
usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP)
file = ARGV.shift
tmpfile = "/tmp/#{File.basename(file)}"
tmpfile = File.join(TMP, File.basename(file))
usage("File '#{file}' doesn't exist") unless File.exists?(file)
FileUtils.cp(file, tmpfile)