If the settings for TMPDIR, TMP, TEMP do not work, it is possible that the directory you specified does not exist or is not writable. Or the variable $ SAFE> 0. The tmp folder is defined using the Dir.tmpdir function (see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tmpdir/rdoc/Dir.html#method-c -tmpdir ).
class Dir def Dir::tmpdir tmp = '.' if $SAFE > 0 tmp = @@systmpdir else for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp'] if dir and stat = File.stat(dir) and stat.directory? and stat.writable? tmp = dir break end rescue nil end File.expand_path(tmp) end end end
Ruby 2.1
def Dir::tmpdir if $SAFE > 0 tmp = @@systmpdir else tmp = nil for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'] next if !dir dir = File.expand_path(dir) if stat = File.stat(dir) and stat.directory? and stat.writable? and (!stat.world_writable? or stat.sticky?) tmp = dir break end rescue nil end raise ArgumentError, "could not find a temporary directory" if !tmp tmp end end
So, if you set the TMP env variables, make sure the lines below are true
- $ SAFE == 0
- File.stat ("you_dir")
- File.stat ("you_dir"). Catalog?
- File.stat ("you_dir"). Recording?
Another way to set tempdir is to override tmpdir in your rails initializer, but obviously this bypasses any directory check, so you have to make sure that it exists / is written
class Dir def self.tmpdir "/your_directory/" end end
source share