1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-28 18:53:20 +02:00

[198728] Copy/paste across connections did not preserve empty folder.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=198728
This commit is contained in:
David Dykstal 2008-04-29 20:25:43 +00:00
parent c885280664
commit 6c6bed23d5
2 changed files with 115 additions and 18 deletions

View file

@ -44,6 +44,7 @@
* David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared * David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared
* Rupen Mardirossian (IBM) - [210682] Collisions when doing a copy operation across systems will us the SystemCopyDialog * Rupen Mardirossian (IBM) - [210682] Collisions when doing a copy operation across systems will us the SystemCopyDialog
* Xuan Chen (IBM) - [229093] set charset of the temp file of the text remote file to its remote encoding * Xuan Chen (IBM) - [229093] set charset of the temp file of the text remote file to its remote encoding
* Rupen Mardirossian (IBM) - [198728] downloadResourcesToWorkspace now creates empty folders for copying across connections via createEmptyFolders method
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.files.ui.resources; package org.eclipse.rse.files.ui.resources;
@ -65,6 +66,7 @@ import java.util.List;
import org.eclipse.core.internal.resources.Resource; import org.eclipse.core.internal.resources.Resource;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -410,6 +412,7 @@ public class UniversalFileTransferUtility
List remoteFilesForDownload = new ArrayList(); List remoteFilesForDownload = new ArrayList();
List tempFilesForDownload = new ArrayList(); List tempFilesForDownload = new ArrayList();
List remoteEncodingsForDownload = new ArrayList(); List remoteEncodingsForDownload = new ArrayList();
List emptyFolders = new ArrayList();
// step 1: pre-download processing // step 1: pre-download processing
for (int i = 0; i < set.size() && !resultSet.hasMessage(); i++){ for (int i = 0; i < set.size() && !resultSet.hasMessage(); i++){
@ -432,7 +435,7 @@ public class UniversalFileTransferUtility
} }
else else
{ {
if (srcFileOrFolder.isFile()) // file transfer if (srcFileOrFolder.isFile()) // file transfer only
{ {
IResource tempResource = getTempFileFor(srcFileOrFolder); IResource tempResource = getTempFileFor(srcFileOrFolder);
@ -460,15 +463,24 @@ public class UniversalFileTransferUtility
} }
} }
} }
else if (srcFileOrFolder.isDirectory()) // recurse for folders and add to our consolidated resource set else if (srcFileOrFolder.isDirectory()) // recurse for empty folders and add to our consolidated resource set
{ {
IResource tempFolder = getTempFileFor(srcFileOrFolder); IResource tempFolder = getTempFileFor(srcFileOrFolder);
try try
{ {
IRemoteFile[] children = srcFS.list(srcFileOrFolder,monitor); //get contents of folder
IRemoteFile[] children = srcFS.list(srcFileOrFolder,IFileService.FILE_TYPE_FILES_AND_FOLDERS,monitor);
//check for empty folder and add to set
if(children==null || children.length==0)
{
emptyFolders.add(tempFolder);
}
//get all subfolders
children=srcFS.list(srcFileOrFolder, IFileService.FILE_TYPE_FOLDERS, monitor);
if(!(children==null) && !(children.length==0))
{
SystemRemoteResourceSet childSet = new SystemRemoteResourceSet(srcFS, children); SystemRemoteResourceSet childSet = new SystemRemoteResourceSet(srcFS, children);
//recurse with subfolders to check for empty folders
SystemWorkspaceResourceSet childResults = downloadResourcesToWorkspaceMultiple(childSet, monitor); SystemWorkspaceResourceSet childResults = downloadResourcesToWorkspaceMultiple(childSet, monitor);
if (childResults.hasMessage()) if (childResults.hasMessage())
{ {
@ -476,6 +488,7 @@ public class UniversalFileTransferUtility
} }
resultSet.addResource(tempFolder); resultSet.addResource(tempFolder);
} }
}
catch (SystemMessageException e) catch (SystemMessageException e)
{ {
e.printStackTrace(); e.printStackTrace();
@ -515,6 +528,18 @@ public class UniversalFileTransferUtility
{ {
} }
//Create empty folders
try
{
createEmptyFolders(monitor, emptyFolders);
}
catch(CoreException e)
{
SystemMessage errorMessage = new SimpleSystemMessage(Activator.PLUGIN_ID,
ISystemFileConstants.FILEMSG_CREATE_FILE_FAILED,
IStatus.ERROR, FileResources.FILEMSG_CREATE_FILE_FAILED, e);
resultSet.setMessage(errorMessage);
}
// step 3: post download processing // step 3: post download processing
if (!resultSet.hasMessage()) if (!resultSet.hasMessage())
@ -593,10 +618,51 @@ public class UniversalFileTransferUtility
} }
} }
} }
return resultSet; return resultSet;
} }
private static void createEmptyFolders(IProgressMonitor monitor, List emptyFolders) throws CoreException
{
IContainer empty;
IFolder emptyFolder;
List emptyParent;
boolean go=false;
for(int i=0; i<emptyFolders.size();i++)
{
emptyParent = new ArrayList();
empty = (IContainer) emptyFolders.get(i);
go=true;
//check to see which parent folders need to be created
while(go)
{
empty = empty.getParent();
if(!empty.exists() && empty instanceof IFolder)
{
emptyParent.add(empty);
}
else
{
go=false;
}
}
//create empty parent folders
for(int j=emptyParent.size()-1;j>=0;j--)
{
emptyFolder = (IFolder) emptyParent.get(j);
if(!emptyFolder.exists())
{
emptyFolder.create(true, true, monitor);
}
}
//create empty folders
emptyFolder = (IFolder) emptyFolders.get(i);
if(!emptyFolder.exists())
{
emptyFolder.create(true, true, monitor);
}
}
}
/** /**
* Replicates a set of remote files or folders to the workspace * Replicates a set of remote files or folders to the workspace
@ -619,6 +685,8 @@ public class UniversalFileTransferUtility
boolean doSuperTransferProperty = doSuperTransfer(srcFS); boolean doSuperTransferProperty = doSuperTransfer(srcFS);
List set = remoteSet.getResourceSet(); List set = remoteSet.getResourceSet();
List emptyFolders = new ArrayList();
for (int i = 0; i < set.size() && !resultSet.hasMessage(); i++) for (int i = 0; i < set.size() && !resultSet.hasMessage(); i++)
{ {
if (monitor != null && monitor.isCanceled()) if (monitor != null && monitor.isCanceled())
@ -674,7 +742,11 @@ public class UniversalFileTransferUtility
try try
{ {
IRemoteFile[] children = srcFS.list(srcFileOrFolder,monitor); IRemoteFile[] children = srcFS.list(srcFileOrFolder,monitor);
//check for empty folder and add to set
if(children==null || children.length==0)
{
emptyFolders.add(tempFolder);
}
SystemRemoteResourceSet childSet = new SystemRemoteResourceSet(srcFS, children); SystemRemoteResourceSet childSet = new SystemRemoteResourceSet(srcFS, children);
SystemWorkspaceResourceSet childResults = downloadResourcesToWorkspace(childSet, monitor); SystemWorkspaceResourceSet childResults = downloadResourcesToWorkspace(childSet, monitor);
@ -693,6 +765,18 @@ public class UniversalFileTransferUtility
} }
} }
//Create empty folders
try
{
createEmptyFolders(monitor, emptyFolders);
}
catch(CoreException e)
{
SystemMessage errorMessage = new SimpleSystemMessage(Activator.PLUGIN_ID,
ISystemFileConstants.FILEMSG_CREATE_FILE_FAILED,
IStatus.ERROR, FileResources.FILEMSG_CREATE_FILE_FAILED, e);
resultSet.setMessage(errorMessage);
}
// refresh and set IFile properties // refresh and set IFile properties
for (int r = 0; r < resultSet.size(); r++) for (int r = 0; r < resultSet.size(); r++)

View file

@ -51,6 +51,7 @@
* Rupen Mardirossian (IBM) - [210682] Copy collisions will use SystemCopyDialog now instead of renameDialog when there is a copy collision within the same connection * Rupen Mardirossian (IBM) - [210682] Copy collisions will use SystemCopyDialog now instead of renameDialog when there is a copy collision within the same connection
* David McKnight (IBM) - [224377] "open with" menu does not have "other" option * David McKnight (IBM) - [224377] "open with" menu does not have "other" option
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE * David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
* Rupen Mardirossian (IBM) - [198728] Folder being copied across systems is added to original set of files in order to extract empty (sub)folders in doDrop method
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.files.ui.view; package org.eclipse.rse.internal.files.ui.view;
@ -1652,6 +1653,7 @@ public class SystemViewRemoteFileAdapter
boolean doSuperTransferProperty = RSEUIPlugin.getDefault().getPreferenceStore().getBoolean(ISystemFilePreferencesConstants.DOSUPERTRANSFER); boolean doSuperTransferProperty = RSEUIPlugin.getDefault().getPreferenceStore().getBoolean(ISystemFilePreferencesConstants.DOSUPERTRANSFER);
if (!doSuperTransferProperty && supportsSearch) if (!doSuperTransferProperty && supportsSearch)
{ {
//flatset will contain all FILES that will be copied to workspace in UniversalFileTransferUtility and create corresponding folders. Empty folders will be ignored
SystemRemoteResourceSet flatSet = new SystemRemoteResourceSet(set.getSubSystem(), set.getAdapter()); SystemRemoteResourceSet flatSet = new SystemRemoteResourceSet(set.getSubSystem(), set.getAdapter());
long totalByteSize = getFlatRemoteResourceSet(set.getResourceSet(), flatSet, monitor); long totalByteSize = getFlatRemoteResourceSet(set.getResourceSet(), flatSet, monitor);
flatSet.setByteSize(totalByteSize); flatSet.setByteSize(totalByteSize);
@ -1662,6 +1664,17 @@ public class SystemViewRemoteFileAdapter
//monitor.done(); //monitor.done();
} }
//add folders to set that are being copied to the workspace in order to strip out empty folders in UniversalFileTransferUtility
for (int i=0;i<set.size();i++)
{
IRemoteFile remoteFile = (IRemoteFile)set.get(i);
//make sure it is a folder as files are being accounted for already
if(remoteFile.isDirectory())
{
flatSet.addResource(remoteFile);
}
}
try try
{ {
//SystemWorkspaceResourceSet flatResult = UniversalFileTransferUtility.copyRemoteResourcesToWorkspace(flatSet, monitor); //SystemWorkspaceResourceSet flatResult = UniversalFileTransferUtility.copyRemoteResourcesToWorkspace(flatSet, monitor);