db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r957278 - in /db/derby/code/branches/10.6/java: engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/impl/io/ engine/org/apache/derby/impl/load/ testing/org/apache/derbyTesting/functionTests/tests/tools/
Date Wed, 23 Jun 2010 17:32:32 GMT
Author: rhillegas
Date: Wed Jun 23 17:32:32 2010
New Revision: 957278

URL: http://svn.apache.org/viewvc?rev=957278&view=rev
Log:
DERBY-2925: Port 957171 from trunk to 10.6 branch.

Modified:
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/services/io/FileUtil.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/io/CPFile.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/Export.java
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/ExportWriteData.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/services/io/FileUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/services/io/FileUtil.java?rev=957278&r1=957277&r2=957278&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/services/io/FileUtil.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/services/io/FileUtil.java
Wed Jun 23 17:32:32 2010
@@ -26,6 +26,8 @@ import org.apache.derby.io.WritableStora
 import org.apache.derby.io.StorageFile;
 
 import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
 	A set of public static methods for dealing with File objects.
@@ -554,4 +556,21 @@ nextFile:	for (int i = 0; i < list.lengt
 		else
 			return new File(parent, name);
 	}
+
+	/**
+		Remove the leading 'file://' protocol from a filename which has been
+        expressed as an URL. If the filename is not an URL, then nothing is done.
+        Otherwise, an URL like 'file:///tmp/foo.txt' is transformed into the legal
+        file name '/tmp/foo.txt'.
+	*/
+    public static String stripProtocolFromFileName( String originalName )
+    {
+        String result = originalName;
+        try {
+            URL url = new URL(originalName);
+            result = url.getFile();
+        } catch (MalformedURLException ex) {}
+
+        return result;
+    }
 }

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/io/CPFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/io/CPFile.java?rev=957278&r1=957277&r2=957278&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/io/CPFile.java (original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/io/CPFile.java Wed Jun 23
17:32:32 2010
@@ -26,7 +26,6 @@ import org.apache.derby.io.StorageFile;
 import java.io.InputStream;
 
 import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
 import java.net.URL;
 
 /**

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/Export.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/Export.java?rev=957278&r1=957277&r2=957278&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/Export.java (original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/Export.java Wed Jun
23 17:32:32 2010
@@ -30,6 +30,7 @@ import java.security.PrivilegedAction;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.io.FileUtil;
 
 
 /**
@@ -122,7 +123,8 @@ public class Export extends ExportAbstra
             throw PublicAPI.wrapStandardException(
                       StandardException.newException(
 		      SQLState.LOB_DATA_FILE_NULL));
-        }
+            }
+            fileName = FileUtil.stripProtocolFromFileName( fileName );
             File file = new File(fileName);
 
             return fileExists(file);
@@ -139,7 +141,8 @@ public class Export extends ExportAbstra
             throw PublicAPI.wrapStandardException(
                       StandardException.newException(
                       SQLState.DATA_FILE_NULL));
-        }
+            }
+            fileName = FileUtil.stripProtocolFromFileName( fileName );
             File file = new File(fileName);
 
             return fileExists(file);

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/ExportWriteData.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/ExportWriteData.java?rev=957278&r1=957277&r2=957278&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/ExportWriteData.java
(original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/load/ExportWriteData.java
Wed Jun 23 17:32:32 2010
@@ -27,12 +27,12 @@ import java.io.OutputStreamWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.Reader;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.Date;
 import java.io.IOException;
 import java.io.File;
 
+import org.apache.derby.iapi.services.io.FileUtil;
+
 //this class takes the passed row and writes it into the data file using the
 //properties from the control file
 //FIXED FORMAT: if length of nullstring is greater than column width, throw execption
@@ -96,15 +96,9 @@ final class ExportWriteData extends Expo
 
   //prepares the o/p file for writing
   private void openFiles() throws Exception {
-    try {
-      URL url = new URL(outputFileName);
-      outputFileName = url.getFile();
-	  if (lobsInExtFile) {
-		  url = new URL(lobsFileName);
-		  lobsFileName = url.getFile();
-	  }
-    } catch (MalformedURLException ex) {}
 
+    outputFileName = FileUtil.stripProtocolFromFileName( outputFileName );
+    if ( lobsInExtFile ) { lobsFileName = FileUtil.stripProtocolFromFileName( lobsFileName
); }
     
     FileOutputStream anOutputStream = null;
     BufferedOutputStream buffered = null;

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java?rev=957278&r1=957277&r2=957278&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
(original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
Wed Jun 23 17:32:32 2010
@@ -1,7 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.functionTests.tests.
-                                         tools.ImportExportBinaryDataTest
+   Derby - Class org.apache.derbyTesting.functionTests.tests.tools.ImportExportBinaryDataTest
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -388,6 +387,15 @@ public class ImportExportBinaryDataTest 
 	    assertSQLState("XIE0S", e);
 	}
 
+    // should not be able to subvert the check by turning the file name into an url
+	try {
+	    doExportTable("APP", "DERBY_2925_TAB", "file:" + fileName, null, null , null);
+	    fail("export should have failed on existing data file.");
+	}
+	catch (SQLException e) {
+	    assertSQLState("XIE0S", e);
+	}
+
     }
     /*
      * DERBY-2925: Prevent export from overwriting existing files



Mime
View raw message