Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions src/org/jruby/RubyFileStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,44 @@ private void setup(String filename, boolean lstat) {
filename += "/";
}

if (filename.startsWith("file:") && filename.indexOf('!') != -1) {
// file: URL handling
String zipFileEntry = filename.substring(filename.indexOf("!") + 1);
if (zipFileEntry.length() > 0) {
if (zipFileEntry.charAt(0) == '/') {
if (zipFileEntry.length() > 1) {
zipFileEntry = zipFileEntry.substring(1);
} else {
if (filename.startsWith("file:") ) {
if (filename.indexOf('!') != -1) {
// file: URL handling
String zipFileEntry = filename.substring(filename.indexOf("!") + 1);
if (zipFileEntry.length() > 0) {
if (zipFileEntry.charAt(0) == '/') {
if (zipFileEntry.length() > 1) {
zipFileEntry = zipFileEntry.substring(1);
} else {
throw getRuntime().newErrnoENOENTError("invalid jar/file URL: " + filename);
}
}
} else {
throw getRuntime().newErrnoENOENTError("invalid jar/file URL: " + filename);
}
String zipfilename = filename.substring(5, filename.indexOf("!"));

try {
ZipFile zipFile = new ZipFile(zipfilename);
ZipEntry zipEntry = RubyFile.getFileEntry(zipFile, zipFileEntry);

if (zipEntry == null) {
throw getRuntime().newErrnoENOENTError("invalid jar/file URL: " + filename);
}
stat = new ZipFileStat(zipEntry);
return;
} catch (IOException ioe) {
// fall through and use the zip file as the file to stat
}

filename = zipfilename;
} else {
throw getRuntime().newErrnoENOENTError("invalid jar/file URL: " + filename);
}
String zipfilename = filename.substring(5, filename.indexOf("!"));

try {
ZipFile zipFile = new ZipFile(zipfilename);
ZipEntry zipEntry = RubyFile.getFileEntry(zipFile, zipFileEntry);

if (zipEntry == null) {
throw getRuntime().newErrnoENOENTError("invalid jar/file URL: " + filename);
}
stat = new ZipFileStat(zipEntry);
return;
} catch (IOException ioe) {
// fall through and use the zip file as the file to stat
}

filename = zipfilename;
}

file = JRubyFile.create(getRuntime().getCurrentDirectory(), filename);

if (file instanceof JRubyNonExistentFile) {
throw getRuntime().newErrnoENOENTError("No such file or directory - " + filename);
}
Expand Down