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 545429c032b..84aad89c376 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 @@ -54,6 +54,8 @@ * David McKnight (IBM) - [262092] Special characters are missing when pasting a file on a different connection * David McKnight (IBM) - [271831] Set the readonly file attribute when download the file * David McKnight (IBM) - [251136] Error copying local file to remote system when temp file is readonly + * 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.files.ui.resources; @@ -197,6 +199,15 @@ public class UniversalFileTransferUtility { if (tempFile.exists() && ((Resource)tempFile).getPropertyManager() != null) { SystemIFileProperties properties = new SystemIFileProperties(tempFile); + + String replicaRemoteFilePath = properties.getRemoteFilePath(); + String remoteFilePath = remoteFile.getAbsolutePath(); + + if (!replicaRemoteFilePath.equals(remoteFilePath)){ + // this temp file is for a file of different case + return false; + } + long storedModifiedStamp = properties.getRemoteFileTimeStamp(); @@ -1825,6 +1836,17 @@ public class UniversalFileTransferUtility { if (targetFS instanceof FileServiceSubSystem) { + /* + OutputStream outStream = targetFS.getOutputStream(targetFolder.getAbsolutePath(), name, IFileService.NONE, monitor); + + byte[] buffer = new byte[1024]; + int readCount; + while( (readCount = inStream.read(buffer)) > 0) + { + outStream.write(buffer, 0, readCount); + } + outStream.close(); + */ IFileService fileService = ((FileServiceSubSystem)targetFS).getFileService(); // for bug 236723, getting remote encoding for target instead of default for target fs @@ -2568,6 +2590,22 @@ public class UniversalFileTransferUtility { } String fileName = expectedPath.segment(expectedPath.segmentCount() - 1); + try { + IResource[] resources = container.members(); + boolean found = false; + for (int r = 0; r < resources.length && !found; r++){ + IResource resource = resources[r]; + if (resource instanceof IFile){ + String resourceName = resource.getName(); + if (resourceName.toLowerCase().equals(fileName.toLowerCase())){ + found = true; + fileName = resourceName; + } + } + } + } + catch (CoreException e){} + actualPath = container.getLocation().append(fileName); return actualPath; } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFileAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFileAction.java index dbe38a6b6be..722b67f3175 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFileAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFileAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 IBM Corporation and others. + * Copyright (c) 2002, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,23 +15,28 @@ * Martin Oberhuber (Wind River) - [189130] Move SystemIFileProperties from UI to Core * David McKnight (IBM) - [189873] DownloadJob changed to DownloadAndOpenJob * David McKnight (IBM) - [224377] "open with" menu does not have "other" option + * David McKnight (IBM) - [276103] Files with names in different cases are not handled properly *******************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; +import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility; import org.eclipse.rse.internal.files.ui.view.DownloadAndOpenJob; import org.eclipse.rse.subsystems.files.core.SystemIFileProperties; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFile; import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; @@ -139,16 +144,79 @@ public class SystemEditFileAction extends SystemBaseAction { return false; } + private SystemEditableRemoteFile getEditableRemoteObject(Object element) + { + SystemEditableRemoteFile editable = null; + RemoteFile remoteFile = (RemoteFile) element; + if (remoteFile.isFile()) + { + try + { + IFile file = (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile); + if (file != null) + { + SystemIFileProperties properties = new SystemIFileProperties(file); + + Object obj = properties.getRemoteFileObject(); + if (obj != null && obj instanceof SystemEditableRemoteFile) + { + editable = (SystemEditableRemoteFile) obj; + + String remotePath = remoteFile.getAbsolutePath(); + String replicaRemotePath = editable.getAbsolutePath(); + // first make sure that the correct remote file is referenced (might be difference because of different case) + if (!replicaRemotePath.equals(remotePath)){ // for bug 276103 + + IEditorPart editor = editable.getEditorPart(); + boolean editorWasClosed = false; + if (editor.isDirty()){ + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + if (editorWasClosed) + editable.doImmediateSaveAndUpload(); + } + else { + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + } + + if (!editorWasClosed){ + // use cancelled operation so we need to get out of here + return null; + } + + try { + IFile originalFile = editable.getLocalResource(); + originalFile.delete(true, new NullProgressMonitor()); + } + catch (CoreException e){ + } + // fall through and let the new editable get created + } + else { + return editable; + } + } + } + + editable = new SystemEditableRemoteFile(remoteFile); + } + catch (Exception e) + { + } + } + return editable; + } + /** * Process the object: download file, open in editor, etc. */ protected void process(IRemoteFile remoteFile) { - /* - SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, _editorId); - editableFile.open(SystemBasePlugin.getActiveWorkbenchShell()); - */ - SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, _editorDescriptor); + SystemEditableRemoteFile editable = getEditableRemoteObject(remoteFile); + if (editable == null){ + // case for cancelled operation when user was prompted to save file of different case + return; + } + else { try { diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java index 7f160bc28c3..2c75485e848 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 IBM Corporation and others. + * Copyright (c) 2002, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ * David McKnight (IBM) - [209660] check for changed encoding before using cached file * David McKnight (IBM) - [189873] DownloadJob changed to DownloadAndOpenJob * David McKnight (IBM) - [224377] "open with" menu does not have "other" option + * David McKnight (IBM) - [276103] Files with names in different cases are not handled properly *******************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -23,6 +24,7 @@ package org.eclipse.rse.internal.files.ui.actions; import java.util.Iterator; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; @@ -31,10 +33,12 @@ import org.eclipse.rse.internal.files.ui.view.DownloadAndOpenJob; import org.eclipse.rse.subsystems.files.core.SystemIFileProperties; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFile; import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; @@ -174,7 +178,12 @@ public class SystemEditFilesAction extends SystemBaseAction { editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } - SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, des); + SystemEditableRemoteFile editable = getEditableRemoteObject(remoteFile, des); + if (editable == null){ + // case for cancelled operation when user was prompted to save file of different case + return; + } + else { try { @@ -203,4 +212,73 @@ public class SystemEditFilesAction extends SystemBaseAction { } } + + + private SystemEditableRemoteFile getEditableRemoteObject(Object element, IEditorDescriptor descriptor) + { + SystemEditableRemoteFile editable = null; + RemoteFile remoteFile = (RemoteFile) element; + if (remoteFile.isFile()) + { + try + { + IFile file = (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile); + if (file != null) + { + SystemIFileProperties properties = new SystemIFileProperties(file); + + Object obj = properties.getRemoteFileObject(); + if (obj != null && obj instanceof SystemEditableRemoteFile) + { + editable = (SystemEditableRemoteFile) obj; + + String remotePath = remoteFile.getAbsolutePath(); + String replicaRemotePath = editable.getAbsolutePath(); + // first make sure that the correct remote file is referenced (might be difference because of different case) + if (!replicaRemotePath.equals(remotePath)){ // for bug 276103 + + IEditorPart editor = editable.getEditorPart(); + boolean editorWasClosed = false; + if (editor.isDirty()){ + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + if (editorWasClosed) + editable.doImmediateSaveAndUpload(); + } + else { + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + } + + if (!editorWasClosed){ + // use cancelled operation so we need to get out of here + return null; + } + + try { + IFile originalFile = editable.getLocalResource(); + originalFile.delete(true, new NullProgressMonitor()); + } + catch (CoreException e){ + } + // fall through and let the new editable get created + } + else { + return editable; + } + } + } + + if (descriptor != null){ + editable = new SystemEditableRemoteFile(remoteFile, descriptor); + } + else { + editable = new SystemEditableRemoteFile(remoteFile); + } + } + catch (Exception e) + { + } + } + return editable; + } + } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java index 783c1a47285..99ebc34640c 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ * Martin Oberhuber (Wind River) - [189130] Move SystemIFileProperties from UI to Core * David McKnight (IBM) - [189873] DownloadJob changed to DownloadAndOpenJob * David McKnight (IBM) - [224377] "open with" menu does not have "other" option + * *******************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -27,6 +28,7 @@ import java.util.Comparator; import java.util.Hashtable; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.resource.ImageDescriptor; @@ -40,6 +42,7 @@ import org.eclipse.rse.internal.files.ui.view.DownloadAndOpenJob; import org.eclipse.rse.subsystems.files.core.SystemIFileProperties; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.RemoteFile; import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.SystemBasePlugin; import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; @@ -50,6 +53,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; @@ -220,17 +224,79 @@ private void createOtherMenuItem(final Menu menu, final IRemoteFile remoteFile) } +private SystemEditableRemoteFile getEditableRemoteObject(Object element, IEditorDescriptor descriptor) +{ + SystemEditableRemoteFile editable = null; + RemoteFile remoteFile = (RemoteFile) element; + if (remoteFile.isFile()) + { + try + { + IFile file = (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile); + if (file != null) + { + SystemIFileProperties properties = new SystemIFileProperties(file); + + Object obj = properties.getRemoteFileObject(); + if (obj != null && obj instanceof SystemEditableRemoteFile) + { + editable = (SystemEditableRemoteFile) obj; + + String remotePath = remoteFile.getAbsolutePath(); + String replicaRemotePath = editable.getAbsolutePath(); + // first make sure that the correct remote file is referenced (might be difference because of different case) + if (!replicaRemotePath.equals(remotePath)){ // for bug 276103 + + IEditorPart editor = editable.getEditorPart(); + boolean editorWasClosed = false; + if (editor.isDirty()){ + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + if (editorWasClosed) + editable.doImmediateSaveAndUpload(); + } + else { + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + } + + if (!editorWasClosed){ + // use cancelled operation so we need to get out of here + return null; + } + + try { + IFile originalFile = editable.getLocalResource(); + originalFile.delete(true, new NullProgressMonitor()); + } + catch (CoreException e){ + } + // fall through and let the new editable get created + } + else { + return editable; + } + } + } + + if (descriptor != null){ + editable = new SystemEditableRemoteFile(remoteFile, descriptor); + } + else { + editable = new SystemEditableRemoteFile(remoteFile); + } + } + catch (Exception e) + { + } + } + return editable; +} + protected void openEditor(IRemoteFile remoteFile, IEditorDescriptor descriptor) { - SystemEditableRemoteFile editable = null; - - if (descriptor == null) - { - editable = new SystemEditableRemoteFile(remoteFile); - } - else - { - editable = new SystemEditableRemoteFile(remoteFile, descriptor); + SystemEditableRemoteFile editable = getEditableRemoteObject(remoteFile, descriptor); + if (editable == null){ + // case for cancelled operation when user was prompted to save file of different case + return; } boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); 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 318ed03c198..ceaf474f8c4 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 @@ -61,6 +61,7 @@ * David McKnight (IBM) - [261019] New File/Folder actions available in Work Offline mode * 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 *******************************************************************************/ package org.eclipse.rse.internal.files.ui.view; @@ -75,6 +76,7 @@ import java.util.StringTokenizer; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -185,6 +187,7 @@ import org.eclipse.rse.ui.view.ISystemViewElementAdapter; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IWorkbench; @@ -3288,9 +3291,41 @@ public class SystemViewRemoteFileAdapter } // only handle double click if object is a file - ISystemEditableRemoteObject editable = getEditableRemoteObject(remoteFile); + ISystemEditableRemoteObject editable = getEditableRemoteObject(remoteFile); if (editable != null) { + String remotePath = remoteFile.getAbsolutePath(); + String replicaRemotePath = editable.getAbsolutePath(); + // first make sure that the correct remote file is referenced (might be difference because of different case) + if (!replicaRemotePath.equals(remotePath)){ // for bug 276103 + + IEditorPart editor = editable.getEditorPart(); + boolean editorWasClosed = false; + if (editor.isDirty()){ + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + if (editorWasClosed) + editable.doImmediateSaveAndUpload(); + } + else { + editorWasClosed = editor.getEditorSite().getPage().closeEditor(editor, true); + } + + if (!editorWasClosed){ + // use cancelled operation so we need to get out of here + return false; + } + + try { + IFile file = editable.getLocalResource(); + file.delete(true, new NullProgressMonitor()); + } + catch (CoreException e){ + } + + // open new editor for correct replica + editable = getEditableRemoteObject(remoteFile); + } + try { boolean isOpen = editable.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN; @@ -3406,10 +3441,11 @@ public class SystemViewRemoteFileAdapter { try { - IFile file = getCachedCopy(remoteFile); + IFile file = getCachedCopy(remoteFile); // Note that this is a case-sensitive check if (file != null) { SystemIFileProperties properties = new SystemIFileProperties(file); + Object obj = properties.getRemoteFileObject(); if (obj != null && obj instanceof ISystemEditableRemoteObject) { @@ -3419,10 +3455,10 @@ public class SystemViewRemoteFileAdapter { //((IRemoteFile)rmtFile).markStale(true); } + return rmtObj; } } - return new SystemEditableRemoteFile(remoteFile); } catch (Exception e) @@ -3438,7 +3474,7 @@ public class SystemViewRemoteFileAdapter { IResource replica = UniversalFileTransferUtility.getTempFileFor(remoteFile); if (replica != null && replica.exists()) - { + { return (IFile)replica; } }