From 5cf97ddad1d53e45f225ac949389e128b2717b61 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Fri, 15 Jan 2010 15:37:53 +0000 Subject: [PATCH] [299140] Local Readonly file can't be copied/pasted twice --- .../UniversalFileTransferUtility.java | 68 ++++++++++--------- .../local/files/LocalFileService.java | 13 +++- 2 files changed, 48 insertions(+), 33 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 1302b14988b..fb431b38f99 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * Copyright (c) 2006, 2010 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 @@ -58,6 +58,7 @@ * David McKnight (IBM) - [276534] Cache Conflict After Synchronization when Browsing Remote System with Case-Differentiated-Only Filenames * David McKnight (IBM) - [281712] [dstore] Warning message is needed when disk is full * David McKnight (IBM) - [234258] [dnd] Drag&Drop a folder silently ignores elements without permissions + * David McKnight (IBM) - [299140] Local Readonly file can't be copied/pasted twice *******************************************************************************/ package org.eclipse.rse.files.ui.resources; @@ -685,52 +686,55 @@ public class UniversalFileTransferUtility { String storedEncoding = properties.getEncoding(); String currentEncoding = srcFileOrFolder.getEncoding(); - if (storedTime != currentTime && (storedEncoding == null || !storedEncoding.equals(currentEncoding))) + if (storedTime != currentTime || (storedEncoding == null || !storedEncoding.equals(currentEncoding))) { if (tempFile.exists()) { - // set the appropriate readonly flag - boolean readOnly = !srcFileOrFolder.canWrite(); - setReadOnly(tempFile, readOnly); - - try - { - if (remoteEncoding != null) + // deal with encoding properties + if (storedEncoding == null || !storedEncoding.equals(currentEncoding)){ + // set the appropriate readonly flag + boolean readOnly = !srcFileOrFolder.canWrite(); + setReadOnly(tempFile, readOnly); + + try { - if (srcFileOrFolder.isBinary()) + if (remoteEncoding != null) { - if (!tempFile.isSynchronized(IResource.DEPTH_ZERO)) + if (srcFileOrFolder.isBinary()) { - tempFile.refreshLocal(IResource.DEPTH_ZERO, null/*monitor*/); + if (!tempFile.isSynchronized(IResource.DEPTH_ZERO)) + { + tempFile.refreshLocal(IResource.DEPTH_ZERO, null/*monitor*/); + } + if (!tempFile.getCharset().equals(remoteEncoding)) + { + tempFile.setCharset(remoteEncoding, null); + } } - if (!tempFile.getCharset().equals(remoteEncoding)) + else { - tempFile.setCharset(remoteEncoding, null); + // using text mode so the char set needs to be local + if (properties.getLocalEncoding() != null){ + String localEncoding = properties.getLocalEncoding(); + tempFile.setCharset(localEncoding, null); + } + // otherwise, the default charset is inherited so no need to set } } - else - { - // using text mode so the char set needs to be local - if (properties.getLocalEncoding() != null){ - String localEncoding = properties.getLocalEncoding(); - tempFile.setCharset(localEncoding, null); - } - // otherwise, the default charset is inherited so no need to set - } + } + catch (Exception e) + { + SimpleSystemMessage errorMessage = new SimpleSystemMessage(Activator.PLUGIN_ID, + ICommonMessageIds.MSG_OPERATION_FAILED, + IStatus.ERROR, "", e); //$NON-NLS-1$ + resultSet.setMessage(errorMessage); + return null; } } - catch (Exception e) - { - SimpleSystemMessage errorMessage = new SimpleSystemMessage(Activator.PLUGIN_ID, - ICommonMessageIds.MSG_OPERATION_FAILED, - IStatus.ERROR, "", e); //$NON-NLS-1$ - resultSet.setMessage(errorMessage); - return null; - } - try { + // set all properties setIFileProperties(tempFile, srcFileOrFolder, srcFS); } catch (Exception e) diff --git a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java index b29d098ac57..011fc4d32e1 100644 --- a/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java +++ b/rse/plugins/org.eclipse.rse.services.local/src/org/eclipse/rse/internal/services/local/files/LocalFileService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * Copyright (c) 2006, 20010 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 @@ -44,6 +44,7 @@ * David McKnight (IBM) - [280899] RSE can't open files in some directory, which give the RSEG1067 error me * Martin Oberhuber (Wind River) - [285942] Throw exception when listing a non-folder * Martin Oberhuber (Wind River) - [286129][api] RemoteFileException(String) violates API contract + * David McKnight (IBM) - [299140] Local Readonly file can't be copied/pasted twice *******************************************************************************/ package org.eclipse.rse.internal.services.local.files; @@ -405,6 +406,13 @@ public class LocalFileService extends AbstractFileService implements ILocalServi inputStream = new FileInputStream(file); bufInputStream = new BufferedInputStream(inputStream); + + boolean wasReadonly = destinationFile.exists() && !destinationFile.canWrite(); + if (wasReadonly){ // tempfile is readonly + // since we're replacing the tempfile that represents the real file, the readonly bit should be removed for the transfer + //destinationFile.setWritable(true); + setReadOnly(destinationFile.getParent(), destinationFile.getName(), false, monitor); + } outputStream = new FileOutputStream(destinationFile); if (isEncodingConversionRequired) @@ -455,6 +463,9 @@ public class LocalFileService extends AbstractFileService implements ILocalServi isCancelled = monitor.isCanceled(); } } + if (wasReadonly){ + destinationFile.setReadOnly(); + } } catch (Exception e) {