Skip to content

Commit

Permalink
convert_to_shoulda_syntax: use Dir::tmpdir instead of hardcoded /tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
showaltb authored and rmm5t committed Jul 30, 2008
1 parent 630ce17 commit abc3aa7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bin/convert_to_should_syntax
@@ -1,5 +1,8 @@
#!/usr/bin/env ruby
require 'fileutils'
require 'tmpdir'

TMP = Dir::tmpdir

def usage(msg = nil)
puts "Error: #{msg}" if msg
Expand All @@ -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)
Expand Down

0 comments on commit abc3aa7

Please sign in to comment.