Bug 514835 - Provide more detailed reason for failing mkdir operation
Change-Id: I898cf700af408e438dbd12db64224216ac404f2b
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/Messages.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/Messages.java
index e821bc1..4832c68 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/Messages.java
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/Messages.java
@@ -28,6 +28,7 @@
public static String deleteProblem;
public static String deleting;
public static String failedCreateWrongType;
+ public static String failedCreateAccessDenied;
public static String failedMove;
public static String failedReadDuringWrite;
public static String fileExists;
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java
index 207db1a..47ff69d 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java
@@ -96,22 +96,6 @@
}
}
- /**
- * This method is called after a failure to modify a directory.
- * Check to see if the target does not exist (e.g. device doesn't not exist) and if so then
- * throw an exception with a more specific message and error code.
- *
- * @param target The directory that we failed to modify
- * @param exception The low level exception that occurred, or <code>null</code>
- * @throws CoreException A more specific exception if the target does not exist
- */
- private void checkTargetDoesNotExist(File target, Throwable exception) throws CoreException {
- if (!target.exists()) {
- String message = NLS.bind(Messages.fileNotFound, target.getAbsolutePath());
- Policy.error(EFS.ERROR_WRITE, message, exception);
- }
- }
-
@Override
public String[] childNames(int options, IProgressMonitor monitor) {
String[] names = file.list();
@@ -327,12 +311,25 @@
String message = NLS.bind(Messages.failedCreateWrongType, filePath);
Policy.error(EFS.ERROR_WRONG_TYPE, message, e);
}
+ } catch (AccessDeniedException e) {
+ if (!file.isDirectory()) {
+ checkReadOnlyParent(file, e);
+ String message = NLS.bind(Messages.failedCreateAccessDenied, filePath);
+ Policy.error(EFS.ERROR_AUTH_FAILED, message, e);
+ }
+ } catch (NoSuchFileException e) {
+ if (!file.isDirectory()) {
+ String parentPath = file.getParent();
+ String message = NLS.bind(Messages.fileNotFound, parentPath != null ? parentPath : filePath);
+ Policy.error(EFS.ERROR_NOT_EXISTS, message, e);
+ }
} catch (IOException e) {
- checkReadOnlyParent(file, e);
- checkTargetDoesNotExist(file, e);
- checkTargetIsNotWritable(file, e);
- String message = NLS.bind(Messages.failedCreateWrongType, filePath);
- Policy.error(EFS.ERROR_WRONG_TYPE, message, e);
+ if (!file.isDirectory()) {
+ checkReadOnlyParent(file, e);
+ checkTargetIsNotWritable(file, e);
+ String message = NLS.bind(Messages.couldNotWrite, filePath);
+ Policy.error(EFS.ERROR_WRITE, message, e);
+ }
}
return this;
}
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/messages.properties b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/messages.properties
index 98aca60..64f8602 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/messages.properties
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/messages.properties
@@ -19,6 +19,7 @@
couldNotWrite = Could not write file: {0}.
deleteProblem = Problems encountered while deleting files.
deleting = Deleting: {0}.
+failedCreateAccessDenied=Cannot create file, access denied: {0}.
failedCreateWrongType=Cannot create file because existing file of wrong type exists: {0}.
failedMove = Critical failure moving: {0} to: {1}. Content is lost.
failedReadDuringWrite = Could not read from source when writing file: {0}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/CreateDirectoryTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/CreateDirectoryTest.java
index 3a6110c..277d7b5 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/CreateDirectoryTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/CreateDirectoryTest.java
@@ -129,7 +129,7 @@
fail("1.99");
} catch (CoreException e) {
assertNotNull("1.1", e.getStatus());
- assertEquals("1.2", EFS.ERROR_WRITE, e.getStatus().getCode());
+ assertEquals("1.2", EFS.ERROR_NOT_EXISTS, e.getStatus().getCode());
}
}