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

Tempfile.create (and perhaps other paths) does not detect "." and apply cwd #3698

Open
headius opened this issue Feb 25, 2016 · 2 comments
Open

Comments

@headius
Copy link
Member

headius commented Feb 25, 2016

A recent change to tmpdir.rb caused some problems for extensions installing:

diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 03c02fd..18d4fb6 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -138,7 +138,7 @@ def create(basename, *rest)
       end
       n = nil
       begin
-        path = File.expand_path(make_tmpname(basename, n), tmpdir)
+        path = File.join(tmpdir, make_tmpname(basename, n))

When installing an extension, RubyGems puts some requires and env setup into a temporary Ruby file it then loads:

    Tempfile.open %w"siteconf .rb", "." do |siteconf|
      t = siteconf
      siteconf.puts "require 'rbconfig'"
      siteconf.puts "dest_path = #{tmp_dest.dump}"
...

This Tempfile.open call attempts to make a temporary file in the current directory and open it as a normal file (since there's a block provided it can just delete the file when finished).

Tempfile.open circles back to Tempfile.initialize (in Java), which calls Dir::Tmpname.create (patched above). That proceeds to call a CallBlock in Tempfile that attempts to open the file:

    private class TempfileCallback implements BlockCallback {
        @Override
        public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
            Ruby runtime = context.runtime;
            IRubyObject tmpname = args[0], opts = args.length > 2 ? args[2] : context.nil;

...

            // let RubyFile do its init logic to open the channel
            Tempfile.super.initialize(context, new IRubyObject[]{tmpname, runtime.newFixnum(mode), opts}, Block.NULL_BLOCK);
            Tempfile.this.tmpname = tmpname;

            Tempfile.this.mode = runtime.newFixnum(mode & ~(OpenFlags.O_CREAT.intValue() | OpenFlags.O_EXCL.intValue()));
            Tempfile.this.opts = opts;

            return opts;

It is this Tempfile.super.initialize call that eventually blows up because the file has a "." but does not exist in the current directory. With the old tmpdir logic, the . got expanded based on cwd and worked properly.

The symptom I ran into was that any gems with extensions now fail to install, because that temporary environment-setting file can't be found.

I'll be reverting the tmpdir.rb line above for now.

@headius headius changed the title File.open (and perhaps other forms) does not detect "." and apply cwd Tempfile.create (and perhaps other paths) does not detect "." and apply cwd Feb 25, 2016
@headius
Copy link
Member Author

headius commented Feb 25, 2016

The line in question was changed in 2012 for https://bugs.ruby-lang.org/issues/7547 but it seems we didn't pick up this change until recently.

@headius
Copy link
Member Author

headius commented Mar 1, 2023

The commit that's a problem is here: ruby/tmpdir@82068d2

This is the only line keeping us from using the stock tmpdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants