use of java.nio.file.FileVisitOption in project lucene-solr by apache.
the class CorePropertiesLocator method discover.
@Override
public List<CoreDescriptor> discover(final CoreContainer cc) {
logger.debug("Looking for core definitions underneath {}", rootDirectory);
final List<CoreDescriptor> cds = Lists.newArrayList();
try {
Set<FileVisitOption> options = new HashSet<>();
options.add(FileVisitOption.FOLLOW_LINKS);
final int maxDepth = 256;
Files.walkFileTree(this.rootDirectory, options, maxDepth, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().equals(PROPERTIES_FILENAME)) {
CoreDescriptor cd = buildCoreDescriptor(file, cc);
if (cd != null) {
logger.debug("Found core {} in {}", cd.getName(), cd.getInstanceDir());
cds.add(cd);
}
return FileVisitResult.SKIP_SIBLINGS;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
// otherwise, log a warning and continue to try and load other cores
if (file.equals(rootDirectory)) {
logger.error("Error reading core root directory {}: {}", file, exc);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading core root directory");
}
logger.warn("Error visiting {}: {}", file, exc);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Couldn't walk file tree under " + this.rootDirectory, e);
}
logger.info("Found {} core definitions underneath {}", cds.size(), rootDirectory);
if (cds.size() > 0) {
logger.info("Cores are: {}", cds.stream().map(CoreDescriptor::getName).collect(Collectors.toList()));
}
return cds;
}
use of java.nio.file.FileVisitOption in project raml-module-builder by folio-org.
the class RamlDirCopier method copy.
/**
* Copy a RAML directory tree to a target directory tree and
* dereference all $ref references of all .json and .schema files.
* It does not delete any existing files or directories at target,
* but a file may get overwritten.
*
* @param sourceDir directory tree to copy
* @param targetDir target directory
* @throws IOException on read or write error
*/
public static void copy(Path sourceDir, Path targetDir) throws IOException {
File targetFile = targetDir.toFile();
if (!targetFile.isDirectory()) {
targetFile.mkdirs();
}
Set<FileVisitOption> options = Collections.emptySet();
RamlDirCopier ramlDirCopier = new RamlDirCopier(sourceDir, targetDir);
Files.walkFileTree(sourceDir, options, Integer.MAX_VALUE, ramlDirCopier.fileVisitor);
}
use of java.nio.file.FileVisitOption in project bw-calendar-engine by Bedework.
the class Restorer method restoreLocations.
protected void restoreLocations() throws CalFacadeException {
try {
final Path p = openDir(Defs.locationsDirName);
if (p == null) {
return;
}
final DirRestore<BwLocation> dirRestore = new DirRestore<>(p, restoreLoc);
final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(p, opts, Integer.MAX_VALUE, dirRestore);
} catch (final IOException ie) {
throw new CalFacadeException(ie);
} finally {
popPath();
}
}
use of java.nio.file.FileVisitOption in project bw-calendar-engine by Bedework.
the class Restorer method restoreCollections.
protected void restoreCollections(final Path p) throws CalFacadeException {
try {
final DirRestore<BwCalendar> colRestore = new DirRestore<>(p, restoreCol);
final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(p, opts, Integer.MAX_VALUE, colRestore);
} catch (final IOException ie) {
throw new CalFacadeException(ie);
} finally {
popPath();
}
}
use of java.nio.file.FileVisitOption in project embulk by embulk.
the class LocalFileInputPlugin method listFiles.
public List<String> listFiles(PluginTask task) {
Path pathPrefix = Paths.get(task.getPathPrefix()).normalize();
final Path directory;
final String fileNamePrefix;
if (Files.isDirectory(pathPrefix)) {
directory = pathPrefix;
fileNamePrefix = "";
} else {
fileNamePrefix = pathPrefix.getFileName().toString();
Path d = pathPrefix.getParent();
directory = (d == null ? CURRENT_DIR : d);
}
final ImmutableList.Builder<String> builder = ImmutableList.builder();
final String lastPath = task.getLastPath().orNull();
try {
log.info("Listing local files at directory '{}' filtering filename by prefix '{}'", directory.equals(CURRENT_DIR) ? "." : directory.toString(), fileNamePrefix);
int maxDepth = Integer.MAX_VALUE;
Set<FileVisitOption> opts;
if (task.getFollowSymlinks()) {
opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
} else {
opts = EnumSet.noneOf(FileVisitOption.class);
log.info("\"follow_symlinks\" is set false. Note that symbolic links to directories are skipped.");
}
Files.walkFileTree(directory, opts, maxDepth, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) {
if (path.equals(directory)) {
return FileVisitResult.CONTINUE;
} else if (lastPath != null && path.toString().compareTo(lastPath) <= 0) {
return FileVisitResult.SKIP_SUBTREE;
} else {
Path parent = path.getParent();
if (parent == null) {
parent = CURRENT_DIR;
}
if (parent.equals(directory)) {
if (path.getFileName().toString().startsWith(fileNamePrefix)) {
return FileVisitResult.CONTINUE;
} else {
return FileVisitResult.SKIP_SUBTREE;
}
} else {
return FileVisitResult.CONTINUE;
}
}
}
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
try {
// Symbolic links to directories are explicitly skipped here by checking with |Path#toReadlPath|.
if (Files.isDirectory(path.toRealPath())) {
return FileVisitResult.CONTINUE;
}
} catch (IOException ex) {
throw new RuntimeException("Can't resolve symbolic link", ex);
}
if (lastPath != null && path.toString().compareTo(lastPath) <= 0) {
return FileVisitResult.CONTINUE;
} else {
Path parent = path.getParent();
if (parent == null) {
parent = CURRENT_DIR;
}
if (parent.equals(directory)) {
if (path.getFileName().toString().startsWith(fileNamePrefix)) {
builder.add(path.toString());
return FileVisitResult.CONTINUE;
}
} else {
builder.add(path.toString());
}
return FileVisitResult.CONTINUE;
}
}
});
} catch (IOException ex) {
throw new RuntimeException(String.format("Failed get a list of local files at '%s'", directory), ex);
}
return builder.build();
}
Aggregations