-
Notifications
You must be signed in to change notification settings - Fork 395
Fix #703: Recover from empty structure files in PDB_CACHE_DIR #774
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
Changes from 1 commit
5c1a335
4785d57
c3cec91
b207d34
6ea9ae7
62fb2a4
f5b325f
13f267c
c1c3c30
0c10a2e
08ab3e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Files less than 40 bytes are deleted to allow for gzip headers. This addresses #703
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,9 @@ public static enum FetchBehavior { | |
|
|
||
| protected static final String lineSplit = System.getProperty("file.separator"); | ||
|
|
||
| /** Minimum size for a valid file, in bytes */ | ||
| public static final long MIN_PDB_FILE_SIZE = 40; | ||
|
|
||
| private File path; | ||
| private List<String> extensions; | ||
|
|
||
|
|
@@ -687,6 +690,14 @@ public File getLocalFile(String pdbId) { | |
| for(String ex : getExtensions() ){ | ||
| File f = new File(searchdir,prefix + pdbId.toLowerCase() + ex) ; | ||
| if ( f.exists()) { | ||
| // delete files that are too short to have contents | ||
| if( f.length() < MIN_PDB_FILE_SIZE ) { | ||
| boolean success = f.delete(); | ||
| if( ! success) { | ||
| return null; | ||
| } | ||
| assert(!f.exists()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather log a warning here. Assert is going to be ignored in normal situations
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's intended. If the delete was successful then the file will not exist. This is just a sanity check during development to make sure delete() wasn't asynchronous or something. |
||
| } | ||
| return f; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import org.biojava.nbio.core.util.InputStreamProvider; | ||
| import org.biojava.nbio.structure.align.util.HTTPConnectionTools; | ||
| import org.biojava.nbio.structure.align.util.UserConfiguration; | ||
| import org.biojava.nbio.structure.io.LocalPDBDirectory; | ||
| import org.biojava.nbio.structure.io.mmcif.model.ChemComp; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -344,6 +345,12 @@ private static boolean fileExists(String recordName){ | |
|
|
||
| File f = new File(fileName); | ||
|
|
||
| // delete files that are too short to have contents | ||
| if( f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE ) { | ||
| f.delete(); | ||
| return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the file fails to be deleted, this won't work as expected. I think the fail to delete case should throw an IOException
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't check the status because the delete isn't really necessary here. If this method returns false then we re-download the file and move it on top of the old one. I just added the delete defensively. |
||
| } | ||
|
|
||
| return f.exists(); | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this rather throw an exception (perhaps IOException)? I don't see how can this null be handled if file can't be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to
Files.deletewhich throws the exception