Skip to content

Commit

Permalink
Don't rely on FileStat#isIdentical on Windows, since it does not work…
Browse files Browse the repository at this point in the history
… [JRUBY-5726]

FileStat#isIndentical uses inodes for identity, but Windows doesn't
support inodes, and always returns zero, making all files appear identical.

Signed-off-by: Hiro Asari <asari.ruby@gmail.com>
  • Loading branch information
tobias authored and BanzaiMan committed Sep 15, 2011
1 parent ae2f3e4 commit 58d9a33
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/org/jruby/RubyFileTest.java
Expand Up @@ -186,9 +186,21 @@ public static IRubyObject identical_p(IRubyObject recv, IRubyObject filename1, I
Ruby runtime = recv.getRuntime();
JRubyFile file1 = file(filename1);
JRubyFile file2 = file(filename2);


if (Platform.IS_WINDOWS) {
// posix stat uses inodes to determine indentity, and windows has no inodes
// (they are always zero), so we use canonical paths instead. (JRUBY-5726)
try {
return runtime.newBoolean(file1.exists() && file2.exists() &&
file1.getCanonicalPath().equals(file2.getCanonicalPath()));
} catch (IOException e) {
// this is indicative of something really wrong, but for now...
return runtime.getFalse();
}
}

return runtime.newBoolean(file1.exists() && file2.exists() &&
runtime.getPosix().stat(file1.getAbsolutePath()).isIdentical(runtime.getPosix().stat(file2.getAbsolutePath())));
runtime.getPosix().stat(file1.getAbsolutePath()).isIdentical(runtime.getPosix().stat(file2.getAbsolutePath())));
}

@JRubyMethod(name = "owned?", required = 1, module = true)
Expand Down

0 comments on commit 58d9a33

Please sign in to comment.