Permalink
Browse files
Fix File.readlink when chdir and avoid NPE
Existence test is moved in the catch block since readlink should succeed even if target does not exist.
Signed-off-by: Charles Oliver Nutter <headius@headius.com>
Loading branch information...
Showing
1 changed file
with
8 additions
and
6 deletions .
+8
−6
src/org/jruby/RubyFile.java
@@ -922,24 +922,26 @@ public static IRubyObject symlink(ThreadContext context, IRubyObject recv, IRuby
@JRubyMethod (required = 1 , meta = true )
public static IRubyObject readlink (ThreadContext context , IRubyObject recv , IRubyObject path ) {
Ruby runtime = context. getRuntime();
+ JRubyFile link = file(path);
try {
- String realPath = runtime. getPosix(). readlink(path. convertToString(). getUnicodeValue());
-
- if (! RubyFileTest . exist_p(recv, path). isTrue()) {
- throw runtime. newErrnoENOENTError(path. toString());
- }
-
+ String realPath = runtime. getPosix(). readlink(link. toString());
+
if (! RubyFileTest . symlink_p(recv, path). isTrue()) {
throw runtime. newErrnoEINVALError(path. toString());
}
if (realPath == null ) {
// FIXME: When we get JNA3 we need to properly write this to errno.
+ throw runtime. newErrnoFromLastPOSIXErrno();
}
return runtime. newString(realPath);
} catch (IOException e) {
+ if (! RubyFileTest . exist_p(recv, path). isTrue()) {
+ throw runtime. newErrnoENOENTError(link. toString());
+ }
+
throw runtime. newIOError(e. getMessage());
}
}
Toggle all file notes
0 comments on commit
7bb636e