public static boolean hasContent(FileSystem fs, Path path) throws IOException { if (!fs.isDirectory(path)) { return true; } boolean content = false; for (FileStatus fileStatus : fs.listStatus(path)) { content = content || hasContent(fs, fileStatus.getPath()); if (content) { break; } } return content; }
"This version corresponds to the non deletable version. Won't delete the data but metadata will be dropped for the version " + completeName); } else if (HadoopUtils.hasContent(this.fs, versionLocation)) { if (this.simulate) { log.info("Simulate is set to true. Won't delete the partition " + completeName);
/** * A version is called restorable if it can be used to restore dataset. * * If a version is pointing to same data location as of the dataset, then it can't be used for restoring * If a version is pointing to an empty data location, then it can't be used for restoring */ private boolean isRestorable(HivePartitionDataset dataset, HivePartitionVersion version) throws IOException { if (version.getLocation().toString().equalsIgnoreCase(dataset.getLocation().toString())) { return false; } FileSystem fs = ProxyUtils.getOwnerFs(new State(this.state), version.getOwner()); if (!HadoopUtils.hasContent(fs, version.getLocation())) { return false; } return true; }
/** * @param dataset to restore * @return dataset to restore with */ public HivePartitionDataset getDatasetToRestore(HivePartitionDataset dataset) throws IOException { Preconditions.checkArgument(this.state.contains(ComplianceConfigurationKeys.DATASET_TO_RESTORE), "Missing required property " + ComplianceConfigurationKeys.DATASET_TO_RESTORE); HivePartitionDataset hivePartitionDataset = HivePartitionFinder.findDataset(this.state.getProp(ComplianceConfigurationKeys.DATASET_TO_RESTORE), this.state); FileSystem fs = ProxyUtils.getOwnerFs(new State(this.state), hivePartitionDataset.getOwner()); Preconditions.checkArgument(HadoopUtils.hasContent(fs, hivePartitionDataset.getLocation()), "Dataset to restore doesn't have any data"); return hivePartitionDataset; } }
public static boolean hasContent(FileSystem fs, Path path) throws IOException { if (!fs.isDirectory(path)) { return true; } boolean content = false; for (FileStatus fileStatus : fs.listStatus(path)) { content = content || hasContent(fs, fileStatus.getPath()); if (content) { break; } } return content; }