diff --git a/src/main/java/org/olat/core/util/WebappHelper.java b/src/main/java/org/olat/core/util/WebappHelper.java index 2b69d1d52c344ca69301d40ff9f85bbe7599bb9a..70379fe535dd49ec6e2885a882b924faead544e6 100644 --- a/src/main/java/org/olat/core/util/WebappHelper.java +++ b/src/main/java/org/olat/core/util/WebappHelper.java @@ -47,6 +47,7 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.StartupException; import org.olat.core.logging.Tracing; import org.olat.core.util.i18n.I18nModule; +import org.springframework.beans.factory.BeanInitializationException; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.web.context.ServletContextAware; @@ -71,6 +72,7 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA private static String instanceId; private static String userDataRoot; private static String defaultCharset; + private static boolean enforceUtf8Filesystem; private static Map<String, String> mailConfig = new HashMap<String, String>(6); private static long timeOfServerStartup = System.currentTimeMillis(); @@ -375,6 +377,14 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA WebappHelper.defaultCharset = defaultCharset; } + /** + * [spring] + * @param enforceUtf8Filesystem + */ + public void setEnforceUtf8Filesystem(boolean enforceUtf8Filesystem) { + WebappHelper.enforceUtf8Filesystem = enforceUtf8Filesystem; + } + /** * key="mailhost" * key="mailTimeout" @@ -432,13 +442,20 @@ public class WebappHelper implements Initializable, Destroyable, ServletContextA } else { // test failed 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()::" + java.nio.charset.Charset.defaultCharset().name() + " (the one used) and your system property file.encoding::" + System.getProperty("file.encoding") + " (the one configured)"); } // try to delete file anyway 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!"); + } } /** diff --git a/src/main/java/org/olat/core/util/_spring/utilCorecontext.xml b/src/main/java/org/olat/core/util/_spring/utilCorecontext.xml index 8c7bdba61ac87e11739c601de33dd2c2a54fd5b0..3608aef9fd72f96b7543c9a1804047662607c96f 100644 --- a/src/main/java/org/olat/core/util/_spring/utilCorecontext.xml +++ b/src/main/java/org/olat/core/util/_spring/utilCorecontext.xml @@ -40,6 +40,7 @@ </map> </property> <property name="defaultCharset" value="${defaultcharset}" /> + <property name="enforceUtf8Filesystem" value="${enforce.utf8.filesystem}" /> <property name="version" value="${build.version}" /> <property name="applicationName" value="${application.name}" /> <property name="mobileContext" value="${mobile.context}" /> diff --git a/src/main/resources/serviceconfig/olat.properties b/src/main/resources/serviceconfig/olat.properties index f462387ca4b7010a5629a931e0034ff2f39ed85a..cb39eef258060698656429d9c455bfff84a8422b 100644 --- a/src/main/resources/serviceconfig/olat.properties +++ b/src/main/resources/serviceconfig/olat.properties @@ -82,10 +82,12 @@ fallbacklang.values=de,en # ${userdata.dir}/system/configuration/org.olat.core.util.i18n.I18nModule.properties 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 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 history.back.enabled=true