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

Bug 334839

Summary: File Content Conflict is not handled properly
Product: [Tools] Target Management Reporter: Samuel Wu <samuelwu>
Component: RSEAssignee: David McKnight <dmcknigh>
Status: RESOLVED FIXED QA Contact: Martin Oberhuber <mober.at+eclipse>
Severity: normal    
Priority: P3 CC: dmcknigh, wagnross
Version: 3.2   
Target Milestone: 3.3 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 337852    
Attachments:
Description Flags
patch to make the editor dirty on unresolved upload conflict
none
patch to make the editor dirty on unresolved upload conflict
none
updated patch with handling for reopen
none
updated patch allowing remote save during shutdown if connected
none
updated patch with handling for some special shutdown cases
none
updated patch with keyhandling for save as and editor focus
none
update to use PlatformUI.getWorkbench().isClosing() none

Description Samuel Wu CLA 2011-01-19 17:47:00 EST
Build Identifier: RSE 3.2.0

When a file is opened in the editor its content might be changed outside eclipse which will cause a content conflict. It is not handled properly in RSE 3.2

Reproducible: Always

Steps to Reproduce:
It was found that the content conflict resolving was changed in RSE 3.2 and it behaves very strangely. 
1. Open a file in the editor and make a change without saving it.
2. Make a change to the original file outside Eclipse
3. Press Ctrl-S to save the file
4. When the Save Conflict dialog comes up, click Cancel button 
5. The Save button is disabled and the file can't be saved any more. Should the file be still marked as dirty since the change hasn't been saved yet?
6. Close the file and reopen it.
7. When Local Changes Pending dialog comes up, choose to Open editor with pending changes. 
8. The file is opened with the pending change but the file is not marked as dirty and the pending change can't be saved
9. If the action Save as is run, the Eclipse project browse dialog will be brought up which can't save the file either
10. Make another change to the file
11. Shut down eclipse
12. Eclipse notices the pending change and asks whether to save
13. Click Yes to save the change
14. Restart the eclipse
15. The file is not marked as dirty and the pending change is not saved to the original file
Comment 1 David McKnight CLA 2011-01-20 10:43:50 EST
Created attachment 187201 [details]
patch to make the editor dirty on unresolved upload conflict
Comment 2 David McKnight CLA 2011-01-20 10:45:09 EST
Created attachment 187202 [details]
patch to make the editor dirty on unresolved upload conflict
Comment 3 David McKnight CLA 2011-01-20 10:45:52 EST
Samuel, could you try with this patch?
Comment 4 Samuel Wu CLA 2011-01-20 12:08:19 EST
Thank you for the prompt response, Dave. 
Can you please check for ITextEditor instead of AbstractTextEditor. It's a bit too restrictive.
The problem was fixed until step 6 as in the problem scenario. I re-wrote it as the following.

6. Close the file with pending changes. Choose no when being asked whether to save the pending changes. Reopen the file
7. When Local Changes Pending dialog comes up, choose to Open editor with
pending changes. 
8. The file is opened with the pending change but the file is not marked as
dirty and the pending change can't be saved
9. If the action Save as is run, the Eclipse project browse dialog will be
brought up which can't save the file either
10. Make another change to the file
11. Shut down eclipse
12. Eclipse notices the pending change and asks whether to save
13. Click Yes to save the change
14. Restart the eclipse
15. The file is not marked as dirty and the pending change is not saved to the
original file
Comment 5 David McKnight CLA 2011-01-20 12:44:33 EST
Created attachment 187217 [details]
updated patch with handling for reopen

I've updated the patch to mark the editor dirty on reopen of a file that we've marked as dirty.
Comment 6 Samuel Wu CLA 2011-01-20 14:30:46 EST
The new patch moves forward and it fine until step 11. RSE used to pop up a content conflict dialog if the user chooses to save the file. It doesn't do that any more. 

