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

FileStitcher: do not use detected patterns that include missing files #3129

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions components/formats-bsd/src/loci/formats/FileStitcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package loci.formats;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -969,10 +970,28 @@ protected void initFile(String id) throws FormatException, IOException {

String[] patterns = findPatterns(id);
if (patterns.length == 0) patterns = new String[] {id};
externals = new ExternalSeries[patterns.length];

for (int i=0; i<externals.length; i++) {
externals[i] = new ExternalSeries(new FilePattern(patterns[i]));
// catching FileNotFoundException here and during setId below
// allows us to filter out patterns that include missing files
// the exception is caught instead of proactively checking for
// new Location(...).exists() so that patterns consisting of
// .fake files that do not exist on disk continue to be supported
List<ExternalSeries> validExternals = new ArrayList<ExternalSeries>();
for (int i=0; i<patterns.length; i++) {
try {
ExternalSeries e = new ExternalSeries(new FilePattern(patterns[i]));
validExternals.add(e);
}
catch (FileNotFoundException e) {
LOGGER.trace("Could not use pattern " + patterns[i], e);
}
}
if (validExternals.size() == 0) {
patterns = new String[] {id};
externals = new ExternalSeries[] {new ExternalSeries(new FilePattern(id))};
}
else {
externals = validExternals.toArray(new ExternalSeries[validExternals.size()]);
}
fp = new FilePattern(patterns[0]);

Expand All @@ -982,7 +1001,16 @@ protected void initFile(String id) throws FormatException, IOException {
if (!fp.isValid()) {
throw new FormatException("Invalid file pattern: " + fp.getPattern());
}
reader.setId(fp.getFiles()[0]);
try {
reader.setId(fp.getFiles()[0]);
}
catch (FileNotFoundException e) {
LOGGER.trace("Could not use pattern " + patterns[0], e);
patterns = new String[] {id};
fp = new FilePattern(id);
externals = new ExternalSeries[] {new ExternalSeries(fp)};
reader.setId(fp.getFiles()[0]);
}

String msg = " Please rename your files or disable file stitching.";
if (reader.getCoreMetadataList().size() > 1 && externals.length > 1) {
Expand Down