Skip to content

Commit

Permalink
Properly extract the 'perm' kwarg to File.open
Browse files Browse the repository at this point in the history
The logic here was incorrectly ported. The original code checks
the vperm pointer passed in to know whether it can be
dereferenced. The broken code in JRuby ends up requiring a
a non-null positional vperm argument in order to use the kwarg,
which then immediately errors anyway.

The new code if the perm kwarg and the positional vperm are both
set, but if only the kwarg is given, it will be used for the new
file.

Fixes failures switching from our own native Tempfile to the
tempfile gem.

See jruby#7973
  • Loading branch information
headius committed Oct 26, 2023
1 parent b9fe936 commit 45daaad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ public static void extractModeEncoding(ThreadContext context,

v = hashARef(runtime, options, "perm");
if (!v.isNil()) {
if (vperm(vmodeAndVperm_p) != null) {
if (!vperm(vmodeAndVperm_p).isNil()) throw runtime.newArgumentError("perm specified twice");

vperm(vmodeAndVperm_p, v);
if (vperm(vmodeAndVperm_p) != null && !vperm(vmodeAndVperm_p).isNil()) {
throw runtime.newArgumentError("perm specified twice");
}

vperm(vmodeAndVperm_p, v);
} else {
/* perm no use, just ignore */
}

IRubyObject extraFlags = hashARef(runtime, options, "flags");
Expand Down

0 comments on commit 45daaad

Please sign in to comment.