Skip to content

Commit 6ea9ae7

Browse files
committed
Re-download empty structure or chemical component structures
Files less than 40 bytes are deleted to allow for gzip headers. This addresses #703
1 parent b207d34 commit 6ea9ae7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public static enum FetchBehavior {
127127

128128
protected static final String lineSplit = System.getProperty("file.separator");
129129

130+
/** Minimum size for a valid file, in bytes */
131+
public static final long MIN_PDB_FILE_SIZE = 40;
132+
130133
private File path;
131134
private List<String> extensions;
132135

@@ -687,6 +690,14 @@ public File getLocalFile(String pdbId) {
687690
for(String ex : getExtensions() ){
688691
File f = new File(searchdir,prefix + pdbId.toLowerCase() + ex) ;
689692
if ( f.exists()) {
693+
// delete files that are too short to have contents
694+
if( f.length() < MIN_PDB_FILE_SIZE ) {
695+
boolean success = f.delete();
696+
if( ! success) {
697+
return null;
698+
}
699+
assert(!f.exists());
700+
}
690701
return f;
691702
}
692703
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.biojava.nbio.core.util.InputStreamProvider;
4343
import org.biojava.nbio.structure.align.util.HTTPConnectionTools;
4444
import org.biojava.nbio.structure.align.util.UserConfiguration;
45+
import org.biojava.nbio.structure.io.LocalPDBDirectory;
4546
import org.biojava.nbio.structure.io.mmcif.model.ChemComp;
4647
import org.slf4j.Logger;
4748
import org.slf4j.LoggerFactory;
@@ -344,6 +345,12 @@ private static boolean fileExists(String recordName){
344345

345346
File f = new File(fileName);
346347

348+
// delete files that are too short to have contents
349+
if( f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE ) {
350+
f.delete();
351+
return false;
352+
}
353+
347354
return f.exists();
348355

349356
}

0 commit comments

Comments
 (0)