Skip to content
Snippets Groups Projects
Commit e4913313 authored by gnaegi's avatar gnaegi
Browse files

OO-1054 implement system startup abort when UTF-8 filesystem is not available

parent 5093bf77
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ import org.olat.core.logging.OLog; ...@@ -47,6 +47,7 @@ import org.olat.core.logging.OLog;
import org.olat.core.logging.StartupException; import org.olat.core.logging.StartupException;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.i18n.I18nModule; import org.olat.core.util.i18n.I18nModule;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
...@@ -71,6 +72,7 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA ...@@ -71,6 +72,7 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA
private static String instanceId; private static String instanceId;
private static String userDataRoot; private static String userDataRoot;
private static String defaultCharset; private static String defaultCharset;
private static boolean enforceUtf8Filesystem;
private static Map<String, String> mailConfig = new HashMap<String, String>(6); private static Map<String, String> mailConfig = new HashMap<String, String>(6);
private static long timeOfServerStartup = System.currentTimeMillis(); private static long timeOfServerStartup = System.currentTimeMillis();
...@@ -375,6 +377,14 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA ...@@ -375,6 +377,14 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA
WebappHelper.defaultCharset = defaultCharset; WebappHelper.defaultCharset = defaultCharset;
} }
/**
* [spring]
* @param enforceUtf8Filesystem
*/
public void setEnforceUtf8Filesystem(boolean enforceUtf8Filesystem) {
WebappHelper.enforceUtf8Filesystem = enforceUtf8Filesystem;
}
/** /**
* key="mailhost" * key="mailhost"
* key="mailTimeout" * key="mailTimeout"
...@@ -432,13 +442,20 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA ...@@ -432,13 +442,20 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA
} else { } else {
// test failed // test failed
log.warn("No UTF-8 capable filesystem found! Could not read / write UTF-8 characters from / to filesystem! " log.warn("No UTF-8 capable filesystem found! Could not read / write UTF-8 characters from / to filesystem! "
+ "You probably misconfigured your system, try setting your LC_HOME variable to a correct value."); + "You probably misconfigured your system, try setting your LANG variable to a correct value.");
log.warn("Your current file encoding configuration: java.nio.charset.Charset.defaultCharset().name()::" log.warn("Your current file encoding configuration: java.nio.charset.Charset.defaultCharset().name()::"
+ java.nio.charset.Charset.defaultCharset().name() + " (the one used) and your system property file.encoding::" + java.nio.charset.Charset.defaultCharset().name() + " (the one used) and your system property file.encoding::"
+ System.getProperty("file.encoding") + " (the one configured)"); + System.getProperty("file.encoding") + " (the one configured)");
} }
// try to delete file anyway // try to delete file anyway
writeFile.delete(); writeFile.delete();
if (!foundUtf8File && WebappHelper.enforceUtf8Filesystem) {
throw new BeanInitializationException(
"System startup aborted to to file system missconfiguration. See previous warnings in logfile and fix your " +
"Java environment. This check can be disabled by setting enforce.utf8.filesystem=false, but be aware that the " +
"decision to use a certain encoding on the filesystem is a one-time decision. You can not cange to UTF-8 later!");
}
} }
/** /**
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
</map> </map>
</property> </property>
<property name="defaultCharset" value="${defaultcharset}" /> <property name="defaultCharset" value="${defaultcharset}" />
<property name="enforceUtf8Filesystem" value="${enforce.utf8.filesystem}" />
<property name="version" value="${build.version}" /> <property name="version" value="${build.version}" />
<property name="applicationName" value="${application.name}" /> <property name="applicationName" value="${application.name}" />
<property name="mobileContext" value="${mobile.context}" /> <property name="mobileContext" value="${mobile.context}" />
......
...@@ -82,10 +82,12 @@ fallbacklang.values=de,en ...@@ -82,10 +82,12 @@ fallbacklang.values=de,en
# ${userdata.dir}/system/configuration/org.olat.core.util.i18n.I18nModule.properties # ${userdata.dir}/system/configuration/org.olat.core.util.i18n.I18nModule.properties
enabledLanguages=en,de,fr,it,es enabledLanguages=en,de,fr,it,es
# determines the character set of files written to the filesystem # determines the character set of files written to the file system
# e.g.: US-ASCII, ISO-8859-1, UTF-8 # e.g.: US-ASCII, ISO-8859-1, UTF-8
defaultcharset=UTF-8 defaultcharset=UTF-8
# abort system startup when no UTF-8 capable file system is detected. In production this should be set to
# true to prevent accidental startup with another encoding which leads to a big data mess
enforce.utf8.filesystem=true
# global on/off config for back and resume # global on/off config for back and resume
history.back.enabled=true history.back.enabled=true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment