List of usage examples for org.apache.hadoop.fs FileStatus compareTo
@Override public int compareTo(Object o)
From source file:org.oclc.firefly.hadoop.backup.BackupUtils.java
License:Apache License
/** * Looks under the table directory in the filesystem for files with a '.tableinfo' prefix. Returns * reference to the 'latest' instance./*from w ww . j a va 2 s . co m*/ * * @param fs The filesytem where to look * @param tableDirPath the hdfs table directory * @return The 'current' tableinfo file. * @throws IOException If failed to read from file system */ public static FileStatus getTableInfoPath(final FileSystem fs, final Path tableDirPath) throws IOException { FileStatus ret = null; FileStatus[] status = FSUtils.listStatus(fs, tableDirPath, new PathFilter() { @Override public boolean accept(Path p) { // Accept any file that starts with TABLEINFO_NAME return p.getName().startsWith(FSTableDescriptors.TABLEINFO_NAME); } }); if (status != null && status.length > 0) { Arrays.sort(status, new Comparator<FileStatus>() { @Override public int compare(FileStatus left, FileStatus right) { return -left.compareTo(right); } }); if (status.length > 1) { // Clean away old versions of .tableinfo for (int i = 1; i < status.length; i++) { Path p = status[i].getPath(); // Clean up old versions if (!fs.delete(p, false)) { LOG.warn("Failed cleanup of " + status); } else { LOG.debug("Cleaned up old tableinfo file " + p); } } } ret = status[0]; } return ret; }