/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
/** * We read txn log files, if we fail we throw only if the user has specified * OnTxnErr.THROW, else we log an error and apply the txn log anyway */ void classifyFiles(File txnFile) { try (LogFile txn = LogFile.make(txnFile)) { readTxnLog(txn); classifyFiles(txn); files.put(txnFile, FileType.TXN_LOG); } }
public List<File> list() { try { return innerList(); } catch (Throwable t) { throw new RuntimeException(String.format("Failed to list files in %s", folder), t); } }
setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; if (allFilesPresent(oldFiles)) setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; readTxnLog(txnFile); setTemporary(txnFile, oldFiles.values(), newFiles.values()); return;
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; if (allFilesPresent(oldFiles)) setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; readTxnLog(txnFile); setTemporary(txnFile, oldFiles.values(), newFiles.values()); return;
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; if (allFilesPresent(oldFiles)) setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; readTxnLog(txnFile); setTemporary(txnFile, oldFiles.values(), newFiles.values()); return;
/** * We read txn log files, if we fail we throw only if the user has specified * OnTxnErr.THROW, else we log an error and apply the txn log anyway */ void classifyFiles(File txnFile) { try (LogFile txn = LogFile.make(txnFile)) { readTxnLog(txn); classifyFiles(txn); files.put(txnFile, FileType.TXN_LOG); } }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
public List<File> list() { try { return innerList(); } catch (Throwable t) { throw new RuntimeException(String.format("Failed to list files in %s", folder), t); } }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; if (allFilesPresent(oldFiles)) setTemporary(txnFile, oldFiles.values(), newFiles.values()); return; readTxnLog(txnFile); setTemporary(txnFile, oldFiles.values(), newFiles.values()); return;
/** * We read txn log files, if we fail we throw only if the user has specified * OnTxnErr.THROW, else we log an error and apply the txn log anyway */ void classifyFiles(File txnFile) { try (LogFile txn = LogFile.make(txnFile)) { readTxnLog(txn); classifyFiles(txn); files.put(txnFile, FileType.TXN_LOG); } }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
public List<File> list() { try { return innerList(); } catch (Throwable t) { throw new RuntimeException(String.format("Failed to list files in %s", folder), t); } }
List<File> innerList() throws Throwable { list(Files.newDirectoryStream(folder)) .stream() .filter((f) -> !LogFile.isLogFile(f)) .forEach((f) -> files.put(f, FileType.FINAL)); // Since many file systems are not atomic, we cannot be sure we have listed a consistent disk state // (Linux would permit this, but for simplicity we keep our behaviour the same across platforms) // so we must be careful to list txn log files AFTER every other file since these files are deleted last, // after all other files are removed list(Files.newDirectoryStream(folder, '*' + LogFile.EXT)) .stream() .filter(LogFile::isLogFile) .forEach(this::classifyFiles); // Finally we apply the user filter before returning our result return files.entrySet().stream() .filter((e) -> filter.apply(e.getKey(), e.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
/** * We read txn log files, if we fail we throw only if the user has specified * OnTxnErr.THROW, else we log an error and apply the txn log anyway */ void classifyFiles(File txnFile) { try (LogFile txn = LogFile.make(txnFile)) { readTxnLog(txn); classifyFiles(txn); files.put(txnFile, FileType.TXN_LOG); } }
/** * Get the files in the folder specified, provided that the filter returns true. * A filter is given each file and its type, and decides which files should be returned * and which should be discarded. To classify files into their type, we read transaction * log files. Should we fail to read these log files after a few times, we look at onTxnErr * to determine what to do. * * @param folder - the folder to scan * @param onTxnErr - how to handle a failure to read a txn log file * @param filter - A function that receives each file and its type, it should return true to have the file returned * @return - the list of files that were scanned and for which the filter returned true */ public static List<File> getFiles(Path folder, BiFunction<File, Directories.FileType, Boolean> filter, Directories.OnTxnErr onTxnErr) { return new LogAwareFileLister(folder, filter, onTxnErr).list(); }
public List<File> list() { try { return innerList(); } catch (Throwable t) { throw new RuntimeException(String.format("Failed to list files in %s", folder), t); } }