Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a9b383693a46
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 39fcae26f582
Choose a head ref
  • 4 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 27, 2018

  1. Copy the full SHA
    7b8ca7a View commit details
  2. Copy the full SHA
    7b6a410 View commit details
  3. Update File#path to raise an IOError for files opened with File::Cons…

    …tants::TMPFILE option
    
    For more information, please see feature #13568.
    nomadium committed Jan 27, 2018
    Copy the full SHA
    c2a2d25 View commit details

Commits on Jan 29, 2018

  1. Merge pull request #4991 from nomadium/file-path-now-raises-ioerror-w…

    …hen-tmpfile
    
    Update File#path to raise IOError for files opened with File::Constants::TMPFILE option
    enebo authored Jan 29, 2018
    Copy the full SHA
    39fcae2 View commit details
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -455,6 +455,9 @@ public static IRubyObject path(ThreadContext context, IRubyObject self, IRubyObj

@JRubyMethod(name = {"path", "to_path"})
public IRubyObject path(ThreadContext context) {
if ((openFile.getMode() & OpenFile.TMPFILE) != 0) {
throw context.runtime.newIOError("File is unnamed (TMPFILE?)");
}
IRubyObject newPath = context.runtime.getNil();
final String path = getPath();
if (path != null) {
14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/util/io/ModeFlags.java
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ public class ModeFlags implements Cloneable {
public static final int NONBLOCK = OpenFlags.O_NONBLOCK.intValue();
/** binary flag, to ensure no encoding changes are made while writing */
public static final int BINARY = OpenFlags.O_BINARY.intValue();
public static final int TMPFILE = OpenFlags.O_TMPFILE.intValue();
/** textmode flag, MRI has no equivalent but we use ModeFlags currently
* to also capture what are oflags.
*/
@@ -271,6 +272,15 @@ public boolean isText() {
return (flags & TEXT) != 0;
}

/**
* Whether the flags specify "unnamed temporary".
*
* @return true if unnamed temporary mode, false otherwise
*/
public boolean isTemporary() {
return (flags & TMPFILE) != 0;
}

/**
* Whether the flags specify to create nonexisting files.
*
@@ -347,6 +357,7 @@ public String toString() {
if (isExclusive()) buf.append("EXCLUSIVE ");
if (isReadOnly()) buf.append("READONLY ");
if (isText()) buf.append("TEXT ");
if (isTemporary()) buf.append("TMPFILE ");
if (isTruncate()) buf.append("TRUNCATE ");
if (isWritable()) {
if (isReadable()) {
@@ -396,6 +407,9 @@ public static int getOpenFileFlagsFor(int flags) {
if ((flags & BINARY) == BINARY) {
fmodeFlags |= OpenFile.BINMODE;
}
if ((flags & TMPFILE) == TMPFILE) {
fmodeFlags |= OpenFile.TMPFILE;
}

// This is unique to us to keep bridge betweeen mode_flags and oflags
if ((flags & TEXT) == TEXT) {
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ public OpenFile(IRubyObject nil) {
public static final int TRUNC = 0x00000800;
public static final int TEXTMODE = 0x00001000;
public static final int SETENC_BY_BOM = 0x00100000;
public static final int TMPFILE = 0x00410000;
public static final int PREP = (1<<16);

public static final int SYNCWRITE = SYNC | WRITABLE;
12 changes: 12 additions & 0 deletions test/mri/ruby/test_file.rb
Original file line number Diff line number Diff line change
@@ -468,4 +468,16 @@ def test_open_nul
assert_file.not_exist?(path)
end
end

def test_open_tempfile_path
Dir.mktmpdir(__method__.to_s) do |tmpdir|
File.open(tmpdir, File::RDWR | File::TMPFILE) do |io|
io.write "foo"
io.flush
assert_equal 3, io.size
assert_raise(IOError) { io.path }
end
end
end if File::Constants.const_defined?(:TMPFILE)

end