From 06f9bbfe7d40964d0f9c5e920ff1d86cc93d62f4 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Wed, 20 May 2009 14:42:01 +0000 Subject: [PATCH] [276534] Cache Conflict After Synchronization when Browsing Remote System with Case-Differentiated-Only Filenames --- .../UniversalFileTransferUtility.java | 106 ++++++++++++++++-- .../SynchronizeCacheActionDelegate.java | 22 +++- .../ui/view/SystemViewRemoteFileAdapter.java | 13 +-- 3 files changed, 123 insertions(+), 18 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/UniversalFileTransferUtility.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/UniversalFileTransferUtility.java index 84aad89c376..a5f3e0d745b 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/UniversalFileTransferUtility.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/UniversalFileTransferUtility.java @@ -128,6 +128,7 @@ import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.SystemBasePlugin; import org.eclipse.rse.ui.dialogs.SystemRenameSingleDialog; import org.eclipse.rse.ui.messages.SystemMessageDialog; +import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; @@ -193,7 +194,7 @@ public class UniversalFileTransferUtility { } } - private static boolean tempFileAvailable(IFile tempFile, IRemoteFile remoteFile) + private static boolean tempFileAvailable(IFile tempFile, IRemoteFile remoteFile) throws RemoteFileIOException { // before we make the transfer to the temp file check whether a temp file already exists if (tempFile.exists() && ((Resource)tempFile).getPropertyManager() != null) @@ -203,9 +204,10 @@ public class UniversalFileTransferUtility { String replicaRemoteFilePath = properties.getRemoteFilePath(); String remoteFilePath = remoteFile.getAbsolutePath(); - if (!replicaRemoteFilePath.equals(remoteFilePath)){ - // this temp file is for a file of different case - return false; + if (!remoteFilePath.equals(replicaRemoteFilePath)){ + // this temp file is for a file of different case + Exception e = new Exception(FileResources.FILEMSG_CREATE_FILE_FAILED_EXIST); + throw new RemoteFileIOException(e); } @@ -251,7 +253,54 @@ public class UniversalFileTransferUtility { IFile tempFile = (IFile) tempResource; - boolean available = tempFileAvailable(tempFile, srcFileOrFolder); + boolean available = true; + try { + tempFileAvailable(tempFile, srcFileOrFolder); + } + catch (RemoteFileIOException e){ + // this is the case where a temp file exists for a file of a different case + // bug 276534 + SystemIFileProperties properties = new SystemIFileProperties(tempFile); + + Object obj = properties.getRemoteFileObject(); + if (obj != null && obj instanceof SystemEditableRemoteFile) + { + SystemEditableRemoteFile editable = (SystemEditableRemoteFile) obj; + if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN){ + // editor open for this file + // for now, best we may be able to do is just keep this one and warn + String remotePath = editable.getAbsolutePath(); + String msgTxt = NLS.bind(FileResources.FILEMSG_COPY_FILE_FAILED, remotePath); + String msgDetails = FileResources.FILEMSG_COPY_FILE_FAILED_DETAILS; + + final SystemMessage message = new SimpleSystemMessage(Activator.PLUGIN_ID, + ISystemFileConstants.MSG_DOWNLOAD_ALREADY_OPEN_IN_EDITOR, + IStatus.WARNING, msgTxt, msgDetails); + + runInDisplayThread(new Runnable() { + public void run() { + SystemMessageDialog dlg = new SystemMessageDialog(SystemBasePlugin.getActiveWorkbenchShell(), message); + dlg.open(); + }}); + return null; + } + else { + // get rid of the current temp file + try { + tempFile.delete(true, monitor); + } + catch (CoreException ex){} + tempResource = getTempFileFor(srcFileOrFolder); + tempFile = (IFile) tempResource; + + available = false; + } + } + else { + // file not being edited, so overwrite it + available = false; + } + } if (available){ return tempFile; } @@ -465,11 +514,54 @@ public class UniversalFileTransferUtility { IFile tempFile = (IFile) tempResource; - boolean available = tempFileAvailable(tempFile, srcFileOrFolder); + boolean problem = false; + boolean available = true; + try { + available = tempFileAvailable(tempFile, srcFileOrFolder); + } + catch (RemoteFileIOException e){ + // this is the case where a temp file exists for a file of a different case + // bug 276534 + SystemIFileProperties properties = new SystemIFileProperties(tempFile); + + Object obj = properties.getRemoteFileObject(); + if (obj != null && obj instanceof SystemEditableRemoteFile) + { + SystemEditableRemoteFile editable = (SystemEditableRemoteFile) obj; + if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN){ + // editor open for this file + // for now, best we may be able to do is just keep this one and warn + String remotePath = srcFileOrFolder.getAbsolutePath(); + String msgTxt = NLS.bind(FileResources.FILEMSG_COPY_FILE_FAILED, remotePath); + String msgDetails = FileResources.FILEMSG_COPY_FILE_FAILED_DETAILS; + SystemMessage message = new SimpleSystemMessage(Activator.PLUGIN_ID, + ISystemFileConstants.MSG_DOWNLOAD_ALREADY_OPEN_IN_EDITOR, + IStatus.WARNING, msgTxt, msgDetails); + + resultSet.setMessage(message); + problem = true; + } + else { + // get rid of the current temp file + try { + tempFile.delete(true, monitor); + } + catch (CoreException ex){} + tempResource = getTempFileFor(srcFileOrFolder); + tempFile = (IFile) tempResource; + } + available = false; + } + else { + // file not being edited, so overwrite it + available = false; + } + } + if (available){ resultSet.addResource(tempFile); } - else { + else if (!problem){ listener.addIgnoreFile(tempFile); remoteFilesForDownload.add(srcFileOrFolder); diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SynchronizeCacheActionDelegate.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SynchronizeCacheActionDelegate.java index 2d6ece1b0ac..b2cceaedada 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SynchronizeCacheActionDelegate.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SynchronizeCacheActionDelegate.java @@ -11,6 +11,7 @@ * Contributors: * {Name} (company) - description of contribution. * David McKnight (IBM) [143503] [updating] need a synchronize cache operation + * David McKnight (IBM) - [276534] Cache Conflict After Synchronization when Browsing Remote System with Case-Differentiated-Only Filenames ********************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -34,11 +35,15 @@ import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.rse.core.model.ISystemResourceSet; import org.eclipse.rse.core.model.SystemRemoteResourceSet; import org.eclipse.rse.internal.files.ui.Activator; import org.eclipse.rse.internal.files.ui.FileResources; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.ui.messages.SystemMessageDialog; import org.eclipse.rse.ui.view.ISystemViewElementAdapter; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -55,12 +60,14 @@ public class SynchronizeCacheActionDelegate implements IActionDelegate { protected IStructuredSelection fSelection; private IStatus errorStatus; + private SystemMessage systemMessage; public SynchronizeCacheActionDelegate() { } public void run(IAction action) { errorStatus = null; + systemMessage = null; IRemoteFile[] files = getRemoteFiles(fSelection); boolean completed = performCacheRemoteFiles(files); @@ -74,14 +81,21 @@ public class SynchronizeCacheActionDelegate implements IActionDelegate { ErrorDialog.openError(getShell(), FileResources.MESSAGE_ERROR_CACHING_REMOTE_FILES, null, errorStatus); errorStatus = null; } + else if (systemMessage != null){ + SystemMessageDialog dlg = new SystemMessageDialog(getShell(), systemMessage); + dlg.open(); + systemMessage = null; + } } - private void cacheRemoteFiles(IRemoteFile[] files, IProgressMonitor monitor) + private void cacheRemoteFiles(IRemoteFile[] files, IProgressMonitor monitor) throws SystemMessageException { SystemRemoteResourceSet[] sets = getResourceSetsFor(files); for (int i = 0; i < sets.length; i++){ SystemRemoteResourceSet set = sets[i]; - set.getAdapter().doDrag(set, monitor); + ISystemResourceSet resultSet = set.getAdapter().doDrag(set, monitor); + + systemMessage = resultSet.getMessage(); } } @@ -120,7 +134,8 @@ public class SynchronizeCacheActionDelegate implements IActionDelegate { catch (Exception e) { if (e.getCause() instanceof CoreException) { recordError((CoreException)e.getCause()); - } else { + } + else { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), -1, e.getMessage(), e)); @@ -162,6 +177,7 @@ public class SynchronizeCacheActionDelegate implements IActionDelegate { void displayError(String message) { MessageDialog.openError(getShell(), FileResources.MESSAGE_ERROR_CACHING_REMOTE_FILES, message); } + /** * Records the core exception to be displayed to the user once the action is diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java index ceaf474f8c4..07ef71dad4e 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java @@ -62,6 +62,7 @@ * David McKnight (IBM) - [254769] Don't get latest file when opening a file always * David McKnight (IBM) - [264607] Unable to delete a broken symlink * David McKnight (IBM) - [276103] Files with names in different cases are not handled properly + * David McKnight (IBM) - [276534] Cache Conflict After Synchronization when Browsing Remote System with Case-Differentiated-Only Filenames *******************************************************************************/ package org.eclipse.rse.internal.files.ui.view; @@ -3447,16 +3448,12 @@ public class SystemViewRemoteFileAdapter SystemIFileProperties properties = new SystemIFileProperties(file); Object obj = properties.getRemoteFileObject(); - if (obj != null && obj instanceof ISystemEditableRemoteObject) + if (obj != null && obj instanceof SystemEditableRemoteFile) { - ISystemEditableRemoteObject rmtObj = (ISystemEditableRemoteObject) obj; - IAdaptable rmtFile = rmtObj.getRemoteObject(); - if (rmtFile instanceof IRemoteFile) - { - //((IRemoteFile)rmtFile).markStale(true); + SystemEditableRemoteFile rmtObj = (SystemEditableRemoteFile) obj; + if (rmtObj.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN){ // if this is open + return rmtObj; } - - return rmtObj; } } return new SystemEditableRemoteFile(remoteFile);