private void deleteTempDir(File dir) { IOUtils.recursiveDeleteDir(dir); }
/** * Recursive deletion of directories */ public static boolean recursiveDeleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (String child : children) { boolean success = recursiveDeleteDir(new File(dir, child)); if (!success) return false; } } // The directory is now empty so delete it return dir.delete(); }
/** * Shuts down all services. */ @Override public void close() { container.close(); if (deletePathWhenClosing) IOUtils.recursiveDeleteDir(path.toFile()); }
private static void moveFileToDestination(File tempFile, File destination) { try { Files.move(tempFile.toPath(), destination.toPath()); log.log(LogLevel.DEBUG, () -> "File moved from " + tempFile.getAbsolutePath()+ " to " + destination.getAbsolutePath()); } catch (FileAlreadyExistsException e) { // Don't fail if it already exists (we might get the file from several config servers when retrying, servers are down etc. // so it might be written already). Delete temp file/dir in that case, to avoid filling the disk. log.log(LogLevel.DEBUG, () -> "File '" + destination.getAbsolutePath() + "' already exists, continuing: " + e.getMessage()); try { if (tempFile.isDirectory()) IOUtils.recursiveDeleteDir(tempFile); else Files.delete(tempFile.toPath()); } catch (IOException ioe) { log.log(LogLevel.WARNING, "Failed deleting file/dir " + tempFile); } } catch (IOException e) { String message = "Failed moving file '" + tempFile.getAbsolutePath() + "' to '" + destination.getAbsolutePath() + "'"; log.log(LogLevel.ERROR, message, e); throw new RuntimeException(message, e); } }
/** * Closes the current JDisc. */ @Override public void close() { try { testDriver.close(); } finally { Container.resetInstance(); if (deletePathWhenClosing) IOUtils.recursiveDeleteDir(path.toFile()); } }
private static <T> T withTempDir(ThrowingFunction<File, T> f) throws Exception { File tmpDir = createTempDir(); try { return f.apply(tmpDir); } finally { IOUtils.recursiveDeleteDir(tmpDir); } }
@Override public ApplicationPackage preprocess(Zone zone, DeployLogger logger) throws IOException, TransformerException, ParserConfigurationException, SAXException { IOUtils.recursiveDeleteDir(preprocessedDir); IOUtils.copyDirectory(appDir, preprocessedDir, -1, (dir, name) -> ! name.equals(preprocessed) && ! name.equals(SERVICES) && ! name.equals(HOSTS) && ! name.equals(CONFIG_DEFINITIONS_DIR)); preprocessXML(new File(preprocessedDir, SERVICES), getServicesFile(), zone); if (getHostsFile().exists()) { preprocessXML(new File(preprocessedDir, HOSTS), getHostsFile(), zone); } FilesApplicationPackage preprocessed = FilesApplicationPackage.fromFile(preprocessedDir, includeSourceFiles); preprocessed.copyUserDefsIntoApplication(); return preprocessed; }
public static String getSystemPackages() { File cache; try { cache = Files.createTempDirectory("felix-cache").toAbsolutePath().toFile(); } catch (IOException e) { throw new RuntimeException("Could not create temp bundle-cache.", e); } Framework framework = new Felix(felixCacheParams(cache.getAbsolutePath())); try { framework.init(); framework.start(); return framework.getHeaders().get(Constants.EXPORT_PACKAGE); } catch (BundleException e) { throw new RuntimeException("Failed retrieving exported system packages. ", e); } finally { try { framework.stop(); framework.waitForStop(10000); } catch (BundleException | InterruptedException e) { log.warning("Failed to stop Felix framework:\n" + Exceptions.toMessageString(e)); } if (! IOUtils.recursiveDeleteDir(cache)) { log.warning("Failed to delete temp dir, must be deleted manually: " + cache.getAbsolutePath()); } } }
/** * Initializes the validator by using the given file as schema file * * @param vespaVersion the version of Vespa we should validate against */ public SchemaValidators(Version vespaVersion) { File schemaDir = null; try { schemaDir = saveSchemasFromJar(new File(SchemaValidators.schemaDirBase), vespaVersion); servicesXmlValidator = createValidator(schemaDir, servicesXmlSchemaName); hostsXmlValidator = createValidator(schemaDir, hostsXmlSchemaName); deploymentXmlValidator = createValidator(schemaDir, deploymentXmlSchemaName); validationOverridesXmlValidator = createValidator(schemaDir, validationOverridesXmlSchemaName); containerIncludeXmlValidator = createValidator(schemaDir, containerIncludeXmlSchemaName); routingStandaloneXmlValidator = createValidator(schemaDir, routingStandaloneXmlSchemaName); } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (Exception e) { throw e; } finally { if (schemaDir != null) IOUtils.recursiveDeleteDir(schemaDir); } }