Skip to content

Commit

Permalink
Fix isThisType so that invalid *.db files are not picked up
Browse files Browse the repository at this point in the history
melissalinkert committed Nov 20, 2020

Verified

This commit was signed with the committer’s verified signature.
yijiasu-crypto Yijia Su
1 parent d8eb193 commit a730fe7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion components/formats-gpl/src/loci/formats/in/TecanReader.java
Original file line number Diff line number Diff line change
@@ -108,10 +108,30 @@ public TecanReader() {
domains = new String[] {FormatTools.HCS_DOMAIN};
datasetDescription =
"SQLite database, TIFF files, optional analysis output";
suffixSufficient = false;
}

// -- IFormatReader API methods --

/* @see loci.formats.IFormatReader#isThisType(String, boolean) */
@Override
public boolean isThisType(String name, boolean open) {
if (!checkSuffix(name, "db")) {
return false;
}
if (!open) {
return super.isThisType(name, open);
}
try {
Connection conn = openConnection(name);
findPlateDimensions(conn);
return true;
}
catch (Exception e) {
}
return false;
}

/* @see loci.formats.IFormatReader#getRequiredDirectories(String[]) */
@Override
public int getRequiredDirectories(String[] files)
@@ -370,13 +390,17 @@ protected void initFile(String id) throws FormatException, IOException {
}

private Connection openConnection() throws IOException {
return openConnection(getCurrentFile());
}

private Connection openConnection(String file) throws IOException {
Connection conn = null;
try {
// see https://github.com/xerial/sqlite-jdbc/issues/247
SQLiteConfig config = new SQLiteConfig();
config.setReadOnly(true);
conn = config.createConnection("jdbc:sqlite:" +
new Location(getCurrentFile()).getAbsolutePath());
new Location(file).getAbsolutePath());
}
catch (SQLException e) {
LOGGER.warn("Could not read from database");

0 comments on commit a730fe7

Please sign in to comment.