Fix hidden files showing up in TransformationRegistry (#3532)

Signed-off-by: Jan N. Klug <github@klug.nrw>
pull/3556/head
J-N-K 2023-04-15 09:11:03 +02:00 committed by GitHub
parent 3fc4a4c9d2
commit 5ca849ed88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 19 deletions

View File

@ -67,7 +67,8 @@ public class FileTransformationProvider implements WatchService.WatchEventListen
watchService.registerListener(this, transformationPath); watchService.registerListener(this, transformationPath);
// read initial contents // read initial contents
try (Stream<Path> files = Files.walk(transformationPath)) { try (Stream<Path> files = Files.walk(transformationPath)) {
files.filter(Files::isRegularFile).map(transformationPath::relativize).forEach(f -> processPath(CREATE, f)); files.filter(Files::isRegularFile).map(transformationPath::relativize)
.forEach(f -> processWatchEvent(CREATE, f));
} catch (IOException e) { } catch (IOException e) {
logger.warn("Could not list files in '{}', transformation configurations might be missing: {}", logger.warn("Could not list files in '{}', transformation configurations might be missing: {}",
transformationPath, e.getMessage()); transformationPath, e.getMessage());
@ -94,16 +95,18 @@ public class FileTransformationProvider implements WatchService.WatchEventListen
return transformationConfigurations.values(); return transformationConfigurations.values();
} }
private void processPath(WatchService.Kind kind, Path path) { @Override
public void processWatchEvent(WatchService.Kind kind, Path path) {
Path finalPath = transformationPath.resolve(path); Path finalPath = transformationPath.resolve(path);
try {
if (kind == DELETE) { if (kind == DELETE) {
Transformation oldElement = transformationConfigurations.remove(path); Transformation oldElement = transformationConfigurations.remove(path);
if (oldElement != null) { if (oldElement != null) {
logger.trace("Removed configuration from file '{}", path); logger.trace("Removed configuration from file '{}", path);
listeners.forEach(listener -> listener.removed(this, oldElement)); listeners.forEach(listener -> listener.removed(this, oldElement));
} }
} else if (Files.isRegularFile(finalPath) && ((kind == CREATE) || (kind == MODIFY))) { } else if (Files.isRegularFile(finalPath) && !Files.isHidden(finalPath)
try { && ((kind == CREATE) || (kind == MODIFY))) {
String fileName = path.getFileName().toString(); String fileName = path.getFileName().toString();
Matcher m = FILENAME_PATTERN.matcher(fileName); Matcher m = FILENAME_PATTERN.matcher(fileName);
if (!m.matches()) { if (!m.matches()) {
@ -131,16 +134,11 @@ public class FileTransformationProvider implements WatchService.WatchEventListen
logger.trace("Updated new configuration from file '{}'", path); logger.trace("Updated new configuration from file '{}'", path);
listeners.forEach(listener -> listener.updated(this, oldElement, newElement)); listeners.forEach(listener -> listener.updated(this, oldElement, newElement));
} }
} catch (IOException e) {
logger.warn("Skipping {} event for '{}' - failed to read content: {}", kind, path, e.getMessage());
}
} else { } else {
logger.trace("Skipping {} event for '{}' - not a regular file", kind, path); logger.trace("Skipping {} event for '{}' - not a regular file", kind, path);
} }
} catch (IOException e) {
logger.warn("Skipping {} event for '{}' - failed to process it: {}", kind, path, e.getMessage());
} }
@Override
public void processWatchEvent(WatchService.Kind kind, Path path) {
processPath(kind, path);
} }
} }