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: d7c5b10a964e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0e8e7992562c
Choose a head ref
  • 7 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 8, 2017

  1. Copy the full SHA
    6ba780f View commit details
  2. Copy the full SHA
    00fe67e View commit details
  3. Copy the full SHA
    a5a0364 View commit details
  4. Copy the full SHA
    5ffee1b View commit details
  5. Copy the full SHA
    c226e3d View commit details
  6. Copy the full SHA
    3c3172c View commit details
  7. Copy the full SHA
    0e8e799 View commit details
Showing with 32 additions and 38 deletions.
  1. +0 −1 core/src/main/java/org/jruby/RubyBasicObject.java
  2. +1 −1 core/src/main/java/org/jruby/RubyDir.java
  3. +31 −36 core/src/main/java/org/jruby/RubyFile.java
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -2198,7 +2198,6 @@ public IRubyObject untaint(ThreadContext context) {
* from prog.rb:3
*/
public IRubyObject freeze(ThreadContext context) {
Ruby runtime = context.runtime;
if ((flags & FROZEN_F) == 0) {
flags |= FROZEN_F;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ public class RubyDir extends RubyObject {

private final static Encoding UTF8 = UTF8Encoding.INSTANCE;

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");
private static final Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");

public RubyDir(Ruby runtime, RubyClass type) {
super(runtime, type);
67 changes: 31 additions & 36 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -35,14 +35,11 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import jnr.constants.platform.OpenFlags;
import jnr.posix.POSIX;
import org.jcodings.Encoding;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
@@ -61,13 +58,14 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import jnr.constants.platform.OpenFlags;
import jnr.posix.POSIX;
import jnr.posix.util.Platform;
import org.jcodings.Encoding;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import jnr.posix.FileStat;
import jnr.posix.util.Platform;
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.FileSites;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
@@ -264,7 +262,7 @@ public RubyFile(Ruby runtime, RubyClass type) {

// XXX This constructor is a hack to implement the __END__ syntax.
// Converting a reader back into an InputStream doesn't generally work.
public RubyFile(Ruby runtime, String path, final Reader reader) {
RubyFile(Ruby runtime, String path, final Reader reader) {
this(runtime, path, new InputStream() {
@Override
public int read() throws IOException {
@@ -657,42 +655,38 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

public static Pattern PROTOCOL_PATTERN = Pattern.compile(URI_PREFIX_STRING + ".*");
static final Pattern PROTOCOL_PATTERN = Pattern.compile(URI_PREFIX_STRING + ".*");

public static String dirname(ThreadContext context, String jfilename) {
final Ruby runtime = context.runtime;
final String separator = runtime.getClass("File").getConstant("SEPARATOR").toString();
final RubyClass File = context.runtime.getFile();
final String separator = File.getConstant("SEPARATOR").toString();
final char separatorChar = separator.charAt(0);
String altSeparator = null;
char altSeparatorChar = '\0';
final IRubyObject rbAltSeparator = runtime.getClass("File").getConstant("ALT_SEPARATOR");
final IRubyObject rbAltSeparator = File.getConstant("ALT_SEPARATOR");
if (rbAltSeparator != context.nil) {
altSeparator = rbAltSeparator.toString();
altSeparatorChar = altSeparator.charAt(0);
altSeparator = rbAltSeparator.toString();
altSeparatorChar = altSeparator.charAt(0);
}
String name = jfilename;
if (altSeparator != null) {
name = jfilename.replace(altSeparator, separator);
name = jfilename.replace(altSeparator, separator);
}
int minPathLength = 1;
boolean trimmedSlashes = false;

boolean startsWithSeparator = false;

if (!name.isEmpty()) {
startsWithSeparator = name.charAt(0) == separatorChar;
startsWithSeparator = name.charAt(0) == separatorChar;
}

boolean startsWithUNCOnWindows = Platform.IS_WINDOWS && startsWith(name, separatorChar, separatorChar);

if (startsWithUNCOnWindows) {
minPathLength = 2;
}
if (startsWithUNCOnWindows) minPathLength = 2;

boolean startsWithDriveLetterOnWindows = startsWithDriveLetterOnWindows(name);

if (startsWithDriveLetterOnWindows) {
minPathLength = 3;
}
if (startsWithDriveLetterOnWindows) minPathLength = 3;

// jar like paths
if (name.contains(".jar!" + separator)) {
@@ -819,7 +813,7 @@ public static IRubyObject extname(ThreadContext context, IRubyObject recv, IRuby
*/
@JRubyMethod(name = "expand_path", required = 1, optional = 1, meta = true)
public static IRubyObject expand_path(ThreadContext context, IRubyObject recv, IRubyObject... args) {
return expandPathInternal(context, recv, args, true, false);
return expandPathInternal(context, args, true, false);
}

@Deprecated
@@ -849,17 +843,17 @@ public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv,
*/
@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false, false);
return expandPathInternal(context, args, false, false);
}

@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return expandPathInternal(context, recv, args, false, true);
return expandPathInternal(context, args, false, true);
}

@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
IRubyObject file = expandPathInternal(context, recv, args, false, true);
IRubyObject file = expandPathInternal(context, args, false, true);
if (!RubyFileTest.exist_p(recv, file).isTrue()) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
@@ -1140,14 +1134,14 @@ public static IRubyObject truncate19(ThreadContext context, IRubyObject recv, IR
@JRubyMethod(meta = true, optional = 1)
public static IRubyObject umask(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
int oldMask = 0;
int oldMask;
if (args.length == 0) {
oldMask = PosixShim.umask(runtime.getPosix());
} else if (args.length == 1) {
int newMask = (int) args[0].convertToInteger().getLongValue();
oldMask = PosixShim.umask(runtime.getPosix(), newMask);
} else {
runtime.newArgumentError("wrong number of arguments");
throw runtime.newArgumentError("wrong number of arguments");
}

return runtime.newFixnum(oldMask);
@@ -1246,9 +1240,7 @@ public static IRubyObject unlink(ThreadContext context, IRubyObject... args) {
// rb_file_size but not using stat
@JRubyMethod
public IRubyObject size(ThreadContext context) {
Ruby runtime = context.runtime;
OpenFile fptr;
FileStat st;
long size;

fptr = getOpenFileChecked();
@@ -1258,7 +1250,7 @@ public IRubyObject size(ThreadContext context) {

size = fptr.posix.size(fptr.fd());

return RubyFixnum.newFixnum(runtime, size);
return RubyFixnum.newFixnum(context.runtime, size);
}

@JRubyMethod(meta = true)
@@ -1458,6 +1450,7 @@ public String toString() {
return "RubyFile(" + openFile.getPath() + ", " + openFile.getMode();
}

@Deprecated // private
public static ZipEntry getFileEntry(ZipFile zf, String path) throws IOException {
ZipEntry entry = zf.getEntry(path);
if (entry == null) {
@@ -1468,10 +1461,12 @@ public static ZipEntry getFileEntry(ZipFile zf, String path) throws IOException
return entry;
}

@Deprecated // not-used
public static ZipEntry getDirOrFileEntry(String jar, String path) throws IOException {
return getDirOrFileEntry(new JarFile(jar), path);
}

@Deprecated // private
public static ZipEntry getDirOrFileEntry(ZipFile zf, String path) throws IOException {
String dirPath = path + '/';
ZipEntry entry = zf.getEntry(dirPath); // first try as directory
@@ -1592,7 +1587,7 @@ private void checkClosed(ThreadContext context) {

private static final Pattern PROTOCOL_PREFIX_PATTERN = Pattern.compile(URI_PREFIX_STRING);

private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject recv, IRubyObject[] args, boolean expandUser, boolean canonicalize) {
private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject[] args, boolean expandUser, boolean canonicalize) {
Ruby runtime = context.runtime;

RubyString origPath = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[0]));
@@ -1981,7 +1976,7 @@ private static String canonicalize(String canonicalPath, String remaining) {
// no canonical path yet or length is zero, and we have a / followed by a dot...
if (slash == -1) {
// we don't have another slash after this, so replace /. with /
if (canonicalPath != null && canonicalPath.length() == 0 && slash == -1) canonicalPath += '/';
if (canonicalPath != null && canonicalPath.length() == 0) canonicalPath += '/';
} else {
// we do have another slash; omit both / and . (JRUBY-1606)
}
@@ -2153,7 +2148,7 @@ private static IRubyObject truncateCommon(ThreadContext context, IRubyObject rec
RubyInteger newLength = arg2.convertToInteger();

File testFile ;
File childFile = new File(filename.getUnicodeValue() );
File childFile = new File(filename.getUnicodeValue());
String filenameString = Helpers.decodeByteList(runtime, filename.getByteList());

if ( childFile.isAbsolute() ) {
@@ -2202,7 +2197,7 @@ public IRubyObject initialize19(IRubyObject[] args, Block block) {
private static final int FNM_SYSCASE = Platform.IS_WINDOWS ? FNM_CASEFOLD : 0;

private static final String[] SLASHES = {"", "/", "//"};
private static Pattern URI_PREFIX = Pattern.compile("^(jar:)?[a-z]{2,}:(.*)");
private static final Pattern URI_PREFIX = Pattern.compile("^(jar:)?[a-z]{2,}:(.*)");

@Deprecated
protected String path;