Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnaohara committed May 1, 2024
1 parent 0b26b15 commit cef23cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,11 @@ public void analyze(List<DataPointDAO> dataPoints, JsonNode configuration, Consu
);
} finally {
if (tmpFiles != null) {
cleanupTmpFiles(tmpFiles);
tmpFiles.cleanup();
}
}
}

protected void cleanupTmpFiles(TmpFiles tmpFiles) {
if( tmpFiles.tmpdir.exists() ) {
clearDir(tmpFiles.tmpdir);
} else {
log.debugf("Trying to cleanup temp files, but they do not exist!");
}
}


private void clearDir(File dir){
Arrays.stream(dir.listFiles()).forEach(file -> {
if ( file.isDirectory() ){
clearDir(file);
}
file.delete();
});
if(!dir.delete()){
log.errorf("Failed to cleanup up temporary files: %s", dir.getAbsolutePath());
}
}

protected void processChangePoints(Function<Integer, Optional<DataPointDAO>> changePointSupplier, Consumer<ChangeDAO> changeConsumer, TmpFiles tmpFiles, Instant sinceInstance) {
String command = "hunter analyze horreum --since '" + sinceInstance.toString() + "'";
Expand Down Expand Up @@ -258,6 +238,25 @@ public TmpFiles() throws IOException {
}

}
protected void cleanup() {
if( tmpdir.exists() ) {
clearDir(tmpdir);
} else {
log.debugf("Trying to cleanup temp files, but they do not exist!");
}
}

private void clearDir(File dir){
Arrays.stream(dir.listFiles()).forEach(file -> {
if ( file.isDirectory() ){
clearDir(file);
}
file.delete();
});
if(!dir.delete()){
log.errorf("Failed to cleanup up temporary files: %s", dir.getAbsolutePath());
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ private void runChangeDetection(VariableDAO variable, JsonNode fingerprint, bool
});
} catch (ChangeDetectionException e) {
new ChangeDetectionLogDAO(variable, fingerprint, PersistentLogDAO.ERROR, e.getLocalizedMessage()).persist();
throw new RuntimeException(e);
log.error("An error occurred while running change detection!", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void testFileStructures() {

assertFalse(valid);

tmpFiles.cleanup();

//todo:: cleanup temp files
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public void testDetectedChangePoints(){

assertEquals(1535410, changePoints.get(0).dataset.id);

model.cleanupTmpFiles(tmpFiles);
tmpFiles.cleanup();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit cef23cf

Please sign in to comment.