/** * Same as openForRandomRead except that it will run even if security is off. * This is used by unit tests. */ @VisibleForTesting protected static RandomAccessFile forceSecureOpenForRandomRead(File f, String mode, String expectedOwner, String expectedGroup) throws IOException { RandomAccessFile raf = new RandomAccessFile(f, mode); boolean success = false; try { Stat stat = NativeIO.POSIX.getFstat(raf.getFD()); checkStat(f, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup); success = true; return raf; } finally { if (!success) { raf.close(); } } }
/** * Same as openFSDataInputStream except that it will run even if security is * off. This is used by unit tests. */ @VisibleForTesting protected static FSDataInputStream forceSecureOpenFSDataInputStream( File file, String expectedOwner, String expectedGroup) throws IOException { final FSDataInputStream in = rawFilesystem.open(new Path(file.getAbsolutePath())); boolean success = false; try { Stat stat = NativeIO.POSIX.getFstat(in.getFileDescriptor()); checkStat(file, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup); success = true; return in; } finally { if (!success) { in.close(); } } }
/** * Same as openForRead() except that it will run even if security is off. * This is used by unit tests. */ @VisibleForTesting protected static FileInputStream forceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) throws IOException { FileInputStream fis = new FileInputStream(f); boolean success = false; try { Stat stat = NativeIO.POSIX.getFstat(fis.getFD()); checkStat(f, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup); success = true; return fis; } finally { if (!success) { fis.close(); } } }