From 1b500f829b619a27a323fd64317f1746197a3758 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Fri, 21 Mar 2014 13:18:32 -0400 Subject: [PATCH] [429668] - Avoid race condition causing mkdir to fail. Signed-off-by: Greg Watson --- .../internal/jsch/core/JschFileStore.java | 46 ++++++++++++------- .../internal/jsch/core/messages/Messages.java | 4 +- .../jsch/core/messages/messages.properties | 3 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java index e779ca2b72d..6493afa25e6 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java @@ -217,23 +217,37 @@ public class JschFileStore extends FileStore { JSchConnection connection = checkConnection(); SubMonitor subMon = SubMonitor.convert(monitor, 20); - IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); - if (!subMon.isCanceled()) { - if (!info.exists()) { - if ((options & EFS.SHALLOW) == EFS.SHALLOW) { - IFileStore parent = getParent(); - if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(10)).exists()) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE, - NLS.bind(Messages.JschFileStore_The_parent_of_directory_does_not_exist, fRemotePath.toString()), - null)); - } - } + if ((options & EFS.SHALLOW) == EFS.SHALLOW) { + IFileStore parent = getParent(); + if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(10)).exists()) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE, NLS.bind( + Messages.JschFileStore_The_parent_of_directory_does_not_exist, fRemotePath.toString()), null)); + } + if (subMon.isCanceled()) { + return this; + } + } - MkdirCommand command = new MkdirCommand(connection, fRemotePath); - command.getResult(subMon.newChild(10)); - } else if (!info.isDirectory()) { - throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE, NLS.bind( - Messages.JschFileStore_The_file_of_name_already_exists, fRemotePath.toString()), null)); + try { + MkdirCommand command = new MkdirCommand(connection, fRemotePath); + command.getResult(subMon.newChild(10)); + } catch (Exception e) { + // Ignore any exceptions + } + if (!subMon.isCanceled()) { + /* + * Check if the result exists and is a directory, throw an exception if neither. + */ + IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); + if (!subMon.isCanceled()) { + if (!info.exists()) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE, NLS.bind( + Messages.JschFileStore_The_directory_could_not_be_created, fRemotePath.toString()), null)); + } + if (!info.isDirectory()) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE, + NLS.bind(Messages.JschFileStore_A_file_of_name_already_exists, fRemotePath.toString()), null)); + } } } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java index 8a42c09de63..3d10969ecee 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java @@ -44,7 +44,9 @@ public class Messages extends NLS { public static String JschFileStore_Invalid_connection_for_URI; public static String JschFileStore_Is_a_directory; public static String JschFileStore_No_remote_services_found_for_URI; - public static String JschFileStore_The_file_of_name_already_exists; + public static String JschFileStore_The_directory_could_not_be_created; + + public static String JschFileStore_A_file_of_name_already_exists; public static String JschFileStore_The_parent_of_directory_does_not_exist; static { diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties index 40339a21517..aaf04dad113 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties @@ -34,5 +34,6 @@ JschFileStore_File_doesnt_exist=File {0} doesn't exist JschFileStore_Invalid_connection_for_URI=Invalid connection for URI: "{0}" JschFileStore_Is_a_directory={0} is a directory JschFileStore_No_remote_services_found_for_URI=No remote services found for URI: "{0}" -JschFileStore_The_file_of_name_already_exists=A file of name {0} already exists +JschFileStore_The_directory_could_not_be_created=The directory {0} could not be created +JschFileStore_A_file_of_name_already_exists=A file of name {0} already exists JschFileStore_The_parent_of_directory_does_not_exist=The parent of directory {0} does not exist