Skip to content

Commit

Permalink
Skip registration for files and ignore files with insufficient rights (
Browse files Browse the repository at this point in the history
…#15)

Currently the registration fails silently if the dataset to register
is not wrapped in a directory.

Also, the dataset registration fails, when the application has not sufficient rights to execute and write to the dataset folder (e.g. wrong access group, etc).


# Co-authored-by: KochTobi <tobias.koch@qbic.uni-tuebingen.de>
  • Loading branch information
sven1103 authored May 29, 2024
1 parent 1f5b555 commit d3ae472
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main/java/life/qbic/data/processing/scanner/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,36 @@ public void run() {
private List<RegistrationRequest> detectDataForRegistration() {
return userProcessDirectories.parallelStream()
.map(Path::toFile)
.filter(this::matchesAccessRightsCriteria)
.filter(this::matchesRegistrationCriteria)
.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 boolean matchesRegistrationCriteria(File file) {
if (file.isHidden()) {
return false;
}
return file.isDirectory();
}

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())
.map(file -> createRequest(file, userDirectory)).toList();
return Arrays.stream(files).map(file -> createRequest(file, userDirectory)).toList();
}

private RegistrationRequest createRequest(File file, Path userDirectory) {
Expand Down

0 comments on commit d3ae472

Please sign in to comment.