Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 8-13
Link Here
|
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
10 |
* Red Hat Incorporated - get/setResourceAttribute code |
10 |
* Red Hat Incorporated - get/setResourceAttribute code |
|
|
11 |
* Martin Oberhuber (Wind River) - [170317] add symbolic link support to API |
11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
12 |
#include <jni.h> |
13 |
#include <jni.h> |
13 |
#include <sys/types.h> |
14 |
#include <sys/types.h> |
Lines 17-22
Link Here
|
17 |
#include <string.h> |
18 |
#include <string.h> |
18 |
#include "../localfile.h" |
19 |
#include "../localfile.h" |
19 |
#include <os_custom.h> |
20 |
#include <os_custom.h> |
|
|
21 |
#ifdef LINUX |
22 |
#include <limits.h> |
23 |
#include <unistd.h> |
24 |
#endif |
20 |
|
25 |
|
21 |
/* |
26 |
/* |
22 |
* Get a null-terminated byte array from a java byte array. |
27 |
* Get a null-terminated byte array from a java byte array. |
Lines 94-108
Link Here
|
94 |
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_EXECUTABLE, JNI_TRUE); |
99 |
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_EXECUTABLE, JNI_TRUE); |
95 |
} |
100 |
} |
96 |
|
101 |
|
97 |
// sym link? |
|
|
98 |
// if ((info.st_mode & S_IFLNK) == S_IFLNK) { |
99 |
// mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V"); |
100 |
// if (mid == 0) return JNI_FALSE; |
101 |
// (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK, JNI_TRUE); |
102 |
// } |
103 |
return JNI_TRUE; |
102 |
return JNI_TRUE; |
104 |
} |
103 |
} |
105 |
|
104 |
|
|
|
105 |
#ifdef LINUX |
106 |
/* |
107 |
* Set symbolic link information in IFileInfo |
108 |
*/ |
109 |
jboolean setSymlinkInFileInfo (JNIEnv *env, jobject fileInfo, jstring linkTarget) { |
110 |
jclass cls; |
111 |
jmethodID mid; |
112 |
|
113 |
cls = (*env)->GetObjectClass(env, fileInfo); |
114 |
if (cls == 0) return JNI_FALSE; |
115 |
|
116 |
// set symlink attribute |
117 |
mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V"); |
118 |
if (mid == 0) return JNI_FALSE; |
119 |
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_SYMLINK, JNI_TRUE); |
120 |
|
121 |
// set link target |
122 |
mid = (*env)->GetMethodID(env, cls, "setStringAttribute", "(ILjava/lang/String;)V"); |
123 |
if (mid == 0) return JNI_FALSE; |
124 |
(*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK_TARGET, linkTarget); |
125 |
} |
126 |
#endif |
127 |
|
106 |
/* |
128 |
/* |
107 |
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives |
129 |
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives |
108 |
* Method: internalGetFileInfo |
130 |
* Method: internalGetFileInfo |
Lines 114-123
Link Here
|
114 |
jlong result; |
136 |
jlong result; |
115 |
jint code; |
137 |
jint code; |
116 |
jbyte *name; |
138 |
jbyte *name; |
|
|
139 |
jstring linkTarget = NULL; |
117 |
|
140 |
|
118 |
/* get stat */ |
141 |
/* get stat */ |
119 |
name = getByteArray(env, target); |
142 |
name = getByteArray(env, target); |
|
|
143 |
#ifdef LINUX |
144 |
//do an lstat first to see if it is a symbolic link |
145 |
code = lstat((const char*)name, &info); |
146 |
if (code == 0 && (info.st_mode & S_IFLNK) == S_IFLNK) { |
147 |
//symbolic link: read link target |
148 |
char buf[PATH_MAX+1]; |
149 |
int len; |
150 |
len = readlink((const char*)name, buf, PATH_MAX); |
151 |
if (len>0) { |
152 |
buf[len]=0; |
153 |
} else { |
154 |
buf[0]=0; |
155 |
} |
156 |
//TODO find a way for creating Strings from encodings other than UTF-8 |
157 |
//On Linux, UTF8 is fine since this is the default platform encoding. |
158 |
//Other platforms may be problematic since accessing Java classes |
159 |
//(for Converters) doesnt work through the OSGi classloaders. |
160 |
linkTarget = (*env)->NewStringUTF(env, buf); |
161 |
setSymlinkInFileInfo(env, fileInfo, linkTarget); |
162 |
|
163 |
//stat link target (will fail for broken links) |
164 |
code = stat((const char*)name, &info); |
165 |
} |
166 |
#else |
120 |
code = stat((const char*)name, &info); |
167 |
code = stat((const char*)name, &info); |
|
|
168 |
#endif |
121 |
free(name); |
169 |
free(name); |
122 |
|
170 |
|
123 |
/* test if an error occurred */ |
171 |
/* test if an error occurred */ |