View | Details | Raw Unified | Return to bug 314448
Collapse All | Expand All

(-)natives/unix/unixfile.c (-1 / +5 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [314448] error on exists() for non-accessible
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
#include <stdlib.h>
13
#include <stdlib.h>
Lines 138-143 Link Here
138
 * Class:     org_eclipse_core_internal_filesystem_local_unix_UnixFileNatives
139
 * Class:     org_eclipse_core_internal_filesystem_local_unix_UnixFileNatives
139
 * Method:    lstat
140
 * Method:    lstat
140
 * Signature: ([BLorg/eclipse/core/internal/filesystem/local/unix/StructStat;)I
141
 * Signature: ([BLorg/eclipse/core/internal/filesystem/local/unix/StructStat;)I
142
 * returns:   0 on success, -1 on error converting to Java, -2 if file does not exist, or errno code on file access error
141
 */
143
 */
142
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_filesystem_local_unix_UnixFileNatives_lstat
144
JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_filesystem_local_unix_UnixFileNatives_lstat
143
  (JNIEnv *env, jclass clazz, jbyteArray path, jobject buf)
145
  (JNIEnv *env, jclass clazz, jbyteArray path, jobject buf)
Lines 151-158 Link Here
151
	free(name);
153
	free(name);
152
	if (code != -1)
154
	if (code != -1)
153
		return convertStatToObject(env, info, buf);
155
		return convertStatToObject(env, info, buf);
156
	else if (errno == ENOENT)
157
		return -2; /* file does not exist */
154
	else
158
	else
155
		return code;
159
		return errno;
156
}
160
}
157
161
158
/*
162
/*
(-)src/org/eclipse/core/internal/filesystem/local/LocalFile.java (-8 / +16 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [294429] Avoid substring baggage in FileInfo
10
 * Martin Oberhuber (Wind River) - [294429] Avoid substring baggage in FileInfo
11
 * Martin Oberhuber (Wind River) - [314448] error on exists() for non-accessible
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.core.internal.filesystem.local;
13
package org.eclipse.core.internal.filesystem.local;
13
14
Lines 139-145 Link Here
139
		return file.equals(otherFile.file);
140
		return file.equals(otherFile.file);
140
	}
141
	}
141
142
142
	public IFileInfo fetchInfo(int options, IProgressMonitor monitor) {
143
	public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
143
		if (LocalFileNativesManager.isUsingNatives()) {
144
		if (LocalFileNativesManager.isUsingNatives()) {
144
			FileInfo info = LocalFileNativesManager.fetchFileInfo(filePath);
145
			FileInfo info = LocalFileNativesManager.fetchFileInfo(filePath);
145
			//natives don't set the file name on all platforms
146
			//natives don't set the file name on all platforms
Lines 212-218 Link Here
212
		if (monitor.isCanceled()) {
213
		if (monitor.isCanceled()) {
213
			throw new OperationCanceledException();
214
			throw new OperationCanceledException();
214
		}
215
		}
215
		if (target.delete() || !target.exists())
216
		if (target.delete())
216
			return true;
217
			return true;
217
		if (target.isDirectory()) {
218
		if (target.isDirectory()) {
218
			monitor.subTask(NLS.bind(Messages.deleting, target));
219
			monitor.subTask(NLS.bind(Messages.deleting, target));
Lines 246-258 Link Here
246
				return false;
247
				return false;
247
			}
248
			}
248
		}
249
		}
249
		//if we got this far, we failed
250
		//if we got this far, we failed or the file never existed 
250
		String message = null;
251
		String message = null;
251
		if (fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY))
252
		try {
252
			message = NLS.bind(Messages.couldnotDeleteReadOnly, target.getAbsolutePath());
253
			IFileInfo info = fetchInfo(EFS.NONE, monitor);
253
		else
254
			if (!info.exists())
254
			message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath());
255
				return true;
255
		status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null));
256
			else if (info.getAttribute(EFS.ATTRIBUTE_READ_ONLY))
257
				message = NLS.bind(Messages.couldnotDeleteReadOnly, target.getAbsolutePath());
258
			else
259
				message = NLS.bind(Messages.couldnotDelete, target.getAbsolutePath());
260
			status.add(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_DELETE, message, null));
261
		} catch (CoreException ce) {
262
			status.add(ce.getStatus());
263
		}
256
		return false;
264
		return false;
257
	}
265
	}
258
266
(-)src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java (-1 / +3 lines)
Lines 7-18 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [314448] error on exists() for non-accessible
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.filesystem.local;
12
package org.eclipse.core.internal.filesystem.local;
12
13
13
import org.eclipse.core.filesystem.IFileInfo;
14
import org.eclipse.core.filesystem.IFileInfo;
14
import org.eclipse.core.filesystem.provider.FileInfo;
15
import org.eclipse.core.filesystem.provider.FileInfo;
15
import org.eclipse.core.internal.filesystem.local.unix.UnixFileNatives;
16
import org.eclipse.core.internal.filesystem.local.unix.UnixFileNatives;
17
import org.eclipse.core.runtime.CoreException;
16
18
17
/**
19
/**
18
 * Dispatches methods backed by native code to the appropriate platform specific 
20
 * Dispatches methods backed by native code to the appropriate platform specific 
Lines 26-32 Link Here
26
		return LocalFileNatives.attributes();
28
		return LocalFileNatives.attributes();
27
	}
29
	}
28
30
29
	public static FileInfo fetchFileInfo(String fileName) {
31
	public static FileInfo fetchFileInfo(String fileName) throws CoreException {
30
		if (UnixFileNatives.isUsingNatives())
32
		if (UnixFileNatives.isUsingNatives())
31
			return UnixFileNatives.fetchFileInfo(fileName);
33
			return UnixFileNatives.fetchFileInfo(fileName);
32
		return LocalFileNatives.fetchFileInfo(fileName);
34
		return LocalFileNatives.fetchFileInfo(fileName);
(-)src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java (-4 / +10 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [314448] error on exists() for non-accessible
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.filesystem.local.unix;
12
package org.eclipse.core.internal.filesystem.local.unix;
12
13
Lines 17-23 Link Here
17
import org.eclipse.core.filesystem.provider.FileInfo;
18
import org.eclipse.core.filesystem.provider.FileInfo;
18
import org.eclipse.core.internal.filesystem.*;
19
import org.eclipse.core.internal.filesystem.*;
19
import org.eclipse.core.internal.filesystem.local.Convert;
20
import org.eclipse.core.internal.filesystem.local.Convert;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.*;
21
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.osgi.util.NLS;
22
23
23
public abstract class UnixFileNatives {
24
public abstract class UnixFileNatives {
Lines 66-76 Link Here
66
		return ret;
67
		return ret;
67
	}
68
	}
68
69
69
	public static FileInfo fetchFileInfo(String fileName) {
70
	public static FileInfo fetchFileInfo(String fileName) throws CoreException {
70
		FileInfo info = null;
71
		FileInfo info = null;
71
		byte[] name = fileNameToBytes(fileName);
72
		byte[] name = fileNameToBytes(fileName);
72
		StructStat stat = new StructStat();
73
		StructStat stat = new StructStat();
73
		if (lstat(name, stat) == 0) {
74
		int errno = lstat(name, stat);
75
		if (errno == 0) {
74
			if ((stat.st_mode & UnixFileFlags.S_IFMT) == UnixFileFlags.S_IFLNK) {
76
			if ((stat.st_mode & UnixFileFlags.S_IFMT) == UnixFileFlags.S_IFLNK) {
75
				if (stat(name, stat) == 0)
77
				if (stat(name, stat) == 0)
76
					info = stat.toFileInfo();
78
					info = stat.toFileInfo();
Lines 83-90 Link Here
83
					info.setStringAttribute(EFS.ATTRIBUTE_LINK_TARGET, bytesToFileName(target, (int) length));
85
					info.setStringAttribute(EFS.ATTRIBUTE_LINK_TARGET, bytesToFileName(target, (int) length));
84
			} else
86
			} else
85
				info = stat.toFileInfo();
87
				info = stat.toFileInfo();
86
		} else
88
		} else if (errno == -2) {
89
			//file does not exist
87
			info = new FileInfo();
90
			info = new FileInfo();
91
		} else {
92
			throw new CoreException(new Status(IStatus.ERROR, Policy.PI_FILE_SYSTEM, EFS.ERROR_READ, "errno: " + info, null)); //$NON-NLS-1$
93
		}
88
		return info;
94
		return info;
89
	}
95
	}
90
96

Return to bug 314448