skip "." and ".." in File.list{Files} to match Sun

This commit is contained in:
Joel Dice
2010-01-09 19:18:39 -07:00
parent 585dba004b
commit b1a1391093

View File

@ -452,13 +452,19 @@ Java_java_io_File_readDir(JNIEnv* e, jclass, jlong handle)
{ {
Directory* d = reinterpret_cast<Directory*>(handle); Directory* d = reinterpret_cast<Directory*>(handle);
while (true) {
const char* s = d->next(); const char* s = d->next();
if (s) { if (s) {
if (strcmp(s, ".") == 0 || strcmp(s, "..") == 0) {
// skip . or .. and try again
} else {
return e->NewStringUTF(s); return e->NewStringUTF(s);
}
} else { } else {
return 0; return 0;
} }
} }
}
extern "C" JNIEXPORT void JNICALL extern "C" JNIEXPORT void JNICALL
Java_java_io_File_closeDir(JNIEnv* , jclass, jlong handle) Java_java_io_File_closeDir(JNIEnv* , jclass, jlong handle)
@ -487,12 +493,19 @@ Java_java_io_File_readDir(JNIEnv* e, jclass, jlong handle)
struct dirent * directoryEntry; struct dirent * directoryEntry;
if (handle!=0) { if (handle!=0) {
while (true) {
directoryEntry = readdir(reinterpret_cast<DIR*>(handle)); directoryEntry = readdir(reinterpret_cast<DIR*>(handle));
if (directoryEntry == NULL) { if (directoryEntry == NULL) {
return NULL; return NULL;
} } else if (strcmp(directoryEntry->d_name, ".") == 0
|| strcmp(directoryEntry->d_name, "..") == 0)
{
// skip . or .. and try again
} else {
return e->NewStringUTF(directoryEntry->d_name); return e->NewStringUTF(directoryEntry->d_name);
} }
}
}
return NULL; return NULL;
} }