/** * Determines if the given workingDir is a subdirectory of the default working snapshot directory * @param workingDir a directory to check * @param conf configuration for the HBase cluster * @return true if the given workingDir is a subdirectory of the default working directory for * snapshots, false otherwise */ public static boolean isWithinDefaultWorkingDir(final Path workingDir, Configuration conf) { Path defaultWorkingDir = getDefaultWorkingSnapshotDir(new Path(conf.get(HConstants.HBASE_DIR))); return workingDir.equals(defaultWorkingDir) || isSubDirectoryOf(workingDir, defaultWorkingDir); }
@Test public void testIsSubDirectoryWorks() { Path rootDir = new Path("hdfs://root/.hbase-snapshot/"); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf(rootDir, rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://root/.hbase-snapshotdir"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://root/.hbase-snapshot"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://.hbase-snapshot"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://.hbase-snapshot/.tmp"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf(new Path("hdfs://root"), rootDir)); assertTrue(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://root/.hbase-snapshot/.tmp"), rootDir)); assertTrue(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("hdfs://root/.hbase-snapshot/.tmp/snapshot"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("s3://root/.hbase-snapshot/"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf(new Path("s3://root"), rootDir)); assertFalse(SnapshotDescriptionUtils.isSubDirectoryOf( new Path("s3://root/.hbase-snapshot/.tmp/snapshot"), rootDir)); }
this.rootDir = this.master.getMasterFileSystem().getRootDir(); this.workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir, conf); Preconditions.checkArgument(!SnapshotDescriptionUtils.isSubDirectoryOf(workingDir, rootDir) || SnapshotDescriptionUtils.isWithinDefaultWorkingDir(workingDir, conf), "The working directory " + workingDir + " cannot be in the root directory unless it is "