Bug 532417 - Rename refactoring badly messes up code if there are duplicate linked resources due to cmake import
Summary: Rename refactoring badly messes up code if there are duplicate linked resourc...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 9.4.2   Edit
Hardware: PC Mac OS X
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-13 19:12 EDT by Martin Oberhuber CLA
Modified: 2020-09-04 15:19 EDT (History)
1 user (show)

See Also:


Attachments
Screenshot (470.50 KB, image/png)
2018-03-13 19:12 EDT, Martin Oberhuber CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2018-03-13 19:12:51 EDT
Created attachment 273112 [details]
Screenshot

Build ID: CDT Photon M6 (9.5m6) on Eclipse Photon M6 / MacOSX Sierra 10.12.6

If the "Rename Refactoring" finds partial matches and there are multiple Linked Resources pointing to a matching file, the source code gets totally messed up: editor contents still looks correct, but file contents on disk is broken. Even "Refresh" doesn't reload broken contents from disk, so users might notice too late. This is a severe issue as it may cause data loss! Likely affects all hosts and not only MacOSX. See also the lower pane ("Goinkoink") in attached screenshot how file is broken.

I assume the issue occurs, because file contents is replaced multiple times in the same file (ie once per linked resource). The issue occurs on CDT projects generated by cmake, as these typically create duplicate file resources.

Steps to reproduce:
1. git clone https://github.com/moberhuber/refactor-test-suite.git
2. brew install cmake
3. brew install ninja
4. mkdir rft-build && cd rft-build
5. cmake -G'Eclipse CDT4 - Ninja' ../refactor-test-suite
6. In CDT, "Import Existing Projects" from the rft-build directory
7. Open Resource : Rename.cpp
8. In line 53, select the namespace identifier X and Refactor > Rename : Goink
   --> In the "11 Potential Matches" dialog, accept defaults (Preview, OK)
   --> Editor looks OK, but "git diff" on command-line shows the broken file

Workaround : In the "Potential Matches" dialog, deselect the 2nd linked resource occurrence of Rename.cpp

Proposed fix: Make sure that any file shown in the "Partial Matches" dialog from refactoring is unique. Simply hide any duplicates caused by linked resources or symbolic links.