@Test public void testIsWithinWorkingDir() { Configuration conf = new Configuration(); conf.set(HConstants.HBASE_DIR, "hdfs://root/"); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://root/"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://root/.hbase-snapshotdir"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://root/.hbase-snapshot"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://.hbase-snapshot"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://.hbase-snapshot/.tmp"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir(new Path("hdfs://root"), conf)); assertTrue(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://root/.hbase-snapshot/.tmp"), conf)); assertTrue(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("hdfs://root/.hbase-snapshot/.tmp/snapshot"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("s3://root/.hbase-snapshot/"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir(new Path("s3://root"), conf)); assertFalse(SnapshotDescriptionUtils.isWithinDefaultWorkingDir( new Path("s3://root/.hbase-snapshot/.tmp/snapshot"), conf)); } }
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 " + "within the default working directory");