| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,9 +37,6 @@ | |||
| 37 | 37 | ||
| 38 | 38 | import jnr.constants.platform.OpenFlags; | |
| 39 | 39 | import org.jcodings.Encoding; | |
| 40 | - import org.jruby.util.io.ModeFlags; | ||
| 41 | - import org.jruby.util.io.OpenFile; | ||
| 42 | - import org.jruby.util.io.ChannelDescriptor; | ||
| 43 | 40 | import java.io.File; | |
| 44 | 41 | import java.io.FileDescriptor; | |
| 45 | 42 | import java.io.FileNotFoundException; | |
@@ -76,23 +73,26 @@ | |||
| 76 | 73 | import org.jruby.util.ByteList; | |
| 77 | 74 | import org.jruby.util.FileResource; | |
| 78 | 75 | import org.jruby.util.JRubyFile; | |
| 76 | + import org.jruby.util.ResourceException; | ||
| 79 | 77 | import org.jruby.util.TypeConverter; | |
| 80 | - import org.jruby.util.io.DirectoryAsFileException; | ||
| 81 | - import org.jruby.util.io.PermissionDeniedException; | ||
| 82 | - import org.jruby.util.io.Stream; | ||
| 83 | - import org.jruby.util.io.ChannelStream; | ||
| 84 | - import org.jruby.util.io.IOOptions; | ||
| 78 | + import org.jruby.util.encoding.Transcoder; | ||
| 85 | 79 | import org.jruby.util.io.BadDescriptorException; | |
| 80 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 81 | + import org.jruby.util.io.ChannelStream; | ||
| 82 | + import org.jruby.util.io.DirectoryAsFileException; | ||
| 83 | + import org.jruby.util.io.EncodingUtils; | ||
| 86 | 84 | import org.jruby.util.io.FileExistsException; | |
| 85 | + import org.jruby.util.io.IOEncodable; | ||
| 86 | + import org.jruby.util.io.IOOptions; | ||
| 87 | 87 | import org.jruby.util.io.InvalidValueException; | |
| 88 | + import org.jruby.util.io.ModeFlags; | ||
| 89 | + import org.jruby.util.io.OpenFile; | ||
| 88 | 90 | import org.jruby.util.io.PipeException; | |
| 91 | + import org.jruby.util.io.Stream; | ||
| 89 | 92 | import static org.jruby.CompatVersion.*; | |
| 90 | 93 | import org.jruby.exceptions.RaiseException; | |
| 91 | 94 | import org.jruby.runtime.Helpers; | |
| 92 | 95 | import org.jruby.runtime.encoding.EncodingService; | |
| 93 | - import org.jruby.util.encoding.Transcoder; | ||
| 94 | - import org.jruby.util.io.EncodingUtils; | ||
| 95 | - import org.jruby.util.io.IOEncodable; | ||
| 96 | 96 | ||
| 97 | 97 | /** | |
| 98 | 98 | * Ruby File class equivalent in java. | |
@@ -1299,23 +1299,16 @@ private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) { | |||
| 1299 | 1299 | // TODO: check if too many open files, GC and try again | |
| 1300 | 1300 | ||
| 1301 | 1301 | return descriptor; | |
| 1302 | - } catch (PermissionDeniedException pde) { | ||
| 1303 | - // PDException can be thrown only when creating the file and | ||
| 1304 | - // permission is denied. See JavaDoc of PermissionDeniedException. | ||
| 1305 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1306 | - } catch (FileNotFoundException fnfe) { | ||
| 1307 | - // FNFException can be thrown in both cases, when the file | ||
| 1308 | - // is not found, or when permission is denied. | ||
| 1309 | - if (Ruby.isSecurityRestricted() || new File(path).exists()) { | ||
| 1310 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1311 | - } | ||
| 1312 | - throw getRuntime().newErrnoENOENTError(path); | ||
| 1313 | - } catch (DirectoryAsFileException dafe) { | ||
| 1314 | - throw getRuntime().newErrnoEISDirError(); | ||
| 1315 | - } catch (FileExistsException fee) { | ||
| 1316 | - throw getRuntime().newErrnoEEXISTError(path); | ||
| 1317 | - } catch (IOException ioe) { | ||
| 1318 | - throw getRuntime().newIOErrorFromException(ioe); | ||
| 1302 | + } catch (ResourceException resourceException) { | ||
| 1303 | + throw resourceException.newRaiseException(getRuntime()); | ||
| 1304 | + } catch (FileNotFoundException ignored) { | ||
| 1305 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1306 | + } catch (DirectoryAsFileException ignored) { | ||
| 1307 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1308 | + } catch (FileExistsException ignored) { | ||
| 1309 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1310 | + } catch (IOException ignored) { | ||
| 1311 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1319 | 1312 | } | |
| 1320 | 1313 | } | |
| 1321 | 1314 | ||
@@ -1325,34 +1318,18 @@ private Stream fopen(String path, ModeFlags flags) { | |||
| 1325 | 1318 | getRuntime(), | |
| 1326 | 1319 | path, | |
| 1327 | 1320 | flags); | |
| 1321 | + } catch (InvalidValueException ex) { | ||
| 1322 | + throw getRuntime().newErrnoEINVALError(); | ||
| 1323 | + } catch (PipeException ex) { | ||
| 1324 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1328 | 1325 | } catch (BadDescriptorException e) { | |
| 1329 | - throw getRuntime().newErrnoEBADFError(); | ||
| 1330 | - } catch (PermissionDeniedException pde) { | ||
| 1331 | - // PDException can be thrown only when creating the file and | ||
| 1332 | - // permission is denied. See JavaDoc of PermissionDeniedException. | ||
| 1333 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1326 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1334 | 1327 | } catch (FileNotFoundException ex) { | |
| 1335 | - // FNFException can be thrown in both cases, when the file | ||
| 1336 | - // is not found, or when permission is denied. | ||
| 1337 | - // FIXME: yes, this is indeed gross. | ||
| 1338 | - String message = ex.getMessage(); | ||
| 1339 | - | ||
| 1340 | - if (message.contains(/*P*/"ermission denied") || | ||
| 1341 | - message.contains(/*A*/"ccess is denied")) { | ||
| 1342 | - throw getRuntime().newErrnoEACCESError(path); | ||
| 1343 | - } | ||
| 1344 | - | ||
| 1345 | - throw getRuntime().newErrnoENOENTError(path); | ||
| 1346 | - } catch (DirectoryAsFileException ex) { | ||
| 1347 | - throw getRuntime().newErrnoEISDirError(); | ||
| 1328 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1348 | 1329 | } catch (FileExistsException ex) { | |
| 1349 | - throw getRuntime().newErrnoEEXISTError(path); | ||
| 1330 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1350 | 1331 | } catch (IOException ex) { | |
| 1351 | - throw getRuntime().newIOErrorFromException(ex); | ||
| 1352 | - } catch (InvalidValueException ex) { | ||
| 1353 | - throw getRuntime().newErrnoEINVALError(); | ||
| 1354 | - } catch (PipeException ex) { | ||
| 1355 | - throw getRuntime().newErrnoEPIPEError(); | ||
| 1332 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1356 | 1333 | } catch (SecurityException ex) { | |
| 1357 | 1334 | throw getRuntime().newErrnoEACCESError(path); | |
| 1358 | 1335 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,8 +36,11 @@ | |||
| 36 | 36 | package org.jruby; | |
| 37 | 37 | ||
| 38 | 38 | import org.jruby.runtime.Helpers; | |
| 39 | + import org.jruby.util.ResourceException; | ||
| 39 | 40 | import org.jruby.util.StringSupport; | |
| 41 | + import org.jruby.util.io.DirectoryAsFileException; | ||
| 40 | 42 | import org.jruby.util.io.EncodingUtils; | |
| 43 | + import org.jruby.util.io.FileExistsException; | ||
| 41 | 44 | import org.jruby.util.io.ModeFlags; | |
| 42 | 45 | import org.jruby.util.io.SelectBlob; | |
| 43 | 46 | import jnr.constants.platform.Fcntl; | |
@@ -87,8 +90,6 @@ | |||
| 87 | 90 | import org.jruby.util.io.ChannelStream; | |
| 88 | 91 | import org.jruby.util.io.InvalidValueException; | |
| 89 | 92 | import org.jruby.util.io.PipeException; | |
| 90 | - import org.jruby.util.io.FileExistsException; | ||
| 91 | - import org.jruby.util.io.DirectoryAsFileException; | ||
| 92 | 93 | import org.jruby.util.io.STDIO; | |
| 93 | 94 | import org.jruby.util.io.OpenFile; | |
| 94 | 95 | import org.jruby.util.io.ChannelDescriptor; | |
@@ -348,11 +349,7 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) { | |||
| 348 | 349 | openFile.setPath(path); | |
| 349 | 350 | ||
| 350 | 351 | if (openFile.getMainStream() == null) { | |
| 351 | - try { | ||
| 352 | - openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags())); | ||
| 353 | - } catch (FileExistsException fee) { | ||
| 354 | - throw runtime.newErrnoEEXISTError(path); | ||
| 355 | - } | ||
| 352 | + openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags())); | ||
| 356 | 353 | ||
| 357 | 354 | if (openFile.getPipeStream() != null) { | |
| 358 | 355 | openFile.getPipeStream().fclose(); | |
@@ -366,14 +363,16 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) { | |||
| 366 | 363 | // TODO: pipe handler to be reopened with path and "w" mode | |
| 367 | 364 | } | |
| 368 | 365 | } | |
| 366 | + } catch (InvalidValueException e) { | ||
| 367 | + throw runtime.newErrnoEINVALError(); | ||
| 369 | 368 | } catch (PipeException pe) { | |
| 370 | - throw runtime.newErrnoEPIPEError(); | ||
| 369 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 371 | 370 | } catch (IOException ex) { | |
| 372 | - throw runtime.newIOErrorFromException(ex); | ||
| 371 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 373 | 372 | } catch (BadDescriptorException ex) { | |
| 374 | - throw runtime.newErrnoEBADFError(); | ||
| 375 | - } catch (InvalidValueException e) { | ||
| 376 | - throw runtime.newErrnoEINVALError(); | ||
| 373 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 374 | + } catch (FileExistsException fee) { | ||
| 375 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 377 | 376 | } | |
| 378 | 377 | } | |
| 379 | 378 | ||
@@ -1241,16 +1240,19 @@ private static IRubyObject sysopenCommon(IRubyObject recv, IRubyObject[] args, B | |||
| 1241 | 1240 | runtime.getJRubyClassLoader()); | |
| 1242 | 1241 | // always a new fileno, so ok to use internal only | |
| 1243 | 1242 | fileno = descriptor.getFileno(); | |
| 1243 | + } catch (ResourceException resourceException) { | ||
| 1244 | + throw resourceException.newRaiseException(runtime); | ||
| 1245 | + } catch (FileNotFoundException ignored) { | ||
| 1246 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1247 | + } catch (DirectoryAsFileException ignored) { | ||
| 1248 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1249 | + } catch (FileExistsException ignored) { | ||
| 1250 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1251 | + } catch (IOException ignored) { | ||
| 1252 | + throw new IllegalStateException("For compile compatibility only"); | ||
| 1244 | 1253 | } | |
| 1245 | - catch (FileNotFoundException fnfe) { | ||
| 1246 | - throw runtime.newErrnoENOENTError(path); | ||
| 1247 | - } catch (DirectoryAsFileException dafe) { | ||
| 1248 | - throw runtime.newErrnoEISDirError(path); | ||
| 1249 | - } catch (FileExistsException fee) { | ||
| 1250 | - throw runtime.newErrnoEEXISTError(path); | ||
| 1251 | - } catch (IOException ioe) { | ||
| 1252 | - throw runtime.newIOErrorFromException(ioe); | ||
| 1253 | - } | ||
| 1254 | + | ||
| 1255 | + | ||
| 1254 | 1256 | return runtime.newFixnum(fileno); | |
| 1255 | 1257 | } | |
| 1256 | 1258 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import jnr.posix.FileStat; | |
| 4 | 4 | import jnr.posix.POSIX; | |
| 5 | - import org.jruby.exceptions.RaiseException; | ||
| 6 | 5 | import org.jruby.runtime.ThreadContext; | |
| 6 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 7 | + import org.jruby.util.io.ModeFlags; | ||
| 7 | 8 | ||
| 8 | 9 | class EmptyFileResource implements FileResource { | |
| 9 | 10 | // All empty resources are the same and immutable, so may as well | |
@@ -82,4 +83,9 @@ public JRubyFile hackyGetJRubyFile() { | |||
| 82 | 83 | // should be okay for now. | |
| 83 | 84 | return JRubyNonExistentFile.NOT_EXIST; | |
| 84 | 85 | } | |
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public ChannelDescriptor openDescriptor(ModeFlags flags, POSIX posix, int perm) throws ResourceException { | ||
| 89 | + throw new ResourceException.NotFound(absolutePath()); | ||
| 90 | + } | ||
| 85 | 91 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import jnr.posix.FileStat; | |
| 4 | 4 | import jnr.posix.POSIX; | |
| 5 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 6 | + import org.jruby.util.io.ModeFlags; | ||
| 5 | 7 | ||
| 6 | 8 | /** | |
| 7 | 9 | * This is a shared interface for files loaded as {@link java.io.File} and {@link java.util.zip.ZipEntry}. | |
@@ -33,4 +35,6 @@ public interface FileResource { | |||
| 33 | 35 | // JRubyFile if this resource is backed by one, and NOT_FOUND JRubyFile | |
| 34 | 36 | // otherwise. | |
| 35 | 37 | JRubyFile hackyGetJRubyFile(); | |
| 38 | + | ||
| 39 | + ChannelDescriptor openDescriptor(ModeFlags flags, POSIX posix, int perm) throws ResourceException; | ||
| 36 | 40 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,10 @@ | |||
| 1 | 1 | package org.jruby.util; | |
| 2 | 2 | ||
| 3 | + import jnr.posix.POSIX; | ||
| 4 | + import org.jruby.Ruby; | ||
| 5 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 6 | + import org.jruby.util.io.ModeFlags; | ||
| 7 | + | ||
| 3 | 8 | /** | |
| 4 | 9 | * Represents a directory in a jar. | |
| 5 | 10 | * | |
@@ -53,4 +58,11 @@ public String[] list() { | |||
| 53 | 58 | public boolean isRoot() { | |
| 54 | 59 | return "/".equals(path); | |
| 55 | 60 | } | |
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public ChannelDescriptor openDescriptor(ModeFlags flags, POSIX posix, int perm) throws ResourceException { | ||
| 64 | + // opening a directory seems to blow up with EACCESS in jruby (although MRI allows instantiation but blows up on read). | ||
| 65 | + // So mimicking that for now. | ||
| 66 | + throw new ResourceException.PermissionDenied(absolutePath()); | ||
| 67 | + } | ||
| 56 | 68 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,12 @@ | |||
| 1 | 1 | package org.jruby.util; | |
| 2 | 2 | ||
| 3 | - import java.util.jar.JarFile; | ||
| 3 | + import jnr.posix.POSIX; | ||
| 4 | + import org.jruby.Ruby; | ||
| 5 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 6 | + import org.jruby.util.io.ModeFlags; | ||
| 7 | + | ||
| 8 | + import java.io.InputStream; | ||
| 9 | + import java.nio.channels.Channels; | ||
| 4 | 10 | import java.util.jar.JarEntry; | |
| 5 | 11 | ||
| 6 | 12 | /** | |
@@ -14,10 +20,12 @@ | |||
| 14 | 20 | */ | |
| 15 | 21 | class JarFileResource extends JarResource { | |
| 16 | 22 | private final JarEntry entry; | |
| 23 | + private final InputStream entryStream; | ||
| 17 | 24 | ||
| 18 | - JarFileResource(String jarPath, JarEntry entry) { | ||
| 25 | + JarFileResource(String jarPath, JarEntry entry, InputStream entryStream) { | ||
| 19 | 26 | super(jarPath); | |
| 20 | 27 | this.entry = entry; | |
| 28 | + this.entryStream = entryStream; | ||
| 21 | 29 | } | |
| 22 | 30 | ||
| 23 | 31 | @Override | |
@@ -50,4 +58,9 @@ public String[] list() { | |||
| 50 | 58 | // Files cannot be listed | |
| 51 | 59 | return null; | |
| 52 | 60 | } | |
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public ChannelDescriptor openDescriptor(ModeFlags flags, POSIX posix, int perm) throws ResourceException { | ||
| 64 | + return new ChannelDescriptor(Channels.newChannel(entryStream), flags); | ||
| 65 | + } | ||
| 53 | 66 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,13 +2,17 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import jnr.posix.FileStat; | |
| 4 | 4 | import jnr.posix.POSIX; | |
| 5 | + import org.jruby.util.io.ChannelDescriptor; | ||
| 6 | + import org.jruby.util.io.ModeFlags; | ||
| 7 | + | ||
| 5 | 8 | import java.io.IOException; | |
| 9 | + import java.io.InputStream; | ||
| 6 | 10 | import java.util.regex.Matcher; | |
| 7 | 11 | import java.util.regex.Pattern; | |
| 8 | 12 | import java.util.jar.JarEntry; | |
| 9 | 13 | import java.util.jar.JarFile; | |
| 10 | 14 | ||
| 11 | - public abstract class JarResource implements FileResource { | ||
| 15 | + abstract class JarResource implements FileResource { | ||
| 12 | 16 | private static Pattern PREFIX_MATCH = Pattern.compile("^(?:jar:)?(?:file:)?(.*)$"); | |
| 13 | 17 | ||
| 14 | 18 | private static final JarCache jarCache = new JarCache(); | |
@@ -53,9 +57,14 @@ private static JarResource createJarResource(String jarPath, String path) { | |||
| 53 | 57 | return new JarDirectoryResource(jarPath, path, entries); | |
| 54 | 58 | } | |
| 55 | 59 | ||
| 56 | - JarEntry jarEntry = index.getJarEntry(path); | ||
| 57 | - if (jarEntry != null) { | ||
| 58 | - return new JarFileResource(jarPath, jarEntry); | ||
| 60 | + try { | ||
| 61 | + JarEntry jarEntry = index.getJarEntry(path); | ||
| 62 | + if (jarEntry != null) { | ||
| 63 | + InputStream jarEntryStream = index.jar.getInputStream(jarEntry); | ||
| 64 | + return new JarFileResource(path, jarEntry, jarEntryStream); | ||
| 65 | + } | ||
| 66 | + } catch (IOException ioe) { | ||
| 67 | + // Probably not a jar entry then | ||
| 59 | 68 | } | |
| 60 | 69 | ||
| 61 | 70 | return null; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments