Skip to content

Commit 7ff7a58

Browse files
committed
Remove unused (native) code in Windows LocalFileNatives
Unicode support was assumed to be present if the Windows-OS version is greater or equal five, which corresponds to Windows 2000 or later [1]. Because parts of the removed and remaining native code call methods that are only available on Windows XP/Server 2003 or later, for example 'FindFirstFileA()' (the code says 'FindFirstFile' but it is linked to 'FindFirstFileA') respectively 'FindFirstFileW()', it is save to assume Unicode is always supported. All methods that check it or handle an alternative encoding are effectively dead code and can be removed. Furthermore only 64-bit artifacts are provided now and 64-bit CPU are not supported before Windows XP, too. Also remove build-scripts for CPU architectures not supported anymore and java and native code that is not called (anymore). [1] - https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfow
1 parent ad89d5c commit 7ff7a58

File tree

8 files changed

+16
-490
lines changed

8 files changed

+16
-490
lines changed

resources/bundles/org.eclipse.core.filesystem/natives/localfile.h

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2012 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -51,22 +51,6 @@ extern "C" {
5151
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_nativeAttributes
5252
(JNIEnv *, jclass);
5353

54-
/*
55-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
56-
* Method: internalIsUnicode
57-
* Signature: ()Z
58-
*/
59-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalIsUnicode
60-
(JNIEnv *, jclass);
61-
62-
/*
63-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
64-
* Method: internalGetFileInfo
65-
* Signature: ([CLorg/eclipse/core/filesystem/IFileInfo;)Z
66-
*/
67-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalGetFileInfo
68-
(JNIEnv *env, jclass clazz, jbyteArray target, jobject fileInfo);
69-
7054
/*
7155
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
7256
* Method: internalGetFileInfoW
@@ -75,30 +59,6 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_Local
7559
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalGetFileInfoW
7660
(JNIEnv *env, jclass clazz, jcharArray target, jobject fileInfo);
7761

78-
/*
79-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
80-
* Method: internalCopyAttributes
81-
* Signature: ([B[BZ)Z
82-
*/
83-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributes
84-
(JNIEnv *env, jclass clazz, jbyteArray source, jbyteArray destination, jboolean copyLastModified);
85-
86-
/*
87-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
88-
* Method: internalCopyAttributesW
89-
* Signature: ([C[CZ)Z
90-
*/
91-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributesW
92-
(JNIEnv *env, jclass clazz, jcharArray source, jcharArray destination, jboolean copyLastModified);
93-
94-
/*
95-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
96-
* Method: internalSetFileInfo
97-
* Signature: ([BLorg/eclipse/core/filesystem/IFileInfo;)Z
98-
*/
99-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalSetFileInfo
100-
(JNIEnv *env, jclass clazz, jcharArray target, jobject obj);
101-
10262
/*
10363
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
10464
* Method: internalSetFileInfoW

resources/bundles/org.eclipse.core.filesystem/natives/win32/ia64/make_IA64.bat

Lines changed: 0 additions & 24 deletions
This file was deleted.

resources/bundles/org.eclipse.core.filesystem/natives/win32/localfile.c

Lines changed: 0 additions & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,6 @@ jlong fileTimeToMillis(FILETIME ft) {
6969
return millis;
7070
}
7171

72-
/*
73-
* Get a null-terminated byte array from a java byte array.
74-
* The returned bytearray needs to be freed when not used
75-
* anymore. Use free(result) to do that.
76-
*/
77-
jbyte* getByteArray(JNIEnv *env, jbyteArray target) {
78-
jsize n;
79-
jbyte *temp, *result;
80-
81-
temp = (*env)->GetByteArrayElements(env, target, 0);
82-
n = (*env)->GetArrayLength(env, target);
83-
result = malloc((n+1) * sizeof(jbyte));
84-
memcpy(result, temp, n * sizeof(jbyte));
85-
result[n] = '\0';
86-
(*env)->ReleaseByteArrayElements(env, target, temp, 0);
87-
return result;
88-
}
89-
9072
/*
9173
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
9274
* Method: nativeAttributes
@@ -104,24 +86,6 @@ JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFile
10486
return attributes;
10587
}
10688

107-
/*
108-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
109-
* Method: internalIsUnicode
110-
* Signature: ()Z
111-
*/
112-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalIsUnicode
113-
(JNIEnv *env, jclass clazz) {
114-
OSVERSIONINFO osvi;
115-
memset(&osvi, 0, sizeof(OSVERSIONINFO));
116-
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
117-
if (!GetVersionEx (&osvi))
118-
return JNI_FALSE;
119-
// only Windows NT 4, Windows 2K and XP support Unicode API calls
120-
if (!(osvi.dwMajorVersion >= 5 || (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4)))
121-
return JNI_FALSE;
122-
return JNI_TRUE;
123-
}
124-
12589
/*
12690
* Get a null-terminated short array from a java char array.
12791
* The returned short array needs to be freed when not used
@@ -140,93 +104,6 @@ jchar* getCharArray(JNIEnv *env, jcharArray target) {
140104
return result;
141105
}
142106

143-
/*
144-
* Returns a Java string object for a given windows character string
145-
*/
146-
jstring windowsTojstring( JNIEnv* env, char* str )
147-
{
148-
jstring rtn = 0;
149-
int slen = strlen(str);
150-
wchar_t* buffer = 0;
151-
if( slen == 0 )
152-
rtn = (*env)->NewStringUTF( env, str ); //UTF ok since empty string
153-
else
154-
{
155-
int length =
156-
MultiByteToWideChar( CP_ACP, 0, (LPCSTR)str, slen, NULL, 0 );
157-
buffer = malloc( length*2 + 1 );
158-
if( MultiByteToWideChar( CP_ACP, 0, (LPCSTR)str, slen,
159-
(LPWSTR)buffer, length ) >0 )
160-
rtn = (*env)->NewString( env, (jchar*)buffer, length );
161-
}
162-
if( buffer )
163-
free( buffer );
164-
return rtn;
165-
}
166-
167-
/*
168-
* Converts a WIN32_FIND_DATA to IFileInfo
169-
*/
170-
jboolean convertFindDataToFileInfo(JNIEnv *env, WIN32_FIND_DATA info, jobject fileInfo) {
171-
jclass cls;
172-
jmethodID mid;
173-
ULONGLONG fileLength;
174-
175-
cls = (*env)->GetObjectClass(env, fileInfo);
176-
if (cls == 0) return JNI_FALSE;
177-
178-
// select interesting information
179-
//exists
180-
mid = (*env)->GetMethodID(env, cls, "setExists", "(Z)V");
181-
if (mid == 0) return JNI_FALSE;
182-
(*env)->CallVoidMethod(env, fileInfo, mid, JNI_TRUE);
183-
184-
// file name
185-
mid = (*env)->GetMethodID(env, cls, "setName", "(Ljava/lang/String;)V");
186-
if (mid == 0) return JNI_FALSE;
187-
(*env)->CallVoidMethod(env, fileInfo, mid, windowsTojstring(env, info.cFileName));
188-
189-
// last modified
190-
mid = (*env)->GetMethodID(env, cls, "setLastModified", "(J)V");
191-
if (mid == 0) return JNI_FALSE;
192-
(*env)->CallVoidMethod(env, fileInfo, mid, fileTimeToMillis(info.ftLastWriteTime));
193-
194-
// file length
195-
fileLength =(info.nFileSizeHigh * (((ULONGLONG)MAXDWORD)+1)) + info.nFileSizeLow;
196-
mid = (*env)->GetMethodID(env, cls, "setLength", "(J)V");
197-
if (mid == 0) return JNI_FALSE;
198-
(*env)->CallVoidMethod(env, fileInfo, mid, fileLength);
199-
200-
// folder or file?
201-
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
202-
mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
203-
if (mid == 0) return JNI_FALSE;
204-
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_DIRECTORY, JNI_TRUE);
205-
}
206-
207-
// read-only?
208-
if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
209-
mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
210-
if (mid == 0) return JNI_FALSE;
211-
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_READ_ONLY, JNI_TRUE);
212-
}
213-
214-
// archive?
215-
if (info.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
216-
mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
217-
if (mid == 0) return JNI_FALSE;
218-
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_ARCHIVE, JNI_TRUE);
219-
}
220-
221-
// hidden?
222-
if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
223-
mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
224-
if (mid == 0) return JNI_FALSE;
225-
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_HIDDEN, JNI_TRUE);
226-
}
227-
return JNI_TRUE;
228-
}
229-
230107
/*
231108
* Set symbolic link information in IFileInfo
232109
*/
@@ -398,38 +275,6 @@ jboolean setIOError(JNIEnv *env, jobject fileInfo) {
398275
return JNI_TRUE;
399276
}
400277

401-
/*
402-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
403-
* Method: internalGetFileInfo
404-
* Signature: ([CLorg/eclipse/core/filesystem/IFileInfo;)Z
405-
*/
406-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalGetFileInfo
407-
(JNIEnv *env, jclass clazz, jbyteArray target, jobject fileInfo) {
408-
jbyte *name;
409-
jsize size;
410-
HANDLE handle;
411-
WIN32_FIND_DATA info;
412-
413-
name = getByteArray(env, target);
414-
size = (*env)->GetArrayLength(env, target);
415-
// FindFirstFile does not work at the root level. However, we
416-
// don't need it because the root will never change timestamp
417-
// The pattern \\?\c:\ represents a root path
418-
if (size == 7 && name[2] == '?' && name[5] == ':' && name[6] == '\\') {
419-
free(name);
420-
return fillEmptyDirectory(env, fileInfo);
421-
}
422-
handle = FindFirstFile(name, &info);
423-
free(name);
424-
if (handle == INVALID_HANDLE_VALUE) {
425-
if (GetLastError() != ERROR_FILE_NOT_FOUND)
426-
setIOError(env, fileInfo);
427-
return JNI_FALSE;
428-
}
429-
FindClose(handle);
430-
return convertFindDataToFileInfo(env, info, fileInfo);
431-
}
432-
433278
/*
434279
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
435280
* Method: internalGetFileInfoW
@@ -466,127 +311,6 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_Local
466311
return result;
467312
}
468313

469-
/*
470-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
471-
* Method: internalCopyAttributes
472-
* Signature: ([B[BZ)Z
473-
*/
474-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributes
475-
(JNIEnv *env, jclass clazz, jbyteArray source, jbyteArray destination, jboolean copyLastModified) {
476-
477-
HANDLE handle;
478-
WIN32_FIND_DATA info;
479-
jbyte *sourceFile, *destinationFile;
480-
int success = 1;
481-
482-
sourceFile = getByteArray(env, source);
483-
destinationFile = getByteArray(env, destination);
484-
485-
handle = FindFirstFile(sourceFile, &info);
486-
if (handle != INVALID_HANDLE_VALUE) {
487-
success = SetFileAttributes(destinationFile, info.dwFileAttributes);
488-
if (success != 0 && copyLastModified) {
489-
// does not honor copyLastModified
490-
// call to SetFileTime should pass file handle instead of file name
491-
// success = SetFileTime(destinationFile, &info.ftCreationTime, &info.ftLastAccessTime, &info.ftLastWriteTime);
492-
}
493-
} else {
494-
success = 0;
495-
}
496-
497-
free(sourceFile);
498-
free(destinationFile);
499-
FindClose(handle);
500-
return success;
501-
}
502-
503-
/*
504-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
505-
* Method: internalCopyAttributesW
506-
* Signature: ([C[CZ)Z
507-
*/
508-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributesW
509-
(JNIEnv *env, jclass clazz, jcharArray source, jcharArray destination, jboolean copyLastModified) {
510-
511-
HANDLE handle;
512-
WIN32_FIND_DATAW info;
513-
jchar *sourceFile, *destinationFile;
514-
int success = 1;
515-
516-
sourceFile = getCharArray(env, source);
517-
destinationFile = getCharArray(env, destination);
518-
519-
handle = FindFirstFileW(sourceFile, &info);
520-
521-
if (handle != INVALID_HANDLE_VALUE) {
522-
success = SetFileAttributesW(destinationFile, info.dwFileAttributes);
523-
if (success != 0 && copyLastModified) {
524-
// does not honor copyLastModified
525-
// call to SetFileTime should pass file handle instead of file name
526-
// success = SetFileTime(destinationFile, &info.ftCreationTime, &info.ftLastAccessTime, &info.ftLastWriteTime);
527-
}
528-
} else {
529-
success = 0;
530-
}
531-
532-
free(sourceFile);
533-
free(destinationFile);
534-
FindClose(handle);
535-
return success;
536-
}
537-
538-
/*
539-
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
540-
* Method: internalSetFileInfo
541-
* Signature: ([BLorg/eclipse/core/filesystem/IFileInfo;)Z
542-
*/
543-
JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalSetFileInfo
544-
(JNIEnv *env, jclass clazz, jcharArray target, jobject obj) {
545-
546-
HANDLE handle;
547-
jbyte *targetFile;
548-
jmethodID mid;
549-
int success = JNI_FALSE;
550-
DWORD attributes;
551-
jboolean readOnly, hidden, archive;
552-
jclass cls;
553-
554-
/* find out if we need to set the readonly bit */
555-
cls = (*env)->GetObjectClass(env, obj);
556-
mid = (*env)->GetMethodID(env, cls, "getAttribute", "(I)Z");
557-
if (mid == 0) goto fail;
558-
readOnly = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_READ_ONLY);
559-
560-
/* find out if we need to set the archive bit */
561-
archive = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_ARCHIVE);
562-
563-
/* find out if we need to set the hidden bit */
564-
hidden = (*env)->CallBooleanMethod(env, obj, mid, ATTRIBUTE_HIDDEN);
565-
566-
targetFile = getByteArray(env, target);
567-
attributes = GetFileAttributes(targetFile);
568-
if (attributes == (DWORD)-1) goto fail;
569-
570-
if (readOnly)
571-
attributes = attributes | FILE_ATTRIBUTE_READONLY;
572-
else
573-
attributes = attributes & ~FILE_ATTRIBUTE_READONLY;
574-
if (archive)
575-
attributes = attributes | FILE_ATTRIBUTE_ARCHIVE;
576-
else
577-
attributes = attributes & ~FILE_ATTRIBUTE_ARCHIVE;
578-
if (hidden)
579-
attributes = attributes | FILE_ATTRIBUTE_HIDDEN;
580-
else
581-
attributes = attributes & ~FILE_ATTRIBUTE_HIDDEN;
582-
583-
success = SetFileAttributes(targetFile, attributes);
584-
585-
fail:
586-
free(targetFile);
587-
return success;
588-
}
589-
590314
/*
591315
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
592316
* Method: internalSetFileInfoW

0 commit comments

Comments
 (0)