Skip to content

Commit

Permalink
Fixes to get Rails on windows working more cleanly
Browse files Browse the repository at this point in the history
- Normalize paths on script entry, so __FILE__ is correct
- update win32api and openssl stubs to report more correctly
  • Loading branch information
nicksieger committed Sep 29, 2009
1 parent cda039d commit a3b8800
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
2 changes: 0 additions & 2 deletions lib/ruby/1.8/Win32API.rb
@@ -1,8 +1,6 @@
require 'rbconfig'
raise LoadError.new("Win32API only supported on win32") unless Config::CONFIG['host_os'] =~ /mswin/

warn "Win32API: This is only a partial implementation, and is likely broken"

require 'ffi'

class Win32API
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/site_ruby/shared/jruby/openssl/builtin.rb
Expand Up @@ -186,6 +186,6 @@ def create_mac
end
end
warn %{JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL}
http://jruby.kenai.com/pages/JRuby_Builtin_OpenSSL}
end
end
19 changes: 11 additions & 8 deletions src/org/jruby/runtime/load/ExternalScript.java
Expand Up @@ -34,6 +34,8 @@
import java.io.InputStream;
import org.jruby.Ruby;

import static org.jruby.util.JRubyFile.normalizeSeps;

public class ExternalScript implements Library {
private final LoadServiceResource resource;

Expand All @@ -42,30 +44,31 @@ public ExternalScript(LoadServiceResource resource, String name) {
}

public void load(Ruby runtime, boolean wrap) {
InputStream in = null;
try {
InputStream in = resource.getInputStream();

String name = resource.getName();
in = resource.getInputStream();
String name = normalizeSeps(resource.getName());
try {
name = java.net.URLDecoder.decode(name, "ISO-8859-1");
} catch(Exception ignored) {
}
} catch(Exception ignored) {}

if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
runtime.compileAndLoadFile(name, in, wrap);
} else {
java.io.File path = resource.getPath();

if(path != null && !resource.isAbsolute()) {
name = path.getCanonicalPath();
name = normalizeSeps(path.getCanonicalPath());
}

runtime.loadFile(name, in, wrap);
}
// FIXME: This should be in finally
in.close();


} catch (IOException e) {
throw runtime.newIOErrorFromException(e);
} finally {
try { in.close(); } catch (Exception ex) {}
}
}

Expand Down
25 changes: 16 additions & 9 deletions src/org/jruby/util/JRubyFile.java
Expand Up @@ -38,6 +38,7 @@
import org.jruby.Ruby;

import org.jruby.ext.posix.JavaSecuredFile;
import org.jruby.platform.Platform;

/**
* <p>This file acts as an alternative to NormalizedFile, due to the problems with current working
Expand All @@ -51,6 +52,14 @@ public static JRubyFile create(String cwd, String pathname) {
return createNoUnicodeConversion(cwd, pathname);
}

public static String normalizeSeps(String path) {
if (Platform.IS_WINDOWS) {
return path.replace(File.separatorChar, '/');
} else {
return path;
}
}

private static JRubyFile createNoUnicodeConversion(String cwd, String pathname) {
if (pathname == null || pathname.equals("") || Ruby.isSecurityRestricted()) {
return JRubyNonExistentFile.NOT_EXIST;
Expand All @@ -66,9 +75,7 @@ private static JRubyFile createNoUnicodeConversion(String cwd, String pathname)
}

public static String getFileProperty(String property) {
String value = SafePropertyAccessor.getProperty(property, "/");

return value.replace(File.separatorChar, '/');
return normalizeSeps(SafePropertyAccessor.getProperty(property, "/"));
}

private JRubyFile(File file) {
Expand All @@ -81,22 +88,22 @@ protected JRubyFile(String filename) {

@Override
public String getAbsolutePath() {
return new File(super.getPath()).getAbsolutePath().replace(File.separatorChar, '/');
return normalizeSeps(new File(super.getPath()).getAbsolutePath());
}

@Override
public String getCanonicalPath() throws IOException {
return super.getCanonicalPath().replace(File.separatorChar, '/');
return normalizeSeps(super.getCanonicalPath());
}

@Override
public String getPath() {
return super.getPath().replace(File.separatorChar, '/');
return normalizeSeps(super.getPath());
}

@Override
public String toString() {
return super.toString().replace(File.separatorChar, '/');
return normalizeSeps(super.toString());
}

@Override
Expand All @@ -113,7 +120,7 @@ public File getCanonicalFile() throws IOException {
public String getParent() {
String par = super.getParent();
if (par != null) {
par = par.replace(File.separatorChar, '/');
par = normalizeSeps(par);
}
return par;
}
Expand Down Expand Up @@ -154,7 +161,7 @@ public String[] list(FilenameFilter filter) {

String[] smartFiles = new String[files.length];
for (int i = 0; i < files.length; i++) {
smartFiles[i] = files[i].replace(File.separatorChar, '/');
smartFiles[i] = normalizeSeps(files[i]);
}
return smartFiles;
}
Expand Down

0 comments on commit a3b8800

Please sign in to comment.