1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

[429668] - Avoid race condition causing mkdir to fail.

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2014-03-21 13:18:32 -04:00
parent 3faf39df8d
commit 1b500f829b
3 changed files with 35 additions and 18 deletions

View file

@ -217,23 +217,37 @@ public class JschFileStore extends FileStore {
JSchConnection connection = checkConnection(); JSchConnection connection = checkConnection();
SubMonitor subMon = SubMonitor.convert(monitor, 20); SubMonitor subMon = SubMonitor.convert(monitor, 20);
IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10)); if ((options & EFS.SHALLOW) == EFS.SHALLOW) {
if (!subMon.isCanceled()) { IFileStore parent = getParent();
if (!info.exists()) { if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(10)).exists()) {
if ((options & EFS.SHALLOW) == EFS.SHALLOW) { throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE, NLS.bind(
IFileStore parent = getParent(); Messages.JschFileStore_The_parent_of_directory_does_not_exist, fRemotePath.toString()), null));
if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(10)).exists()) { }
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRITE, if (subMon.isCanceled()) {
NLS.bind(Messages.JschFileStore_The_parent_of_directory_does_not_exist, fRemotePath.toString()), return this;
null)); }
} }
}
MkdirCommand command = new MkdirCommand(connection, fRemotePath); try {
command.getResult(subMon.newChild(10)); MkdirCommand command = new MkdirCommand(connection, fRemotePath);
} else if (!info.isDirectory()) { command.getResult(subMon.newChild(10));
throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE, NLS.bind( } catch (Exception e) {
Messages.JschFileStore_The_file_of_name_already_exists, fRemotePath.toString()), null)); // 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));
}
} }
} }

View file

@ -44,7 +44,9 @@ public class Messages extends NLS {
public static String JschFileStore_Invalid_connection_for_URI; public static String JschFileStore_Invalid_connection_for_URI;
public static String JschFileStore_Is_a_directory; public static String JschFileStore_Is_a_directory;
public static String JschFileStore_No_remote_services_found_for_URI; 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; public static String JschFileStore_The_parent_of_directory_does_not_exist;
static { static {

View file

@ -34,5 +34,6 @@ JschFileStore_File_doesnt_exist=File {0} doesn't exist
JschFileStore_Invalid_connection_for_URI=Invalid connection for URI: "{0}" JschFileStore_Invalid_connection_for_URI=Invalid connection for URI: "{0}"
JschFileStore_Is_a_directory={0} is a directory JschFileStore_Is_a_directory={0} is a directory
JschFileStore_No_remote_services_found_for_URI=No remote services found for URI: "{0}" 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 JschFileStore_The_parent_of_directory_does_not_exist=The parent of directory {0} does not exist