harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r533069 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/java/java/io/File.java luni/src/test/java/tests/api/java/io/FileTest.java portlib/src/main/native/port/windows/hyfile.c
Date Fri, 27 Apr 2007 11:31:07 GMT
Author: pyang
Date: Fri Apr 27 04:31:06 2007
New Revision: 533069

URL: http://svn.apache.org/viewvc?view=rev&rev=533069
Log:
Revert the patch for HARMONY-3656(classlib][luni] File.mkdir does not support unicode), which
causes HARMONY-3783([classlib][luni] java cannot find class in a directory started with dot)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/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=533069&r1=533068&r2=533069
==============================================================================
--- 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 Fri Apr 27
04:31:06 2007
@@ -394,7 +394,7 @@
             security.checkDelete(path);
         }
 
-        DeleteOnExit.addFile(Util.toUTF8String(properPath(true)));
+        DeleteOnExit.addFile(Util.toString(properPath(true)));
     }
 
     /**
@@ -450,7 +450,7 @@
      */
     public String getAbsolutePath() {
         byte[] absolute = properPath(false);
-        return Util.toUTF8String(absolute);
+        return Util.toString(absolute);
     }
 
     /**
@@ -575,7 +575,7 @@
         newResult[newLength] = 0;
         newResult = getCanonImpl(newResult);
         newLength = newResult.length;
-        return Util.toUTF8String(newResult, 0, newLength);
+        return Util.toString(newResult, 0, newLength);
     }
 
     /**
@@ -1175,7 +1175,7 @@
         if (properPath != null) {
             return properPath;
         }
-        byte[] pathBytes = Util.getUTF8Bytes(path);
+        byte[] pathBytes = Util.getBytes(path);
         if (isAbsoluteImpl(pathBytes)) {
             return properPath = pathBytes;
         }
@@ -1191,32 +1191,23 @@
             return properPath;
         }
         if (path.length() == 0) {
-            return properPath = Util.getUTF8Bytes(userdir);
+            return properPath = Util.getBytes(userdir);
         }
         int length = userdir.length();
-        
-        // Handle windows-like path
         if (path.charAt(0) == '\\') {
             if (length > 1 && userdir.charAt(1) == ':') {
-                return properPath = Util.getUTF8Bytes(userdir.substring(0, 2)
+                return properPath = Util.getBytes(userdir.substring(0, 2)
                         + path);
-            } else {
-                path = path.substring(1);
             }
-        }
-        
-        // Handle separator
-        String result  = userdir;
-        if (userdir.charAt(length - 1) != separatorChar) {
-            if (path.charAt(0) != separatorChar) {
-                result += separator;
+            if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
+                return properPath = Util.getBytes(userdir + path.substring(1));
             }
-        } else if (path.charAt(0) == separatorChar) {
-            result = result.substring(0, length - 2);
-
+            return properPath = Util.getBytes(userdir + path);
+        }
+        if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
+            return properPath = Util.getBytes(userdir + path);
         }
-        result += path;
-        return properPath = Util.getUTF8Bytes(result);        
+        return properPath = Util.getBytes(userdir + separator + path);
     }
 
     private static native byte[] properPathImpl(byte[] path);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java?view=diff&rev=533069&r1=533068&r2=533069
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
Fri Apr 27 04:31:06 2007
@@ -1812,7 +1812,6 @@
         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);
         
@@ -1831,7 +1830,7 @@
                     dir.mkdir() && dir.exists());
             dir.deleteOnExit();
         }
-        dir = new File(sb2.toString());
+        
         // Test make many paths
         while (dir.getCanonicalPath().length() < 256) {
             sb2.append(0);
@@ -1840,25 +1839,6 @@
                     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.getCanonicalPath().equals(newbase + ss[i]));
-            dir.deleteOnExit();
-        }
     }
 
 	/**

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=533069&r1=533068&r2=533069
==============================================================================
--- 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
Fri Apr 27 04:31:06 2007
@@ -35,8 +35,6 @@
 #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
 
@@ -89,10 +87,7 @@
 hyfile_attr (struct HyPortLibrary * portLibrary, const char *path)
 {
   DWORD result;
-  wchar_t *pathW;
-  convert_path_to_unicode(portLibrary, path, &pathW);
-  result = GetFileAttributesW ((LPCWSTR) pathW);
-  portLibrary->mem_free_memory(portLibrary, pathW);
+  result = GetFileAttributes ((LPCTSTR) path);
   if (result == 0xFFFFFFFF)
     {
       result = GetLastError ();
@@ -332,21 +327,32 @@
 
 #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)
+#define CDEV_CURRENT_FUNCTION hyfile_mkdir
+/**
+ * Create a directory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path Directory to be created.
+ *
+ * @return 0 on success, -1 on failure.
+ * @note Assumes all components of path up to the last directory already exist. 
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
 {
+	int returnVar=0;
 	int len = strlen(path);
-	int wlen;
+    //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*sizeof(int));
+        slashStack = portLibrary->mem_allocate_memory(portLibrary, len);
         canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
 
         strcpy(canonicalpath,"\\\\?\\");
@@ -382,34 +388,13 @@
         }
         
         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);
+        returnVar = CreateDirectory (canonicalpath, 0);
+        
         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.
- *
- * @param[in] portLibrary The port library
- * @param[in] path Directory to be created.
- *
- * @return 0 on success, -1 on failure.
- * @note Assumes all components of path up to the last directory already exist. 
- * @internal @todo return negative portable return code on failure.
- */
-I_32 VMCALL
-hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
-{
-	int returnVar=0;
-	wchar_t *pathW;
-	convert_path_to_unicode(portLibrary, path, &pathW);
-	returnVar = CreateDirectoryW (pathW, 0);
-	portLibrary->mem_free_memory(portLibrary, pathW);
+    }else{
+        returnVar = CreateDirectory (path, 0);
+    }
 
 	if (returnVar)
 	{
@@ -774,25 +759,20 @@
 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 == SetFileAttributesW (pathW, FILE_ATTRIBUTE_NORMAL))
+  if (0 == SetFileAttributes (path, FILE_ATTRIBUTE_NORMAL))
     {
       I_32 error = GetLastError ();
       portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue
*/
     }
 
-  if (RemoveDirectoryW (pathW))
+  if (RemoveDirectory (path))
     {
-      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;



Mime
View raw message