Jelajahi Sumber

add xodus readme txt file

jrivard@gmail.com 6 tahun lalu
induk
melakukan
bb133838e8

+ 25 - 1
server/src/main/java/password/pwm/util/localdb/XodusLocalDB.java

@@ -36,6 +36,7 @@ import jetbrains.exodus.env.StoreConfig;
 import jetbrains.exodus.env.Transaction;
 import jetbrains.exodus.management.Statistics;
 import jetbrains.exodus.management.StatisticsItem;
+import password.pwm.PwmConstants;
 import password.pwm.error.ErrorInformation;
 import password.pwm.error.PwmError;
 import password.pwm.util.java.ConditionalTaskExecutor;
@@ -48,6 +49,8 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 import java.time.Instant;
 import java.util.Collection;
 import java.util.Collections;
@@ -55,6 +58,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.zip.Deflater;
@@ -68,6 +72,9 @@ public class XodusLocalDB implements LocalDBProvider
     private static final PwmLogger LOGGER = PwmLogger.forClass( XodusLocalDB.class );
     private static final TimeDuration STATS_OUTPUT_INTERVAL = new TimeDuration( 24, TimeUnit.HOURS );
 
+    private static final String FILE_SUB_PATH = "xodus";
+    private static final String README_FILENAME = "README.TXT";
+
     private Environment environment;
     private File fileLocation;
     private boolean readOnly;
@@ -131,7 +138,7 @@ public class XodusLocalDB implements LocalDBProvider
         readOnly = parameters.containsKey( Parameter.readOnly ) && Boolean.parseBoolean( parameters.get( Parameter.readOnly ) );
 
         LOGGER.trace( "preparing to open with configuration " + JsonUtil.serializeMap( environmentConfig.getSettings() ) );
-        environment = Environments.newInstance( dbDirectory.getAbsolutePath() + File.separator + "xodus", environmentConfig );
+        environment = Environments.newInstance( dbDirectory.getAbsolutePath() + File.separator + FILE_SUB_PATH, environmentConfig );
         LOGGER.trace( "environment open (" + TimeDuration.fromCurrent( startTime ).asCompactString() + ")" );
 
         environment.executeInTransaction( txn ->
@@ -149,6 +156,8 @@ public class XodusLocalDB implements LocalDBProvider
         {
             LOGGER.trace( "opened " + db + " with " + this.size( db ) + " records" );
         }
+
+        outputReadme( new File( dbDirectory.getPath() + File.separator + FILE_SUB_PATH + File.separator + README_FILENAME ) );
     }
 
     @Override
@@ -598,4 +607,19 @@ public class XodusLocalDB implements LocalDBProvider
     {
         return Collections.emptySet();
     }
+
+    private static void outputReadme( final File xodusPath )
+    {
+        try
+        {
+            final ResourceBundle resourceBundle = ResourceBundle.getBundle( XodusLocalDB.class.getName() );
+            final String contents = resourceBundle.getString( "ReadmeContents" );
+            final byte[] byteContents = contents.getBytes( PwmConstants.DEFAULT_CHARSET );
+            Files.write( xodusPath.toPath(), byteContents, StandardOpenOption.TRUNCATE_EXISTING );
+        }
+        catch ( IOException e )
+        {
+            LOGGER.error( "error writing LocalDB readme file: " + e.getMessage() );
+        }
+    }
 }

+ 31 - 0
server/src/main/resources/password/pwm/util/localdb/XodusLocalDB.properties

@@ -0,0 +1,31 @@
+#
+# Password Management Servlets (PWM)
+# http://www.pwm-project.org
+#
+# Copyright (c) 2006-2009 Novell, Inc.
+# Copyright (c) 2009-2018 The PWM Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+ReadmeContents=The files in this directory contain the LocalDB contents.\n\
+  \n\
+  DO NOT DELETE, MODIFY, OR RENAME ANY FILE IN THIS DIRECTORY.\n\
+  \n\
+  As the LocalDB grows or shrinks, the number of files in this directory will increase or decrease accordingly.  Older\n\
+  files are NOT deleted in order of creation.  A garbage collection process removes files as they are no longer needed.\n\
+  \n\
+  You can monitor the contents of the LocalDB using the administration dashboard.  The total size of the LocalDB by\n\
+  managing configuration settings.\n