You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/06/21 05:32:01 UTC
svn commit: r549346 - in /harmony/enhanced/classlib/trunk/modules:
luni/src/main/java/java/io/ luni/src/test/api/common/tests/api/java/io/
luni/src/test/api/windows/org/ luni/src/test/api/windows/org/apache/
luni/src/test/api/windows/org/apache/harmony...
Author: pyang
Date: Wed Jun 20 20:31:59 2007
New Revision: 549346
URL: http://svn.apache.org/viewvc?view=rev&rev=549346
Log:
Apply patch for HARMONY-3656([classlib][luni] File.mkdir does not support unicode) with small modifications to make new FileTest for windows only compile
Added:
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?view=diff&rev=549346&r1=549345&r2=549346
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java Wed Jun 20 20:31:59 2007
@@ -396,7 +396,7 @@
security.checkDelete(path);
}
- DeleteOnExit.addFile(Util.toString(properPath(true)));
+ DeleteOnExit.addFile(Util.toUTF8String(properPath(true)));
}
/**
@@ -452,7 +452,7 @@
*/
public String getAbsolutePath() {
byte[] absolute = properPath(false);
- return Util.toString(absolute);
+ return Util.toUTF8String(absolute);
}
/**
@@ -577,7 +577,7 @@
newResult[newLength] = 0;
newResult = getCanonImpl(newResult);
newLength = newResult.length;
- return Util.toString(newResult, 0, newLength);
+ return Util.toUTF8String(newResult, 0, newLength);
}
/**
@@ -1179,7 +1179,7 @@
if (properPath != null) {
return properPath;
}
- byte[] pathBytes = Util.getBytes(path);
+ byte[] pathBytes = Util.getUTF8Bytes(path);
if (isAbsoluteImpl(pathBytes)) {
return properPath = pathBytes;
}
@@ -1195,23 +1195,32 @@
return properPath;
}
if (path.length() == 0) {
- return properPath = Util.getBytes(userdir);
+ return properPath = Util.getUTF8Bytes(userdir);
}
int length = userdir.length();
+
+ // Handle windows-like path
if (path.charAt(0) == '\\') {
if (length > 1 && userdir.charAt(1) == ':') {
- return properPath = Util.getBytes(userdir.substring(0, 2)
+ return properPath = Util.getUTF8Bytes(userdir.substring(0, 2)
+ path);
+ } else {
+ path = path.substring(1);
}
- if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
- return properPath = Util.getBytes(userdir + path.substring(1));
- }
- return properPath = Util.getBytes(userdir + path);
}
- if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
- return properPath = Util.getBytes(userdir + path);
+
+ // Handle separator
+ String result = userdir;
+ if (userdir.charAt(length - 1) != separatorChar) {
+ if (path.charAt(0) != separatorChar) {
+ result += separator;
+ }
+ } else if (path.charAt(0) == separatorChar) {
+ result = result.substring(0, length - 2);
+
}
- return properPath = Util.getBytes(userdir + separator + path);
+ result += path;
+ return properPath = Util.getUTF8Bytes(result);
}
private static native byte[] properPathImpl(byte[] path);
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java?view=diff&rev=549346&r1=549345&r2=549346
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/FileTest.java Wed Jun 20 20:31:59 2007
@@ -1812,6 +1812,7 @@
dir.deleteOnExit();
String longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars
+ String newbase = new String(dir + File.separator);
StringBuilder sb = new StringBuilder(dir + File.separator);
StringBuilder sb2 = new StringBuilder(dir + File.separator);
@@ -1830,7 +1831,7 @@
dir.mkdir() && dir.exists());
dir.deleteOnExit();
}
-
+ dir = new File(sb2.toString());
// Test make many paths
while (dir.getCanonicalPath().length() < 256) {
sb2.append(0);
@@ -1839,6 +1840,24 @@
dir.mkdir() && dir.exists());
dir.deleteOnExit();
}
+
+ // Regression test for HARMONY-3656
+ String []ss = {
+ "dir\u3400",
+ "abc",
+ "abc@123",
+ "!@#$%^&",
+ "~\u4E00!\u4E8C@\u4E09$",
+ "\u56DB\u4E94\u516D",
+ "\u4E03\u516B\u4E5D"
+ };
+ for (int i=0; i<ss.length; i++)
+ {
+ dir = new File(newbase, ss[i]);
+ assertTrue("mkdir " + dir.getCanonicalPath() + " failed",
+ dir.mkdir() && dir.exists());
+ dir.deleteOnExit();
+ }
}
/**
Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java?view=auto&rev=549346
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java Wed Jun 20 20:31:59 2007
@@ -0,0 +1,88 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.io;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class WinFileTest extends TestCase {
+
+ /**
+ * @tests java.io.File#mkdir()
+ * @throws IOException
+ */
+ public void test_mkdir() throws IOException {
+ // Test for method boolean java.io.File.mkdir() in Windows Platform
+
+ String base = System.getProperty("user.dir");
+ // Old test left behind "garbage files" so this time it creates a
+ // directory
+ // that is guaranteed not to already exist (and deletes it afterward.)
+ int dirNumber = 1;
+ boolean dirExists = true;
+ File dir = new File(base, String.valueOf(dirNumber));
+ while (dirExists) {
+ if (dir.exists()) {
+ dirNumber++;
+ dir = new File(base, String.valueOf(dirNumber));
+ } else {
+ dirExists = false;
+ }
+ }
+ assertTrue("mkdir failed", dir.mkdir() && dir.exists());
+ dir.deleteOnExit();
+ String newbase = new String(dir + File.separator);
+
+ dir = new File(newbase, ".abcd");
+ assertTrue("mkdir " + dir.getCanonicalPath() + " failed",
+ dir.mkdir() && dir.exists() && !(new File(newbase,"abcd")).exists());
+ dir.deleteOnExit();
+
+ String []ss1 = {
+ ".abcd" + File.separator + "." + File.separator + "dir1",
+ ".abcd" + File.separator + ".." + File.separator + "dir2",
+ ".abcd" + File.separator + "." + File.separator + "." + File.separator + "dir3",
+ "12" + File.separator + "34" + File.separator + ".." + File.separator + ".." + File.separator + "dir4",
+ "12" + File.separator + ".." + File.separator + "34" + File.separator + ".." + File.separator + "dir5",
+ ".abcd." + File.separator + ".." + File.separator + "dir6.",
+ ".abcd.." + File.separator + "dir7",
+ ".abcd.." + File.separator + ".." + File.separator + "dir8"
+ };
+ String []ss2 = {
+ ".abcd" + File.separator + "dir1",
+ "dir2",
+ ".abcd" + File.separator + "dir3",
+ "dir4",
+ "dir5",
+ "dir6",
+ ".abcd" + File.separator + "dir7",
+ "dir8"
+ };
+ for (int i=0; i<ss1.length; i++)
+ {
+ dir = new File(newbase, ss1[i]);
+ assertTrue("mkdir " + dir.getCanonicalPath() + " failed",
+ dir.mkdir() && dir.exists());
+ dir = new File(newbase, ss2[i]);
+ assertTrue("mkdir " + dir.getCanonicalPath() + " failed",
+ dir.exists());
+ dir.deleteOnExit();
+ }
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c?view=diff&rev=549346&r1=549345&r2=549346
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c (original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hyfile.c Wed Jun 20 20:31:59 2007
@@ -35,6 +35,8 @@
#define CDEV_CURRENT_FUNCTION _prototypes_private
static I_32 findError (I_32 errorCode);
+void convert_path_to_unicode(struct HyPortLibrary * portLibrary, const char *path,
+ wchar_t **pathW);
#undef CDEV_CURRENT_FUNCTION
@@ -87,7 +89,10 @@
hyfile_attr (struct HyPortLibrary * portLibrary, const char *path)
{
DWORD result;
- result = GetFileAttributes ((LPCTSTR) path);
+ wchar_t *pathW;
+ convert_path_to_unicode(portLibrary, path, &pathW);
+ result = GetFileAttributesW ((LPCWSTR) pathW);
+ portLibrary->mem_free_memory(portLibrary, pathW);
if (result == 0xFFFFFFFF)
{
result = GetLastError ();
@@ -327,6 +332,73 @@
#undef CDEV_CURRENT_FUNCTION
+#define CDEV_CURRENT_FUNCTION convert_path_to_unicode
+
+void
+convert_path_to_unicode(struct HyPortLibrary * portLibrary, const char *path,
+ wchar_t **pathW)
+{
+ int len = strlen(path);
+ int wlen;
+ char *canonicalpath;
+ int srcArrayCount=0;
+ int destArrayCount=0;
+ int slashCount=0; //record how many slashes it met.
+ int dotsCount=0; //record how many dots following a separator.
+ int *slashStack; //record position of every separator.
+ slashStack = portLibrary->mem_allocate_memory(portLibrary, len*sizeof(int));
+ canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
+
+ strcpy(canonicalpath,"\\\\?\\");
+
+ for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
+ // the input path of this method has been parsed to absolute path already.
+ if(path[srcArrayCount]=='.'){
+ // count the dots following last separator.
+ if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
+ dotsCount++;
+ continue;
+ }
+ }
+ // deal with the dots when we meet next separator.
+ if(path[srcArrayCount]=='\\'){
+ if(dotsCount == 1){
+ dotsCount = 0;
+ continue;
+ }else if (dotsCount > 1){
+ if(slashCount-2<0){
+ slashCount=2;
+ }
+ destArrayCount=slashStack[slashCount-2];
+ dotsCount = 0;
+ slashCount--;
+ }else{
+ while(canonicalpath[destArrayCount-1] == '.'){
+ destArrayCount--;
+ }
+ slashStack[slashCount++]=destArrayCount;
+ }
+ }
+ // for normal character.
+ while(dotsCount >0){
+ canonicalpath[destArrayCount++]='.';
+ dotsCount--;
+ }
+ canonicalpath[destArrayCount++]=path[srcArrayCount];
+ }
+ while(canonicalpath[destArrayCount-1] == '.'){
+ destArrayCount--;
+ }
+ canonicalpath[destArrayCount]='\0';
+ wlen = MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, 0);
+ *pathW = portLibrary->mem_allocate_memory(portLibrary, wlen*sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, wlen);
+ portLibrary->mem_free_memory(portLibrary, canonicalpath);
+ portLibrary->mem_free_memory(portLibrary, slashStack);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
#define CDEV_CURRENT_FUNCTION hyfile_mkdir
/**
* Create a directory.
@@ -341,71 +413,22 @@
I_32 VMCALL
hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
{
- int returnVar=0;
- int len = strlen(path);
- //If the length is longer than 248, unicode format should be used to CreateDirectroy.
- //"." and ".." need be processed in the unicode format.
- if(len >= 248){
- char *canonicalpath;
- int srcArrayCount=0;
- int destArrayCount=0;
- int slashCount=0; //record how many slashes it met.
- int dotsCount=0; //record how many dots following a separator.
- int *slashStack; //record position of every separator.
- slashStack = portLibrary->mem_allocate_memory(portLibrary, len);
- canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
-
- strcpy(canonicalpath,"\\\\?\\");
-
- for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
- // the input path of this method has been parsed to absolute path already.
- if(path[srcArrayCount]=='.'){
- // count the dots following last separator.
- if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
- dotsCount++;
- continue;
- }
- }
- // deal with the dots when we meet next separator.
- if(path[srcArrayCount]=='\\'){
- if(dotsCount == 1){
- dotsCount = 0;
- continue;
- }else if (dotsCount > 1){
- if(slashCount-2<0){
- slashCount=2;
- }
- destArrayCount=slashStack[slashCount-2];
- slashCount--;
- }else{
- slashStack[slashCount++]=destArrayCount;
- }
- }
- // for normal character.
- canonicalpath[destArrayCount]=path[srcArrayCount];
- destArrayCount++;
- dotsCount = 0;
- }
-
- canonicalpath[destArrayCount]='\0';
- returnVar = CreateDirectory (canonicalpath, 0);
-
- portLibrary->mem_free_memory(portLibrary, canonicalpath);
- portLibrary->mem_free_memory(portLibrary, slashStack);
- }else{
- returnVar = CreateDirectory (path, 0);
- }
+ int returnVar=0;
+ wchar_t *pathW;
+ convert_path_to_unicode(portLibrary, path, &pathW);
+ returnVar = CreateDirectoryW (pathW, 0);
+ portLibrary->mem_free_memory(portLibrary, pathW);
- if (returnVar)
- {
- return 0;
+ if (returnVar)
+ {
+ return 0;
}
- else
+ else
{
- I_32 error = GetLastError ();
- portLibrary->error_set_last_error (portLibrary, error,
- findError (error));
- return -1;
+ I_32 error = GetLastError ();
+ portLibrary->error_set_last_error (portLibrary, error,
+ findError (error));
+ return -1;
}
}
@@ -760,20 +783,25 @@
I_32 VMCALL
hyfile_unlinkdir (struct HyPortLibrary * portLibrary, const char *path)
{
+ wchar_t *pathW;
+ convert_path_to_unicode(portLibrary, path, &pathW);
+
/* should be able to delete read-only dirs, so we set the file attribute back to normal */
- if (0 == SetFileAttributes (path, FILE_ATTRIBUTE_NORMAL))
+ if (0 == SetFileAttributesW (pathW, FILE_ATTRIBUTE_NORMAL))
{
I_32 error = GetLastError ();
portLibrary->error_set_last_error (portLibrary, error, findError (error)); /* continue */
}
- if (RemoveDirectory (path))
+ if (RemoveDirectoryW (pathW))
{
+ portLibrary->mem_free_memory(portLibrary, pathW);
return 0;
}
else
{
I_32 error = GetLastError ();
+ portLibrary->mem_free_memory(portLibrary, pathW);
portLibrary->error_set_last_error (portLibrary, error,
findError (error));
return -1;