boolean process = (filter == null) || filter.accept(directory, ingestFile.getName()); if (ingestFile.isFile() && process) { FileUtils.deleteFile(ingestFile, logger, 3); FileUtils.deleteFilesInDirectory(ingestFile, filter, logger, recurse, deleteEmptyDirectories); if (deleteEmptyDirectories && ingestFile.list().length == 0) { FileUtils.deleteFile(ingestFile, logger, 3);
FileUtils.ensureDirectoryExistAndCanReadAndWrite(frameworkWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(extensionsWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(docsWorkingDir); FileUtils.ensureDirectoryExistAndCanRead(narDir); for (final File unpackedNar : frameworkWorkingDirContents) { if (!unpackedFramework.equals(unpackedNar)) { FileUtils.deleteFile(unpackedNar, true); for (final File unpackedNar : extensionsWorkingDirContents) { if (!unpackedExtensions.contains(unpackedNar)) { FileUtils.deleteFile(unpackedNar, true); if (docsFiles != null) { for (final File file : docsFiles) { FileUtils.deleteFile(file, true);
public static void deleteFile(final File file, final boolean recurse) throws IOException { final File[] list = file.listFiles(); if (file.isDirectory() && recurse && list != null) { FileUtils.deleteFiles(Arrays.asList(list), recurse); } //now delete the file itself regardless of whether it is plain file or a directory if (!FileUtils.deleteFile(file, null, 5)) { throw new IOException("Unable to delete " + file.getAbsolutePath()); } }
/** * Deletes given files. * * @param files to delete * @param recurse will recurse * @throws IOException if issues deleting files */ public static void deleteFiles(final Collection<File> files, final boolean recurse) throws IOException { for (final File file : files) { FileUtils.deleteFile(file, recurse); } }
/** * Deletes all files (not directories..) in the given directory (non * recursive) that match the given filename filter. If any file cannot be * deleted then this is printed at warn to the given logger. * * @param directory to delete contents of * @param filter if null then no filter is used * @param logger to notify * @throws IOException if abstract pathname does not denote a directory, or * if an I/O error occurs */ public static void deleteFilesInDirectory(final File directory, final FilenameFilter filter, final Logger logger) throws IOException { FileUtils.deleteFilesInDirectory(directory, filter, logger, false); }
@Deprecated public static void ensureDirectoryExistAndCanAccess(final File dir) throws IOException { ensureDirectoryExistAndCanReadAndWrite(dir); }
isGone = file.delete() || !file.exists(); if (!isGone && (effectiveAttempts - i) > 1) { FileUtils.sleepQuietly(MILLIS_BETWEEN_ATTEMPTS);
/** * Unpacks the NAR to the specified directory. Creates a checksum file that * used to determine if future expansion is necessary. * * @param workingDirectory * the root directory to which the NAR should be unpacked. * @throws IOException * if the NAR could not be unpacked. */ private static void unpack(final File nar, final File workingDirectory, final byte[] hash) throws IOException { try (JarFile jarFile = new JarFile(nar)) { Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanAccess(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
/** * Deletes the given file. If the given file exists but could not be deleted * this will be printed as a warning to the given logger * * @param file to delete * @param logger to notify * @return true if deleted */ public static boolean deleteFile(final File file, final Logger logger) { return FileUtils.deleteFile(file, logger, 1); }
/** * Deletes all files (not directories) in the given directory (recursive) * that match the given filename filter. If any file cannot be deleted then * this is printed at warn to the given logger. * * @param directory to delete contents of * @param filter if null then no filter is used * @param logger to notify * @param recurse true if should recurse * @throws IOException if abstract pathname does not denote a directory, or * if an I/O error occurs */ public static void deleteFilesInDirectory(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse) throws IOException { FileUtils.deleteFilesInDirectory(directory, filter, logger, recurse, false); }
/** * Unpacks the NAR to the specified directory. Creates a checksum file that * used to determine if future expansion is necessary. * * @param workingDirectory the root directory to which the NAR should be unpacked. * @throws IOException if the NAR could not be unpacked. */ private static void unpack(final File nar, final File workingDirectory, final byte[] hash) throws IOException { try (JarFile jarFile = new JarFile(nar)) { Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); if(name.contains("META-INF/bundled-dependencies")){ name = name.replace("META-INF/bundled-dependencies", "NAR-INF/bundled-dependencies"); } File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanReadAndWrite(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
isGone = file.delete() || !file.exists(); if (!isGone && (effectiveAttempts - i) > 1) { FileUtils.sleepQuietly(MILLIS_BETWEEN_ATTEMPTS);
/** * Unpacks the NAR to the specified directory. Creates a checksum file that * used to determine if future expansion is necessary. * * @param workingDirectory * the root directory to which the NAR should be unpacked. * @throws IOException * if the NAR could not be unpacked. */ private static void unpack(final File nar, final File workingDirectory, final byte[] hash) throws IOException { try (JarFile jarFile = new JarFile(nar)) { Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanAccess(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
FileUtils.deleteFilesInDirectory(webWorkingDir, null, LOGGER, true, true); FileUtils.deleteFile(webWorkingDir, LOGGER, 3);
FileUtils.ensureDirectoryExistAndCanReadAndWrite(frameworkWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(extensionsWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(docsWorkingDir); FileUtils.ensureDirectoryExistAndCanRead(narDir); for (final File unpackedNar : frameworkWorkingDirContents) { if (!unpackedFramework.equals(unpackedNar)) { FileUtils.deleteFile(unpackedNar, true); for (final File unpackedNar : extensionsWorkingDirContents) { if (!unpackedExtensions.contains(unpackedNar)) { FileUtils.deleteFile(unpackedNar, true); if (docsFiles != null) { for (final File file : docsFiles) { FileUtils.deleteFile(file, true);
final File workingHashFile = new File(narWorkingDirectory, HASH_FILENAME); if (!workingHashFile.exists()) { FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5); } else { if (!Arrays.equals(hashFileContents, narMd5)) { logger.info("Contents of nar {} have changed. Reloading.", new Object[] { nar.getAbsolutePath() }); FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5);
public static void deleteFile(final File file, final boolean recurse) throws IOException { final File[] list = file.listFiles(); if (file.isDirectory() && recurse && list != null) { FileUtils.deleteFiles(Arrays.asList(list), recurse); } //now delete the file itself regardless of whether it is plain file or a directory if (!FileUtils.deleteFile(file, null, 5)) { throw new IOException("Unable to delete " + file.getAbsolutePath()); } }
/** * Deletes all files (not directories..) in the given directory (non * recursive) that match the given filename filter. If any file cannot be * deleted then this is printed at warn to the given logger. * * @param directory to delete contents of * @param filter if null then no filter is used * @param logger to notify * @throws IOException if abstract pathname does not denote a directory, or * if an I/O error occurs */ public static void deleteFilesInDirectory(final File directory, final FilenameFilter filter, final Logger logger) throws IOException { FileUtils.deleteFilesInDirectory(directory, filter, logger, false); }
public synchronized void start() throws IOException { if (started) { return; } FileUtils.ensureDirectoryExistAndCanReadAndWrite(autoLoadDir); final WatchService watcher = FileSystems.getDefault().newWatchService(); final Path autoLoadPath = autoLoadDir.toPath(); autoLoadPath.register(watcher, StandardWatchEventKinds.ENTRY_CREATE); narAutoLoaderTask = new NarAutoLoaderTask.Builder() .autoLoadPath(autoLoadPath) .watchService(watcher) .pollIntervalMillis(POLL_INTERVAL_MS) .narLoader(narLoader) .build(); LOGGER.info("Starting NAR Auto-Loader for directory {} ...", new Object[]{autoLoadPath}); final Thread thread = new Thread(narAutoLoaderTask); thread.setName("NAR Auto-Loader"); thread.setDaemon(true); thread.start(); LOGGER.info("NAR Auto-Loader started"); started = true; }
isGone = file.delete() || !file.exists(); if (!isGone && (effectiveAttempts - i) > 1) { FileUtils.sleepQuietly(MILLIS_BETWEEN_ATTEMPTS);