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/03/05 08:43:51 UTC
svn commit: r514590 - in /harmony/enhanced/classlib/trunk/modules:
luni/src/test/java/tests/api/java/io/FileTest.java
portlib/src/main/native/port/windows/hyfile.c
Author: pyang
Date: Sun Mar 4 23:43:50 2007
New Revision: 514590
URL: http://svn.apache.org/viewvc?view=rev&rev=514590
Log:
Apply patch for HARMONY-2157 ( [classlib][luni]not able to make a directory whose length is greater than 248)
Modified:
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/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=514590&r1=514589&r2=514590
==============================================================================
--- 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 Sun Mar 4 23:43:50 2007
@@ -1789,30 +1789,57 @@
/**
* @tests java.io.File#mkdir()
*/
- public void test_mkdir() {
- // Test for method boolean java.io.File.mkdir()
+ public void test_mkdir() throws IOException {
+ // Test for method boolean java.io.File.mkdir()
- 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;
- }
- }
- try {
- assertTrue("mkdir failed", dir.mkdir() && dir.exists());
- } finally {
- dir.delete();
- }
- }
+ 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 longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars
+ StringBuilder sb = new StringBuilder(dir + File.separator);
+ StringBuilder sb2 = new StringBuilder(dir + File.separator);
+
+ // Test make a long path
+ while (dir.getCanonicalPath().length() < 256 - longDirName.length()) {
+ sb.append(longDirName + File.separator);
+ dir = new File(sb.toString());
+ assertTrue("mkdir failed", dir.mkdir() && dir.exists());
+ dir.deleteOnExit();
+ }
+
+ while (dir.getCanonicalPath().length() < 256) {
+ sb.append(0);
+ dir = new File(sb.toString());
+ assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
+ dir.mkdir() && dir.exists());
+ dir.deleteOnExit();
+ }
+
+ // Test make many paths
+ while (dir.getCanonicalPath().length() < 256) {
+ sb2.append(0);
+ dir = new File(sb2.toString());
+ assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
+ dir.mkdir() && dir.exists());
+ dir.deleteOnExit();
+ }
+ }
/**
* @tests java.io.File#mkdirs()
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=514590&r1=514589&r2=514590
==============================================================================
--- 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 Sun Mar 4 23:43:50 2007
@@ -339,11 +339,66 @@
I_32 VMCALL
hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
{
- if (CreateDirectory (path, 0))
- {
+ 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);
+ }
+
+ if (returnVar)
+ {
return 0;
}
- else
+ else
{
I_32 error = GetLastError ();
portLibrary->error_set_last_error (portLibrary, error,