Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dir.tmpdir implementation differs between JRuby 9.1.5.0, MRI 2.3 #4451

Closed
evadne opened this issue Jan 22, 2017 · 1 comment
Closed

Dir.tmpdir implementation differs between JRuby 9.1.5.0, MRI 2.3 #4451

evadne opened this issue Jan 22, 2017 · 1 comment

Comments

@evadne
Copy link

evadne commented Jan 22, 2017

Continuing #4450 which was closed as “identical to MRI” but they are not exactly done the same way, since the original issue was closed I hope to have this discussion continued in a new issue, and apologise for the bother in advance.

Dir.tmpdir is implemented in JRuby 9.1.5.0 with:

def self.tmpdir
  if $SAFE > 0
    @@systmpdir.dup
  else
    tmp = nil
    # Search a directory which isn't world-writable first. In JRuby,
    # FileUtils.remove_entry_secure(dir) crashes when a dir is under
    # a world-writable directory because it tries to open directory.
    # Opening directory is not allowed in Java.
    dirs = [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.']
    for dir in dirs
      if dir and stat = File.stat(dir) and stat.directory? and stat.writable? and !stat.world_writable?
        return File.expand_path(dir)
      end
    end

    # Some OS sets the environment variables to '/tmp', which we may reject.
    warn "Unable to find a non world-writable directory for #{__method__}. Consider setting ENV['TMPDIR'], ENV['TMP'] or ENV['TEMP'] to a non world-writable directory."

    [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
      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" unless tmp
    tmp
  end
end

Dir.tmpdir is implemented in MRI 2.3 with:

def self.tmpdir
  if $SAFE > 0
    @@systmpdir.dup
  else
    tmp = nil
    [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
      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" unless tmp
    tmp
  end
end
@kares
Copy link
Member

kares commented Jan 22, 2017

you should have tried latest JRuby 9.1 ... the implementations are expected to be the same since 9.1.6.0
ee17203 (from #4184) - hopefully that does it for you - way too many issues around /tmp :)

@kares kares closed this as completed Jan 22, 2017
@kares kares added this to the Invalid or Duplicate milestone Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants