Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip registration for files and ignore files with insufficient rights #15

Merged
merged 7 commits into from
May 29, 2024
15 changes: 14 additions & 1 deletion src/main/java/life/qbic/data/processing/scanner/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,28 @@ public void run() {
private List<RegistrationRequest> detectDataForRegistration() {
return userProcessDirectories.parallelStream()
.map(Path::toFile)
.filter(this::matchesAccessRightsCriteria)
.map(file -> createRequests(file.listFiles(), file.toPath())).flatMap(
Collection::stream).toList();
}

private boolean matchesAccessRightsCriteria(File file) {
if (!file.canWrite()) {
log.error("Cannot write to file '{}'", file);
return false;
}
if (!file.canExecute()) {
log.error("Cannot execute file '{}'", file);
return false;
}
return true;
}

private List<RegistrationRequest> createRequests(File[] files, Path userDirectory) {
if (files == null || files.length == 0) {
return new ArrayList<>();
}
return Arrays.stream(files).filter(file -> !file.isHidden())
return Arrays.stream(files).filter(file -> !file.isHidden()).filter(File::isDirectory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that the filtering for directories should take place earlier. In the detectDataForRegistration there is a variable userProcessDirectories containing both files that are and file that are not directories?
Why is the check in line 74 not sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

I added another filter method and apply all filters before the createRequest method, since it violates the definition of a function.

.map(file -> createRequest(file, userDirectory)).toList();
}

Expand Down
Loading