From 877d847b6d759ccbfc4016a12970a48f76ee2733 Mon Sep 17 00:00:00 2001 From: Xuan Chen Date: Wed, 23 Jan 2008 03:57:16 +0000 Subject: [PATCH] [191370] fix: [dstore] Supertransfer zip not deleted when cancelling copy --- .../UniversalFileTransferUtility.java | 15 +++++++++-- .../archiveutils/SystemTarHandler.java | 23 +++++++++++++--- .../archiveutils/SystemZipHandler.java | 27 ++++++++++++++----- 3 files changed, 54 insertions(+), 11 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 7e9f224cb12..434d9206bf3 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, 2007 IBM Corporation and others. All rights reserved. + * Copyright (c) 2006, 2008 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 http://www.eclipse.org/legal/epl-v10.html @@ -1969,7 +1969,18 @@ public class UniversalFileTransferUtility IRemoteFile sourceDir = sourceFS.getRemoteFileObject(directory.getAbsolutePath(), monitor); // DKM - copy src dir to remote temp archive - sourceFS.copy(sourceDir, destinationArchive, sourceDir.getName(), monitor); + try + { + sourceFS.copy(sourceDir, destinationArchive, sourceDir.getName(), monitor); + } + catch (SystemMessageException e) + { + if (monitor.isCanceled()) + { + cleanup(destinationArchive, null); + return targetResource; + } + } destinationArchive.markStale(true); // reget it so that it's properties (namely "size") are correct diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java index 8238ef32e06..a7641ef10c3 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2008 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 @@ -21,6 +21,7 @@ * Xuan Chen (IBM) - [211551] NPE when moving multiple folders from one tar file to another tar file * Xuan Chen (IBM) - [211653] Copy virtual directory with nested directory of tar file did not work * Xuan Chen (IBM) - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file. + * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when cancelling copy *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -1248,10 +1249,19 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } - + VirtualChild[] newEntriesAdded = new VirtualChild[numFiles]; // for each new file to add for (int i = 0; i < numFiles; i++) { + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) + { + outStream.close(); + if (outputTempFile != null) + { + outputTempFile.delete(); + } + return false; + } String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$ TarEntry newEntry = createTarEntry(files[i], childVirtualPath); @@ -1261,15 +1271,22 @@ public class SystemTarHandler implements ISystemArchiveHandler { // add the new entry to the cache, so that the cache is updated VirtualChild temp = getVirtualChild(newEntry); - vfs.addEntry(temp); + newEntriesAdded[i] = temp; } + // close output stream outStream.close(); // replace the current tar file with the new one, and do not update cache since // we just did replaceFile(outputTempFile, false); + + //Also need to add the new entries into VFS + for (int i = 0; i < numFiles; i++) + { + vfs.addEntry(newEntriesAdded[i]); + } } } diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java index d70b47aa949..18c842cc9f7 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java @@ -21,6 +21,7 @@ * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when cancelling copy * Xuan Chen (IBM) - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file. * Xuan Chen (IBM) - [214786] [regression][archive]rename a virtual directory does not work properly + * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when cancelling copy *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -1285,33 +1286,47 @@ public class SystemZipHandler implements ISystemArchiveHandler if (isCanceled) { dest.close(); - if (!(outputTempFile == null)) outputTempFile.delete(); + if (!(outputTempFile == null)) + { + outputTempFile.delete(); + } if (closeZipFile) closeZipFile(); return false; } } // Now for each new file to add + // We need to remember the entries added, and if this operation is not canceled, we + // will add them into Virtual File system. + ZipEntry[] newEntriesAdded = new ZipEntry[numFiles]; for (int i = 0; i < numFiles; i++) - { - if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) + { + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) { //the operation has been canceled dest.close(); + if (!(outputTempFile == null)) + { + outputTempFile.delete(); + } closeZipFile(); return false; } // append the additional entry to the zip file. ZipEntry newEntry = appendFile(files[i], dest, virtualPath, names[i], sourceEncodings[i], targetEncodings[i], isText[i]); - // Add the new entry to the virtual file system in memory - fillBranch(newEntry); + // Add the new entry to the array first. + newEntriesAdded[i] = newEntry; } dest.close(); // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + //Also need to add the new entries into VFS + for (int i = 0; i < numFiles; i++) + { + fillBranch(newEntriesAdded[i]); + } if (closeZipFile) closeZipFile(); return true;