SimpleStagingService implements StagingService { @Override public void deleteTree(String path) throws IOException { File treeToDelete = new File(stagingDir, path).getCanonicalFile(); String stagingDirPath = stagingDir.getPath(); String treeToDeletePath = treeToDelete.getPath(); if (treeToDeletePath.startsWith(stagingDirPath) && treeToDeletePath.length() > stagingDirPath.length()) { FileUtils.deleteTree(treeToDelete); } else { throw new IOException("Illegal path: " + treeToDeletePath); } } SimpleStagingService(File stagingDir, int numParallelJobs); @Override File getStagingDir(); @Override void submitStaging(Staging staging); @Override void deleteTree(String path); @Override void close(); @Override void setProductionService(Observable productionService); @Override Observable getProductionService();  }
@Test public void testDeleteTree() throws IOException { SimpleStagingService stagingService = new SimpleStagingService(new File("/foo/bar/buz"), 1); stagingService.deleteTree("bas"); try { stagingService.deleteTree("../.."); fail("IOE expected, because canonical names do not match"); } catch (IOException e) { } }