11. Shut down eclipse while there is a pending change in the file. 
12. Eclipse notices the pending change and asks whether to save
13. Click Yes to save the change (no RSE prompt for conflict content)
14. Restart the eclipse
15. The file is not marked as dirty and the pending change is not saved to the
original file
Comment 7 David McKnight CLA 2011-01-20 15:43:13 EST
(In reply to comment #6)
> The new patch moves forward and it fine until step 11. RSE used to pop up a
> content conflict dialog if the user chooses to save the file. It doesn't do
> that any more. 
> 
> 11. Shut down eclipse while there is a pending change in the file. 
> 12. Eclipse notices the pending change and asks whether to save
> 13. Click Yes to save the change (no RSE prompt for conflict content)
> 14. Restart the eclipse
> 15. The file is not marked as dirty and the pending change is not saved to the
> original file

This last issue is a little tricky because, when Eclipse starts up with an open editor, RSE doesn't create the corresponding SystemEditableRemoteFile wrapper until it receives a change event.  In order to resolve this, I suppose we could have RSE to automatically create wrappers for the appropriate open editors at startup although there's the possibility that the RSE plugins might not be loaded yet and I don't think it's a good idea to force the activation of RSE.  The compromise may be to have the temp file listener create the wrappers when it gets loaded - so the dirty editor would only be seen when RSE is loaded.
Comment 8 Samuel Wu CLA 2011-01-25 09:57:18 EST
When there is a pending change in editor and the user choose to shut down, the edito prompts for saving the file. If the user choose to cancel it, the editor will actually cancel the shutdown process. 
Is it possible for RSE to do something similar to handle the content conflict? Then we don't need to worry about the start up.
Comment 9 David McKnight CLA 2011-02-01 12:55:45 EST
Created attachment 188067 [details]
updated patch allowing remote save during shutdown if connected
Comment 10 David McKnight CLA 2011-02-01 13:02:40 EST
(In reply to comment #8)
> When there is a pending change in editor and the user choose to shut down, the
> edito prompts for saving the file. If the user choose to cancel it, the editor
> will actually cancel the shutdown process. 
> Is it possible for RSE to do something similar to handle the content conflict?
> Then we don't need to worry about the start up.

The latest update to the patch should deal with the save case during shutdown so long as the associated subsystem is connected (the remote save should go through).  If not, then we still don't have the dirty flag on the editor.  As far as I can tell, we can't halt the shutdown process like it's done for the editor cancel.
Comment 11 David McKnight CLA 2011-02-04 13:04:53 EST
Created attachment 188341 [details]
updated patch with handling for some special shutdown cases
Comment 12 Samuel Wu CLA 2011-02-15 13:54:04 EST
Hi Dave,
The following scenarios failed for the latest patch.

1. Replace with remote copy after Cancel
   1.1 Open a file in an editor and make a change
   1.2 Touch the file on the remote host to create a conflict
   1.3 Click the Save button and conflict is found.
   1.4 Cancel the conflict dialog
   1.5 Click the Save button again
   1.6 When the conflict dialog comes up again, select to replace the content in the editor with the remote file
   1.7 The file is still marked as dirty in the editor with the pending change and the remote file still contained the old content
   1.8 Click the Save button for the third time
   1.9 The pending change was written to the remote file without any prompt

2. Pending change is lost
   2.1 Open a file in an editor and make a change
   2.2 Touch the file on the remote host to create a conflict
   2.3 Click the Save button and conflict is found.
   2.4 Type a new file name in the file name field and save it. The file is not marked as dirty any more 
   2.5 Close the editor
   2.6 Reopen the file and the pending change could not be found
   2.7 Refresh the directory and the new file couldn't be found either

3. Hangs when shut down
   3.1 Open a remote file in the editor and make a change
   3.2 Touch the file on the remote host o create a conflict
   3.3 Shutdown workbench
   3.4 When being prompted, choose to save the file
   3.5 When conflict dialog comes up, choose to replace the content in the editor with the remote file
   3.6 The workbench stays running with the following stack 
Thread.sleep(long, int) line: not available [native method]	
Thread.sleep(long) line: 850	
SystemTempFileListener$TempFileSaveParticipant.saving(ISaveContext) line: 102	
SaveManager.executeLifecycle(int, ISaveParticipant, SaveContext) line: 361	
SaveManager$1.run() line: 170	
SafeRunner.run(ISafeRunnable) line: 42	
SaveManager.broadcastLifecycle(int, Map, MultiStatus, IProgressMonitor) line: 173	
SaveManager.save(int, boolean, Project, IProgressMonitor) line: 1108	
SaveManager.save(int, Project, IProgressMonitor) line: 1087	
DelayedSnapshotJob.run(IProgressMonitor) line: 44	
SaveManager.shutdown(IProgressMonitor) line: 1366	
Workspace.close(IProgressMonitor) line: 428	
ResourcesPlugin.stop(BundleContext) line: 383	
BundleContextImpl$2.run() line: 843	
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: 251	
BundleContextImpl.stop() line: 836	
BundleHost.stopWorker(int) line: 501	
BundleHost(AbstractBundle).suspend(boolean) line: 550	
Framework.suspendBundle(AbstractBundle, boolean) line: 1097	
StartLevelManager.decFWSL(int, AbstractBundle[]) line: 597	
StartLevelManager.doSetStartLevel(int) line: 257	
StartLevelManager.shutdown() line: 215	
InternalSystemBundle.suspend() line: 266	
Framework.shutdown(int) line: 690	
Framework.close() line: 588	
EclipseStarter.shutdown() line: 415	
EclipseStarter.run(String[], Runnable) line: 198	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 45	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 37	
Method.invoke(Object, Object...) line: 599	
Main.invokeFramework(String[], URL[]) line: 619	
Main.basicRun(String[]) line: 574	
Main.run(String[]) line: 1407	
Main.main(String[]) line: 1383
Comment 13 David McKnight CLA 2011-02-15 15:43:58 EST
(In reply to comment #12)
> Hi Dave,
> The following scenarios failed for the latest patch.
> 
> 1. Replace with remote copy after Cancel
>    1.1 Open a file in an editor and make a change
>    1.2 Touch the file on the remote host to create a conflict
>    1.3 Click the Save button and conflict is found.
>    1.4 Cancel the conflict dialog
>    1.5 Click the Save button again
>    1.6 When the conflict dialog comes up again, select to replace the content
> in the editor with the remote file
>    1.7 The file is still marked as dirty in the editor with the pending change
> and the remote file still contained the old content
>    1.8 Click the Save button for the third time
>    1.9 The pending change was written to the remote file without any prompt
> 

When I try this, I get the following dialog after step 1.6:

"The file <filename> has been changed on the file system.  Do you want to replace the editor contents with these changes?"

I click "Yes" and the editor gets replaced with the remote content, while the dirty flag goes away.



> 2. Pending change is lost
>    2.1 Open a file in an editor and make a change
>    2.2 Touch the file on the remote host to create a conflict
>    2.3 Click the Save button and conflict is found.
>    2.4 Type a new file name in the file name field and save it. The file is not
> marked as dirty any more 
>    2.5 Close the editor
>    2.6 Reopen the file and the pending change could not be found
>    2.7 Refresh the directory and the new file couldn't be found either
> 


This works for me too.  In step 2.4, I use the file dialog to quality the path.  Are you not qualifying the new file name?


> 3. Hangs when shut down
>    3.1 Open a remote file in the editor and make a change
>    3.2 Touch the file on the remote host o create a conflict
>    3.3 Shutdown workbench
>    3.4 When being prompted, choose to save the file
>    3.5 When conflict dialog comes up, choose to replace the content in the
> editor with the remote file
>    3.6 The workbench stays running with the following stack 
> Thread.sleep(long, int) line: not available [native method]    
> Thread.sleep(long) line: 850    
> SystemTempFileListener$TempFileSaveParticipant.saving(ISaveContext) line: 102   
> SaveManager.executeLifecycle(int, ISaveParticipant, SaveContext) line: 361    
> SaveManager$1.run() line: 170    

This works for me; the workbench shuts down completely without any hang.  Does this happen consistently for you?
Comment 14 Samuel Wu CLA 2011-02-16 16:22:10 EST
The third problem, Hangs when shut down, only happens in my runtime workbench. It can be ignored. 
An environment has been set up for the other two problems for Dave to investigate.
Comment 15 David McKnight CLA 2011-02-17 16:15:19 EST
Created attachment 189230 [details]
updated patch with keyhandling for save as and editor focus

The problem with the first scenario turns out to be that the editor was not in focus so the dialog never came up.  Once the dialog comes into focus it will come up but it's possible that a user will be confused and might even close the editor without giving it a chance to update.  To address this, I've put code in to make the editor come into focus after a replace with remote.  

The save as problem is reproduced when the user types the path only (the dialog can't be used).  I've added code to handle that case too.
Comment 16 David McKnight CLA 2011-02-17 16:27:23 EST
I've committed the changes to cvs.  Please reopen if you run into any other conflict issue.
Comment 17 Samuel Wu CLA 2011-02-17 17:00:22 EST
Hi Dave,
The patch looks fine. Can you add it t the 3.2.2 build? thanks a lot.
Comment 18 David McKnight CLA 2011-02-22 11:02:03 EST
(In reply to comment #17)
> Hi Dave,
> The patch looks fine. Can you add it t the 3.2.2 build? thanks a lot.

I've opened bug 337852 for the 3.2.x backport.
Comment 19 Martin Oberhuber CLA 2011-02-28 12:19:54 EST
You are introducing Platform non-API use here:
    Workbench.getInstance()

This is not acceptable. Please use
    PlatformUI.getWorkbench().isClosing()
instead.
Comment 20 David McKnight CLA 2011-02-28 12:38:24 EST
Created attachment 189972 [details]
update to use PlatformUI.getWorkbench().isClosing()
Comment 21 David McKnight CLA 2011-02-28 12:39:27 EST
Committed the update.
Comment 22 Ross Wagner CLA 2011-03-21 15:43:47 EDT
Which plugins were affected by this bug?
Comment 23 David McKnight CLA 2011-03-21 15:48:59 EDT
(In reply to comment #22)
> Which plugins were affected by this bug?

The affected plugins are the following:
org.eclipse.rse.files.ui
org.eclipse.rse.ui