}
@JRubyMethod(name = "identical?", required = 2, module = true)
public static IRubyObject identical_p(IRubyObject recv, IRubyObject filename1, IRubyObject filename2) {
Ruby runtime = recv.getRuntime();
FileResource file1 = fileResource(filename1);
FileResource file2 = fileResource(filename2);
if (Platform.IS_WINDOWS || !runtime.getPosix().isNative()) {
// posix stat uses inodes to determine indentity, and windows has no inodes
// (they are always zero), so we use canonical paths instead. (JRUBY-5726)
// If we can't load a native POSIX, use this same logic. (JRUBY-6982)
if (file1.exists() && file2.exists()) {
try {
String canon1 = new File(file1.absolutePath()).getCanonicalPath();
String canon2 = new File(file2.absolutePath()).getCanonicalPath();
return runtime.newBoolean(canon1.equals(canon2));
} catch (IOException canonicalizationError) {
return runtime.getFalse();
}
} else {
return runtime.getFalse();
}
}
FileStat stat1 = file1.stat();
FileStat stat2 = file2.stat();
return runtime.newBoolean(stat1 != null && stat2 != null && stat1.isIdentical(stat2));
}