You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/10/03 14:44:51 UTC
svn commit: r1629194 - in /db/derby/code/branches/10.11: ./
java/engine/org/apache/derby/impl/sql/compile/
java/engine/org/apache/derby/loc/
java/testing/org/apache/derbyTesting/functionTests/master/
java/testing/org/apache/derbyTesting/functionTests/t...
Author: rhillegas
Date: Fri Oct 3 12:44:51 2014
New Revision: 1629194
URL: http://svn.apache.org/r1629194
Log:
DERBY-6635: Port 1629192 (derby-6635-01-ab-noOverwrite.diff) from trunk to the 10.11 branch.
Modified:
db/derby/code/branches/10.11/ (props changed)
db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml
db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
Propchange: db/derby/code/branches/10.11/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1629192
Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java (original)
+++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java Fri Oct 3 12:44:51 2014
@@ -21,12 +21,16 @@
package org.apache.derby.impl.sql.compile;
+import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
import java.sql.SQLException;
import org.apache.derby.iapi.db.OptimizerTrace;
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.error.StandardException;
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.services.context.ContextService;
import org.apache.derby.iapi.services.i18n.MessageService;
@@ -151,12 +155,23 @@ public class OptimizerTracer implemen
{
pw = AccessController.doPrivileged
(
- new PrivilegedAction<PrintWriter>()
+ new PrivilegedExceptionAction<PrintWriter>()
{
- public PrintWriter run()
+ public PrintWriter run() throws SQLException
{
try {
- return new PrintWriter( configurationParameters[ 0 ] );
+ String fileName = configurationParameters[ 0 ];
+ File outputFile = new File( fileName );
+
+ if ( outputFile.exists() )
+ {
+ throw PublicAPI.wrapStandardException
+ (
+ StandardException.newException( SQLState.DATA_FILE_EXISTS, fileName )
+ );
+ }
+
+ return new PrintWriter( outputFile );
} catch (IOException ioe) { throw new IllegalArgumentException( ioe.getMessage(), ioe ); }
}
}
@@ -174,7 +189,17 @@ public class OptimizerTracer implemen
if ( needsClosing ) { pw.close(); }
}
- catch (Exception e) { throw wrap( e ); }
+ catch (Exception e)
+ {
+ if ( e.getMessage() == null )
+ {
+ Throwable cause = e.getCause();
+ if ( (cause != null) && (cause instanceof SQLException) )
+ { throw (SQLException) cause; }
+ }
+
+ throw wrap( e );
+ }
finally
{
OptimizerTrace.setOptimizerTracer( null );
Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/branches/10.11/java/engine/org/apache/derby/loc/messages.xml Fri Oct 3 12:44:51 2014
@@ -4767,7 +4767,7 @@ ln=lower-case two-letter ISO-639 languag
<msg>
<name>XIE0S.S</name>
- <text>The export operation was not performed, because the specified output file ({0}) already exists. Export processing will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the export procedure arguments to specify a file which does not exist, or delete the existing file, then retry the export operation.</text>
+ <text>The operation was not performed, because the specified output file ({0}) already exists. The procedure will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the procedure arguments to specify a file which does not exist, or delete the existing file, then retry the operation.</text>
<arg>fileName</arg>
</msg>
Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out (original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out Fri Oct 3 12:44:51 2014
@@ -805,7 +805,7 @@ ij> --
--
CALL SYSCS_UTIL.SYSCS_EXPORT_TABLE
( null, 'DERBY_2925_TAB', 'extout/derby-2925.txt', null, null, null);
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925.txt) already exists. Export processing will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the export procedure arguments to specify a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925.txt) already exists. The procedure will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the procedure arguments to specify a file which does not exist, or delete the existing file, then retry the operation.
ij> --
-- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY
--
@@ -820,7 +820,7 @@ ij> --
--
CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY
('select * from DERBY_2925_TAB', 'extout/derby-2925-query.dat', null , null , null ) ;
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925-query.dat) already exists. Export processing will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the export procedure arguments to specify a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925-query.dat) already exists. The procedure will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the procedure arguments to specify a file which does not exist, or delete the existing file, then retry the operation.
ij> --
-- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
--
@@ -848,7 +848,7 @@ ij> --
--
CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
('SELECT * FROM DERBY_2925_LOB','extout/derby-2925_data.dat', '\' ,'|','UTF-16','extout/derby-2925_lobs.dat');
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925_data.dat) already exists. Export processing will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the export procedure arguments to specify a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925_data.dat) already exists. The procedure will not overwrite an existing file, even if the process has permissions to write to that file, due to security concerns, and to avoid accidental file damage. Please either change the output file name in the procedure arguments to specify a file which does not exist, or delete the existing file, then retry the operation.
ij> --
-- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
-- where lob file exists.
Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java (original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java Fri Oct 3 12:44:51 2014
@@ -9316,6 +9316,7 @@ public class MergeStatementTest extends
{
Connection dboConnection = openUserConnection( TEST_DBO );
File traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+ SupportFilesSetup.deleteFile( traceFile );
//
// Schema
Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java (original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java Fri Oct 3 12:44:51 2014
@@ -46,6 +46,7 @@ public class XMLOptimizerTraceTest exte
private static final String TRACE_FILE_NAME = "xott.xml";
private static final String SAVED_TRACE_NAME = "xmlOptimizer.trace";
+ private static final String FILE_EXISTS = "XIE0S";
///////////////////////////////////////////////////////////////////////////////////
//
@@ -228,6 +229,8 @@ public class XMLOptimizerTraceTest exte
Connection conn = getConnection();
File traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+ SupportFilesSetup.deleteFile( traceFile );
+
// turn on xml-based optimizer tracing and run some queries
goodStatement
(
@@ -318,6 +321,25 @@ public class XMLOptimizerTraceTest exte
// use planCost to examine an outer join
vetOuterJoin( conn );
+
+ // verify that you can't overwrite an existing file with xml output (DERBY-6635)
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_register_tool( 'optimizerTracing', true, 'xml' )"
+ );
+ expectExecutionError
+ (
+ conn,
+ FILE_EXISTS,
+ "call syscs_util.syscs_register_tool( 'optimizerTracing', false, '" + traceFile.getPath() + "' )"
+ );
+ goodStatement
+ (
+ conn,
+ "call syscs_util.syscs_register_tool( 'optimizerTracing', false )"
+ );
+
}
/**
@@ -576,6 +598,7 @@ public class XMLOptimizerTraceTest exte
private void vetOuterJoin( Connection conn ) throws Exception
{
File traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+ SupportFilesSetup.deleteFile( traceFile );
// turn on xml-based optimizer tracing
goodStatement
Modified: db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java?rev=1629194&r1=1629193&r2=1629194&view=diff
==============================================================================
--- db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java (original)
+++ db/derby/code/branches/10.11/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java Fri Oct 3 12:44:51 2014
@@ -298,9 +298,13 @@ public class SupportFilesSetup extends T
public static void deleteFile(final String fileName)
{
- File f = new File(fileName);
- if (PrivilegedFileOpsForTests.exists(f)) {
- assertTrue(PrivilegedFileOpsForTests.delete(f));
+ deleteFile( new File(fileName) );
+ }
+
+ public static void deleteFile(final File file )
+ {
+ if (PrivilegedFileOpsForTests.exists(file)) {
+ assertTrue(PrivilegedFileOpsForTests.delete(file));
}
}
}