Skip to content

Commit

Permalink
Missing check when write to "unwriteable" log-file (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
claeis committed Mar 4, 2020
1 parent 34ca82f commit 8e5032c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ configurations {
//}

dependencies {
compile group: 'ch.ehi', name: 'ehibasics', version: '1.3.0+'
compile group: 'ch.interlis', name: 'iox-ili', version: '1.20.17'
compile group: 'ch.interlis', name: 'ili2c-tool', version: "5.0.6"
compile group: 'ch.interlis', name: 'ili2c-core', version: "5.0.6"
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
LATEST VERSION
-----------------------------
- Missing check when write to "unwriteable" log-file (#228)
- ehibasics-1.3.0-SNAPSHOT

ilivalidator 1.11.4 (2020-03-02)
-----------------------------
Expand Down
37 changes: 32 additions & 5 deletions src/org/interlis2/validator/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,34 @@ public boolean validate(
try{
// setup logging of validation results
if(logFilename!=null){
logfile=new FileLogger(new java.io.File(logFilename));
EhiLogger.getInstance().addListener(logfile);
File f=new java.io.File(logFilename);
try {
if(isWriteable(f)) {
logfile=new FileLogger(f);
EhiLogger.getInstance().addListener(logfile);
}else {
EhiLogger.logError("failed to write to logfile <"+f.getPath()+">");
return false;
}
} catch (IOException e) {
EhiLogger.logError("failed to write to logfile <"+f.getPath()+">",e);
return false;
}
}
if(xtflogFilename!=null){
xtflog=new XtfErrorsLogger(new java.io.File(xtflogFilename), Main.APP_NAME+"-"+Main.getVersion());
EhiLogger.getInstance().addListener(xtflog);
File f=new java.io.File(xtflogFilename);
try {
if(isWriteable(f)) {
xtflog=new XtfErrorsLogger(f, Main.APP_NAME+"-"+Main.getVersion());
EhiLogger.getInstance().addListener(xtflog);
}else {
EhiLogger.logError("failed to write to logfile <"+f.getPath()+">");
return false;
}
} catch (IOException e) {
EhiLogger.logError("failed to write to logfile <"+f.getPath()+">",e);
return false;
}
}
if(!TRUE.equals(settings.getValue(SETTING_DISABLE_STD_LOGGER))) {
logStderr=new StdLogger(logFilename);
Expand Down Expand Up @@ -297,7 +319,12 @@ public boolean validate(
return ret;
}

private boolean getVersionControlFormConfigFile(String configFilename) throws IOException {
private static boolean isWriteable(File f) throws IOException {
f.createNewFile();
return f.canWrite();
}

private boolean getVersionControlFormConfigFile(String configFilename) throws IOException {
if (configFilename != null) {
ValidationConfig modelConfig=new ValidationConfig();
modelConfig.mergeConfigFile(new File(configFilename));
Expand Down

0 comments on commit 8e5032c

Please sign in to comment.