Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366339

Summary: Linked resources are not overwritten pressing "yes" on "do you wish to overwrite"
Product: [Eclipse Project] Platform Reporter: valentin Mising name <intellij>
Component: IDEAssignee: Serge Beauchamp <serge>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: pwebster, Szymon.Brandys
Version: 3.8   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description valentin Mising name CLA 2011-12-11 15:31:51 EST
Build Identifier: M20110909-1335

I drop the files into project resources. When there exists a file with such name, "do you wish to overwrite" dialog appears. Pressing does nothing -- I see that resource is still linked to the previous file location. The same thing happens in e4.

There is an easy workaround but it is definitely a bug. Either complete overwriting or do not claim that you will.

Reproducible: Always

Steps to Reproduce:
1.Drop a file into a project. Link it.
2.Drop another file with the same name from another location. Choose linking import also. 
3.Agree on "do you wish to overwrite?" dialog

In the resource properties, see that location still links to the first file location.
Comment 1 Szymon Brandys CLA 2011-12-12 04:30:38 EST
Serge, could you take a look? For me it looks like a problem with ImportOperation#importFile around line 571.
Comment 2 Serge Beauchamp CLA 2011-12-12 06:49:51 EST
Here's a patch to address this issue:

diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java
index 6d588f6..f3c035e 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/datatransfer/ImportOperation.java
@@ -568,16 +568,24 @@ public class ImportOperation extends WorkspaceModifyOperation {
         }
 
         try {
-            if (targetResource.exists()) {
-				targetResource.setContents(contentStream,
-                        IResource.KEEP_HISTORY, null);
+            if (createVirtualFolder || createLinks || createLinkFilesOnly) {
+	            if (targetResource.exists())
+	            	targetResource.delete(true, null);
+                targetResource.createLink(createRelativePath(
+                        new Path(provider
+                                .getFullPath(fileObject)), targetResource), 0, null);
             } else {
-                if (createVirtualFolder || createLinks || createLinkFilesOnly)
-                    targetResource.createLink(createRelativePath(
-                            new Path(provider
-                                    .getFullPath(fileObject)), targetResource), 0, null);
-                else
-                    targetResource.create(contentStream, false, null);
+	            if (targetResource.exists()) {
+	            	if (targetResource.isLinked()) {
+		            	targetResource.delete(true, null);
+		            	targetResource.create(contentStream, false, null);
+	            	}
+	            	else
+	            		targetResource.setContents(contentStream,
+	                        IResource.KEEP_HISTORY, null);
+	            }
+	            else
+	            	targetResource.create(contentStream, false, null);
             }
             setResourceAttributes(targetResource, fileObject);
 
I verified and tested the following use case:

- Drag and drop a simple linked resource file
- Drag and drop a simple file
- Drag and drop a simple file, overriding an existing resource
- Drag and drop a simple linked resource file an existing linked resource
- Drag and drop a simple file, overriding an existing linked resource
- Drag and drop a simple linked resource file an existing resource

Note: the last 2 cases, there's  bug in the UI, it doesn't refresh so the linked resource overlay doesn't disappear: filed bug with it.  F5 does update it properly)
Comment 3 Serge Beauchamp CLA 2011-12-12 06:50:26 EST
The bug in the Project Explorer has been filed as Bug 366380
Comment 4 Serge Beauchamp CLA 2011-12-12 06:59:28 EST
I also verified that the folder import operation works as expected.
Comment 5 Serge Beauchamp CLA 2012-01-17 08:15:23 EST
Now fixed on the git repo.  

Szymon, you mentioned there was another branch I should commit it to, which one was it?
Comment 6 Szymon Brandys CLA 2012-01-17 08:22:31 EST
The fix should be in master and R3_development.
Comment 7 Serge Beauchamp CLA 2012-01-17 08:37:56 EST
(In reply to comment #6)
> The fix should be in master and R3_development.

Thanks, now fixed on R3_development as well.