db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1407170 - in /db/derby/code/trunk/java/engine/org/apache/derby: impl/services/monitor/StorageFactoryService.java impl/store/raw/RawStore.java impl/store/raw/log/LogToFile.java loc/messages.xml
Date Thu, 08 Nov 2012 17:13:36 GMT
Author: mamta
Date: Thu Nov  8 17:13:36 2012
New Revision: 1407170

URL: http://svn.apache.org/viewvc?rev=1407170&view=rev
Log:
DERBY-5232 (Put a stern README file in log and seg0 directories to warn users of corrpution
they will cause if they touch files there)

This commit fixes 
a)a typo in the readme file content.
b)uses OutputStreamWrtier to deal with UTF-8 encoding for the readme files.
c)fixes the if condition used to create readme files


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java?rev=1407170&r1=1407169&r2=1407170&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/StorageFactoryService.java
Thu Nov  8 17:13:36 2012
@@ -435,28 +435,28 @@ final class StorageFactoryService implem
         {
             AccessController.doPrivileged(
             	    new PrivilegedExceptionAction()
-            	    {
-            	        public Object run() throws StandardException
-            	        {
-            	            StorageRandomAccessFile fileReadMeDB=null;
-            	            try 
-            	            {
-            	                StorageFile fileReadMe = storageFactory.newStorageFile(
-            	                    PersistentService.DB_README_FILE_NAME);
-                                fileReadMeDB = fileReadMe.getRandomAccessFile( "rw");
-                                fileReadMeDB.writeUTF(MessageService.getTextMessage(
-                                    MessageId.README_AT_DB_LEVEL));
+                    {
+                        public Object run() throws StandardException
+                        {
+                            OutputStreamWriter osw=null; 
+                            try 
+                            {
+                                StorageFile fileReadMe = storageFactory.newStorageFile(
+                                    PersistentService.DB_README_FILE_NAME);
+                                osw = new OutputStreamWriter(fileReadMe.getOutputStream(),"UTF8");
+                                osw.write(MessageService.getTextMessage(
+                                        MessageId.README_AT_DB_LEVEL));
                             }
                             catch (IOException ioe)
                             {
                             }
                             finally
                             {
-                                if (fileReadMeDB != null)
+                                if (osw != null)
                                 {
                                     try
                                     {
-                                        fileReadMeDB.close();
+                                        osw.close();
                                     }
                                     catch (IOException ioe)
                                     {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java?rev=1407170&r1=1407169&r2=1407170&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/RawStore.java Thu Nov
 8 17:13:36 2012
@@ -75,7 +75,7 @@ import java.io.Serializable;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-
+import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 
@@ -149,7 +149,7 @@ public final class RawStore implements R
     private static final int STORAGE_FILE_GET_CANONICALPATH_ACTION = 16;
     private static final int COPY_STORAGE_FILE_TO_STORAGE_ACTION = 17;
     private static final int STORAGE_FILE_DELETE_ACTION = 18;
-    private String activePerms;
+    private static final int README_FILE_OUTPUTSTREAM_WRITER_ACTION = 19;
 
 	public RawStore() {
 	}
@@ -2372,15 +2372,14 @@ public final class RawStore implements R
         }
     }
 
-    private synchronized StorageRandomAccessFile privRandomAccessFile(StorageFile file, String
perms)
+    private synchronized OutputStreamWriter privGetOutputStreamWriter(StorageFile file)
         throws IOException
     {
-        actionCode = REGULAR_FILE_EXISTS_ACTION;
+        actionCode = README_FILE_OUTPUTSTREAM_WRITER_ACTION;
         actionStorageFile = file;
-        activePerms = perms;
         try
         {
-            return (StorageRandomAccessFile) java.security.AccessController.doPrivileged(this);
+            return (OutputStreamWriter) java.security.AccessController.doPrivileged(this);
         }
         catch (java.security.PrivilegedActionException pae)
         {
@@ -2773,6 +2772,8 @@ public final class RawStore implements R
         case STORAGE_FILE_GET_CANONICALPATH_ACTION:
             // SECURITY PERMISSION - MP1
             return (String)(actionStorageFile.getCanonicalPath());
+        case README_FILE_OUTPUTSTREAM_WRITER_ACTION:
+        	return(new OutputStreamWriter(actionStorageFile.getOutputStream(),"UTF8"));
         }
         return null;
     } // end of run
@@ -2792,24 +2793,24 @@ public final class RawStore implements R
         StorageFile fileReadMe = storageFactory.newStorageFile(
             "seg0",
             PersistentService.DB_README_FILE_NAME);
-        StorageRandomAccessFile fileReadMeDB=null;
-        
-        if (privExists(fileReadMe)) {
+        OutputStreamWriter osw = null;
+
+        if (!privExists(fileReadMe)) {
             try {
-                fileReadMeDB = privRandomAccessFile(fileReadMe, "rw");
-                fileReadMeDB.writeUTF(MessageService.getTextMessage(
-                    MessageId.README_AT_LOG_LEVEL));
+                osw = privGetOutputStreamWriter(fileReadMe);
+                osw.write(MessageService.getTextMessage(
+                    MessageId.README_AT_SEG_LEVEL));
             }
             catch (IOException ioe)
             {
             }
             finally
             {
-                if (fileReadMeDB != null)
+                if (osw != null)
                 {
                     try
                     {
-                        fileReadMeDB.close();
+                        osw.close();
                     }
                     catch (IOException ioe)
                     {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java?rev=1407170&r1=1407169&r2=1407170&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/LogToFile.java Thu
Nov  8 17:13:36 2012
@@ -96,6 +96,7 @@ import org.apache.derby.iapi.util.Interr
 
 import java.io.File; // Plain files are used for backups
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.SyncFailedException;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
@@ -2738,11 +2739,11 @@ public final class LogToFile implements 
             StorageFile fileReadMe = logStorageFactory.newStorageFile(
                 LogFactory.LOG_DIRECTORY_NAME,
                 PersistentService.DB_README_FILE_NAME);
-            if (privExists(fileReadMe)) {
-                StorageRandomAccessFile fileReadMeDB=null;
+            if (!privExists(fileReadMe)) {
+                OutputStreamWriter osw = null;
                 try {
-                    fileReadMeDB = privRandomAccessFile(fileReadMe, "rw");
-                    fileReadMeDB.writeUTF(MessageService.getTextMessage(
+                    osw = privGetOutputStreamWriter(fileReadMe);
+                    osw.write(MessageService.getTextMessage(
                         MessageId.README_AT_LOG_LEVEL));
                 }
                 catch (IOException ioe)
@@ -2750,11 +2751,11 @@ public final class LogToFile implements 
                 }
                 finally
                 {
-                    if (fileReadMeDB != null)
+                    if (osw != null)
                     {
                         try
                         {
-                            fileReadMeDB.close();
+                            osw.close();
                         }
                         catch (IOException ioe)
                         {
@@ -5688,6 +5689,21 @@ public final class LogToFile implements 
         }
     }
 
+    private synchronized OutputStreamWriter privGetOutputStreamWriter(StorageFile file)
+        throws IOException
+    {
+        action = 10;
+        activeFile = file;
+        try
+        {
+            return (OutputStreamWriter) java.security.AccessController.doPrivileged(this);
+        }
+        catch (java.security.PrivilegedActionException pae)
+        {
+            throw (IOException) pae.getException();
+        }
+    }
+
     protected boolean privCanWrite(StorageFile file)
     {
 		return runBooleanAction(3, file);
@@ -5841,6 +5857,8 @@ public final class LogToFile implements 
             return toFile.list();
         case 9:
             return ReuseFactory.getBoolean(FileUtil.copyFile( logStorageFactory, toFile,
activeFile));
+        case 10:
+        	return(new OutputStreamWriter(activeFile.getOutputStream(),"UTF8"));
 
 		default:
 			return null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1407170&r1=1407169&r2=1407170&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Thu Nov  8 17:13:36
2012
@@ -8436,7 +8436,7 @@ Shutting down instance {0} on database d
 # *** FILES IN THIS DIRECTORY AND SUB-DIRECTORIES CONSTITUTE DERBY      ***
 # *** DATABASE WHICH INCLUDES THE DATA (USER AND SYSTEM) AND THE        ***
 # *** NECESSARY FILES FOR DATABASE RECOVERY.                            ***
-# *** EDITING, ADDING OR DELETING ANY OF THESE FILES MAY CAUSE DATA   ***
+# *** EDITING, ADDING OR DELETING ANY OF THESE FILES MAY CAUSE DATA     ***
 # *** CORRUPTION AND LEAVE THE DATABASE IN NON-RECOVERABLE STATE.       ***
 # *************************************************************************</text>
                 <comment>Translators: Please translate the ALL CAPS words.</comment>



Mime
View raw message