db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1403807 - 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 Tue, 30 Oct 2012 18:02:39 GMT
Author: mamta
Date: Tue Oct 30 18:02:38 2012
New Revision: 1403807

URL: http://svn.apache.org/viewvc?rev=1403807&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)

The earlier commit caused test failures because readme file creation was not getting done
inside a privileged block. This commit fixes that problem and it was also fixes so typo and
gets rid of redundant file close since that is already happening in the finally block.


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=1403807&r1=1403806&r2=1403807&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
Tue Oct 30 18:02:38 2012
@@ -446,7 +446,6 @@ final class StorageFactoryService implem
                                 fileReadMeDB = fileReadMe.getRandomAccessFile( "rw");
                                 fileReadMeDB.writeUTF(MessageService.getTextMessage(
                                     MessageId.README_AT_DB_LEVEL));
-                                fileReadMeDB.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=1403807&r1=1403806&r2=1403807&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 Tue Oct
30 18:02:38 2012
@@ -149,6 +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;
 
 	public RawStore() {
 	}
@@ -2371,6 +2372,21 @@ public final class RawStore implements R
         }
     }
 
+    private synchronized StorageRandomAccessFile privRandomAccessFile(StorageFile file, String
perms)
+        throws IOException
+    {
+        actionCode = REGULAR_FILE_EXISTS_ACTION;
+        actionStorageFile = file;
+        activePerms = perms;
+        try
+        {
+            return (StorageRandomAccessFile) java.security.AccessController.doPrivileged(this);
+        }
+        catch (java.security.PrivilegedActionException pae)
+        {
+            throw (IOException) pae.getException();
+        }
+    }
 
     private synchronized boolean privDelete( File file)
     {
@@ -2777,26 +2793,28 @@ public final class RawStore implements R
             "seg0",
             PersistentService.DB_README_FILE_NAME);
         StorageRandomAccessFile fileReadMeDB=null;
-        try {
-            fileReadMeDB = fileReadMe.getRandomAccessFile("rw");
-            fileReadMeDB.writeUTF(MessageService.getTextMessage(
-                MessageId.README_AT_SEG_LEVEL));
-            fileReadMeDB.close();
-        }
-        catch (IOException ioe)
-        {
-        }
-        finally
-        {
-            if (fileReadMeDB != null)
+        
+        if (privExists(fileReadMe)) {
+            try {
+                fileReadMeDB = privRandomAccessFile(fileReadMe, "rw");
+                fileReadMeDB.writeUTF(MessageService.getTextMessage(
+                    MessageId.README_AT_LOG_LEVEL));
+            }
+            catch (IOException ioe)
             {
-                try
-                {
-                    fileReadMeDB.close();
-                }
-                catch (IOException ioe)
+            }
+            finally
+            {
+                if (fileReadMeDB != null)
                 {
-                    // Ignore exception on close
+                    try
+                    {
+                        fileReadMeDB.close();
+                    }
+                    catch (IOException ioe)
+                    {
+                        // Ignore exception on close
+                    }
                 }
             }
         }

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=1403807&r1=1403806&r2=1403807&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 Tue
Oct 30 18:02:38 2012
@@ -2738,27 +2738,28 @@ public final class LogToFile implements 
             StorageFile fileReadMe = logStorageFactory.newStorageFile(
                 LogFactory.LOG_DIRECTORY_NAME,
                 PersistentService.DB_README_FILE_NAME);
-            StorageRandomAccessFile fileReadMeDB=null;
-            try {
-                fileReadMeDB = fileReadMe.getRandomAccessFile("rw");
-                fileReadMeDB.writeUTF(MessageService.getTextMessage(
-                    MessageId.README_AT_LOG_LEVEL));
-                fileReadMeDB.close();
-            }
-            catch (IOException ioe)
-            {
-            }
-            finally
-            {
-                if (fileReadMeDB != null)
+            if (privExists(fileReadMe)) {
+                StorageRandomAccessFile fileReadMeDB=null;
+                try {
+                    fileReadMeDB = privRandomAccessFile(fileReadMe, "rw");
+                    fileReadMeDB.writeUTF(MessageService.getTextMessage(
+                        MessageId.README_AT_LOG_LEVEL));
+                }
+                catch (IOException ioe)
                 {
-                    try
-                    {
-                        fileReadMeDB.close();
-                    }
-                    catch (IOException ioe)
+                }
+                finally
+                {
+                    if (fileReadMeDB != null)
                     {
-                        // Ignore exception on close
+                        try
+                        {
+                            fileReadMeDB.close();
+                        }
+                        catch (IOException ioe)
+                        {
+                            // Ignore exception on close
+                        }
                     }
                 }
             }

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=1403807&r1=1403806&r2=1403807&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 Tue Oct 30 18:02:38
2012
@@ -8428,10 +8428,10 @@ Shutting down instance {0} on database d
                 <text>
 # *************************************************************************
 # ***              Do not touch files in this directory!                ***
-# *** FILES IN THIS DIRECTORY AND SUB-DIRECTORIES CONSTITUES DERBY      ***
-# *** DATABASE WHICH INCLUDES THE DATA(USER AND SYSTEM) AND THE         ***
+# *** FILES IN THIS DIRECTORY AND SUB-DIRECTORIES CONSTITUE DERBY       ***
+# *** DATABASE WHICH INCLUDES THE DATA (USER AND SYSTEM) AND THE        ***
 # *** NECESSARY FILES FOR DATABASE RECOVERY.                            ***
-# *** EDITING, ADDITING 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