Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 307140 - Refator->Move a project to subdirectory deletes it
Summary: Refator->Move a project to subdirectory deletes it
Status: CLOSED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.2.1   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Malgorzata Janczarska CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 339814 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-03-25 17:08 EDT by metronware CLA
Modified: 2011-11-09 08:14 EST (History)
5 users (show)

See Also:


Attachments
Changes "move" opperation on FileStore (2.02 KB, patch)
2010-10-07 05:43 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
Validation fix (1.36 KB, patch)
2010-10-07 05:43 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
Fixed validation and added jUnit (5.14 KB, patch)
2010-10-08 10:44 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
Fixed validation and added jUnit (refactored) (4.27 KB, patch)
2010-10-08 11:36 EDT, Malgorzata Janczarska CLA
Szymon.Brandys: iplog+
Details | Diff
Enhanced test (1.15 KB, patch)
2011-09-08 10:16 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
Enhanced test that fails (2.26 KB, patch)
2011-09-19 08:44 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
fix with test (3.74 KB, patch)
2011-09-19 11:15 EDT, Malgorzata Janczarska CLA
no flags Details | Diff
Message displayed (37.12 KB, image/png)
2011-09-23 08:34 EDT, Malgorzata Janczarska CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description metronware CLA 2010-03-25 17:08:32 EDT
Build Identifier: M20060921-0945

Trying to move a project using the eclipse IDE, from its original location to a subdirectory of that location, will delete it instead!

Reproducible: Always

Steps to Reproduce:
1. Select a project from the workspace
2. Right click on it and select Refactor->Move (Shift+Alt+V)
3. If the project directory is "/home/workspace/project", the location should be set to a subdirectory such as "/home/workspace/project/code"
4. Press OK and your entire project will be deleted!
Comment 1 Francis Upton IV CLA 2010-03-25 17:11:28 EDT
If I counted right, you are on 3.2.1, which is pretty ancient. Can you try this on 3.5.2? Also, you did not specify if you are using the Project Explorer or Package Explorer (they go to different departments around here).
Comment 2 Remy Suen CLA 2010-03-25 21:01:16 EDT
I tried this on Windows 7 with an e4 I20100319-2100 build.

Package Explorer:
My 'src/' folder and .classpath file was destroyed.

Project Explorer:
Same as above.

Navigator:
Same as above.
Comment 3 Remy Suen CLA 2010-03-25 21:04:21 EDT
Attempting to undo did not work. It seems the move operation alone caused exceptions to be written to the log.

!ENTRY org.eclipse.core.resources 4 1 2010-03-25 21:02:56.406
!MESSAGE Internal Error
!STACK 1
org.eclipse.core.runtime.CoreException: File not found: D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test\code\.project.
	at org.eclipse.core.internal.filesystem.Policy.error(Policy.java:55)
	at org.eclipse.core.internal.filesystem.local.LocalFile.openInputStream(LocalFile.java:371)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:702)
	at org.eclipse.core.internal.resources.File.getContents(File.java:293)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.descriptionChanged(FileSystemResourceManager.java:287)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.internalWrite(FileSystemResourceManager.java:548)
	at org.eclipse.core.internal.resources.Project.writeDescription(Project.java:1253)
	at org.eclipse.core.internal.resources.Project.writeDescription(Project.java:1234)
	at org.eclipse.core.internal.resources.ResourceTree.movedProjectSubtree(ResourceTree.java:702)
	at org.eclipse.core.internal.resources.ResourceTree.standardMoveProject(ResourceTree.java:1085)
	at org.eclipse.core.internal.resources.Project.move(Project.java:882)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.moveProject(MoveProjectOperation.java:167)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.doExecute(MoveProjectOperation.java:135)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation$1.run(AbstractWorkspaceOperation.java:206)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation.execute(AbstractWorkspaceOperation.java:204)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
	at org.eclipse.ui.actions.MoveProjectAction$1.run(MoveProjectAction.java:112)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: java.io.FileNotFoundException: D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test\code\.project (The system cannot find the path specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at org.eclipse.core.internal.filesystem.local.LocalFile.openInputStream(LocalFile.java:362)
	... 17 more
!SUBENTRY 1 org.eclipse.core.filesystem 4 271 2010-03-25 21:02:56.407
!MESSAGE File not found: D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test\code\.project.
!STACK 0
java.io.FileNotFoundException: D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test\code\.project (The system cannot find the path specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at org.eclipse.core.internal.filesystem.local.LocalFile.openInputStream(LocalFile.java:362)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:702)
	at org.eclipse.core.internal.resources.File.getContents(File.java:293)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.descriptionChanged(FileSystemResourceManager.java:287)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.internalWrite(FileSystemResourceManager.java:548)
	at org.eclipse.core.internal.resources.Project.writeDescription(Project.java:1253)
	at org.eclipse.core.internal.resources.Project.writeDescription(Project.java:1234)
	at org.eclipse.core.internal.resources.ResourceTree.movedProjectSubtree(ResourceTree.java:702)
	at org.eclipse.core.internal.resources.ResourceTree.standardMoveProject(ResourceTree.java:1085)
	at org.eclipse.core.internal.resources.Project.move(Project.java:882)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.moveProject(MoveProjectOperation.java:167)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.doExecute(MoveProjectOperation.java:135)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation$1.run(AbstractWorkspaceOperation.java:206)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation.execute(AbstractWorkspaceOperation.java:204)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
	at org.eclipse.ui.actions.MoveProjectAction$1.run(MoveProjectAction.java:112)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

!ENTRY org.eclipse.ui 4 4 2010-03-25 21:03:18.366
!MESSAGE Problems encountered while moving resources.

!ENTRY org.eclipse.ui 4 0 2010-03-25 21:03:18.367
!MESSAGE Problems encountered while moving resources.
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Problems encountered while moving resources.
	at org.eclipse.core.internal.resources.Project.move(Project.java:889)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.moveProject(MoveProjectOperation.java:167)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.doExecute(MoveProjectOperation.java:135)
	at org.eclipse.ui.ide.undo.MoveProjectOperation.doUndo(MoveProjectOperation.java:150)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation$3.run(AbstractWorkspaceOperation.java:287)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ui.ide.undo.AbstractWorkspaceOperation.undo(AbstractWorkspaceOperation.java:285)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.doUndo(DefaultOperationHistory.java:415)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.undo(DefaultOperationHistory.java:1280)
	at org.eclipse.ui.operations.UndoActionHandler.runCommand(UndoActionHandler.java:78)
	at org.eclipse.ui.operations.OperationHistoryActionHandler$4.run(OperationHistoryActionHandler.java:311)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Contains: Resource already exists on disk: 'D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test'.
!SUBENTRY 1 org.eclipse.core.resources 1 4 2010-03-25 21:03:18.368
!MESSAGE Problems encountered while moving resources.
!SUBENTRY 2 org.eclipse.core.resources 1 4 2010-03-25 21:03:18.368
!MESSAGE Resource already exists on disk: 'D:\eclipse-e4-SDK-incubation-I20100319-2100-win32\ws\test'.
Comment 4 Remy Suen CLA 2010-03-26 09:45:24 EDT
Resources, please take a look.
Comment 5 Malgorzata Janczarska CLA 2010-10-07 05:43:07 EDT
Created attachment 180402 [details]
Changes "move" opperation on FileStore
Comment 6 Malgorzata Janczarska CLA 2010-10-07 05:43:59 EDT
Created attachment 180403 [details]
Validation fix
Comment 7 Malgorzata Janczarska CLA 2010-10-07 05:55:34 EDT
I've investigated this bug and it's caused by our implementation of "move" opperation on file store. The move function first copies the given resouce to its destination than deletes the oryginal resource. If we are trying to move a folder into its own subfolder than first it's copied than it's deleting while deleting it's first location. I've attached a fix for this using the temporary folder while moving, however I relize that this is a big change in file handling and you may hasitate to commit it.

I think that the first intention was to prevent user from moving the project into it's own directory. I noticed that validation prevents this change but only when project is situated in non-default folder. I tried to move back in the file history to find out why default locations are not validated but it seems that it has been introduced in the initial version of the validator. The second fix I submitted changes the validator so that it verifies all projects, including those located in default locations.
Comment 8 Szymon Brandys CLA 2010-10-08 10:23:45 EDT
(In reply to comment #7)
> I think that the first intention was to prevent user from moving the project
> into it's own directory. I noticed that validation prevents this change but only
> when project is situated in non-default folder.

Right, the second proposal looks better. Just add some tests, please.
Comment 9 Malgorzata Janczarska CLA 2010-10-08 10:44:58 EDT
Created attachment 180490 [details]
Fixed validation and added jUnit
Comment 10 Malgorzata Janczarska CLA 2010-10-08 11:36:17 EDT
Created attachment 180497 [details]
Fixed validation and added jUnit (refactored)
Comment 11 Szymon Brandys CLA 2010-10-08 12:40:07 EDT
I made some changes in the tests. Otherwise looks good. Thanks.
Comment 12 John Arthorne CLA 2011-05-30 09:11:02 EDT
*** Bug 339814 has been marked as a duplicate of this bug. ***
Comment 13 Robin Rosenberg CLA 2011-08-23 16:57:51 EDT
Hi, sorry for being so late with the follow-up, but this till fails with 3.7.0

I can no longer reproduce from the GUI, because it prevents it, but at the API
level the standardMove operation deletes everything.

		// Before
		//		/Users/me/SW/junit-workspace//P
		//		/Users/me/SW/junit-workspace//P/Project-1
		//		/Users/me/SW/junit-workspace//P/Project-1/.classpath
		//		/Users/me/SW/junit-workspace//P/Project-1/.git
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/branches
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/config
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/HEAD
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/hooks
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/index
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/logs
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/logs/refs
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/logs/refs/heads
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/objects
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/objects/b6
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/objects/b6/49a9bf89116c581f8329b8ec3c79a86a70be04
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/objects/info
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/objects/pack
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/refs
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/refs/heads
		//		/Users/me/SW/junit-workspace//P/Project-1/.git/refs/tags
		//		/Users/me/SW/junit-workspace//P/Project-1/.project
		//		/Users/me/SW/junit-workspace//P/Project-1/bin
		//		/Users/me/SW/junit-workspace//P/Project-1/file.txt
After:
		// With 3.7 and earlier
		//		/Users/me/SW/junit-workspace//P
		//		/Users/me/SW/junit-workspace//P/Project-1
		//		/Users/me/SW/junit-workspace//P/Project-1/P2
		//		/Users/me/SW/junit-workspace//P/Project-1/P2/.project
		//		/Users/me/SW/junit-workspace//P/Project-1/P2/bin
		//		/Users/me/SW/junit-workspace//P/Project-1/P2/bin/.project

One thing about the test in the attachment: I don't see where it tests that it actually does what
is tries to do. Not crashing is not the same as passing a test.
Comment 14 Martin Oberhuber CLA 2011-09-08 04:42:21 EDT
The target milestone is confusing ... since the UI issue is fixed and only the API affected I'd suggest closing this and cloning a new bug for the API issue?
Comment 15 Szymon Brandys CLA 2011-09-08 06:08:09 EDT
Gosia, please comment.
Comment 16 Robin Rosenberg CLA 2011-09-08 09:48:02 EDT
As i interpret the issue, it's not a UI issue. 

The user actually wants to do this, at least that is what I wanted to do in Bug 339814.
Comment 17 Malgorzata Janczarska CLA 2011-09-08 10:16:16 EDT
Created attachment 202991 [details]
Enhanced test

Robin, I'm attaching patch that enhances the test with some checks ensuring if contents of project was not deleted. The previous test only checked if an attempt to move the project to its subfolder returns an error, because before that it didn't. Attached test passes in my workspace, so I suppose the test doesn't exactly reflect your scenario.
Could you attach a test that fails or a code snippet that would help me to create a failing test?
And also could you attach the exact build id?
Comment 18 Robin Rosenberg CLA 2011-09-17 18:48:50 EDT
See http://egit.eclipse.org/r/#change,2727 patch 12 

http://egit.eclipse.org/r/#patch,sidebyside,2727,12,org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java

The test method is testMoveProjectWithinGitRepoMoveFromLevelZeroDownOne

Build id is Build id: I20110613-1736
Comment 19 Robin Rosenberg CLA 2011-09-18 15:59:57 EDT
http://egit.eclipse.org/r/#change,2727 patch 14 does not evade the bug, but fails the tests instead.
Comment 20 Malgorzata Janczarska CLA 2011-09-19 08:44:28 EDT
Created attachment 203583 [details]
Enhanced test that fails

Thank you for the code, Robin.
The difference between the two tests is that in your test the project name has been change as well. I modified my test to change the name as well and now it fails, so I know where to search for the bug.
Comment 21 Malgorzata Janczarska CLA 2011-09-19 11:15:05 EDT
Created attachment 203604 [details]
fix with test

This patch contains proposition of solution. The problem was that location is validated by Workspace.validateProjectLocationURI(project, location), but the "project" argument was not the current project, but the destination project. Those were the same projects only if the project name wasn't meant to be changed. The destination project may not exist yet or even more it might have been a completely different project if a project of given name existed in the workspace. The location validator assumed that for projects that are supposed to be moved/copied variable "project" contains the source project and not only used its current location for validation but also if project existed it validated some of its contents. So passing destination instead of a source project broke the validation.
Maybe it's not a bad idea to change the javadoc for Workspace#validateProjectLocationURI(project, location) as well.
Comment 22 Robin Rosenberg CLA 2011-09-22 12:42:04 EDT
(In reply to comment #21)
> Created attachment 203604 [details]
> fix with test
> 

I grabbed R3_7 of core resources, applied this patch, disabled the UI check, created a project and tried to move it down one level. The content of the project was deleted.

The code still fails to rename the project to the subtree and goes down the copy/delete path.
Comment 23 Malgorzata Janczarska CLA 2011-09-23 08:34:53 EDT
Created attachment 203895 [details]
Message displayed
Comment 24 Malgorzata Janczarska CLA 2011-09-23 09:08:50 EDT
(In reply to comment #22)
> (In reply to comment #21)
> > Created attachment 203604 [details]
> > fix with test
> >
> 
> I grabbed R3_7 of core resources, applied this patch, disabled the UI check,
> created a project and tried to move it down one level. The content of the
> project was deleted.
> 
> The code still fails to rename the project to the subtree and goes down the
> copy/delete path.
Robin, I did just the same: replaced my resources with R3_7, applied the patch, removed validation from org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea#checkValidLocation, then I run Eclipse and create a project in "Test1" in default location. Then I went to Refactor->Move and I've chosen location "[workspaceLocation]\Test1\Test1" which was a subdirectory of project Test1. Then I get an error message attached in attachment 203895 [details]. My project is not moved, but nothing get deleted. I tried also with existing and non existing subfolders and with non-default project locations also outside the workspace directory. I always get the same error message and nothing gets deleted.
Maybe you could create a test that fails or attach a workspace with a project that can't be moved into its subfolder?
Comment 25 Szymon Brandys CLA 2011-11-07 05:29:46 EST
Gosia, please open a separate bug for the Robin's case and attach your patch there. Set the new bug for 3.8M4 and close Bug 307140.
Comment 26 Malgorzata Janczarska CLA 2011-11-07 09:34:42 EST
(In reply to comment #25)
> Gosia, please open a separate bug for the Robin's case and attach your patch
> there. Set the new bug for 3.8M4 and close Bug 307140.

Done, the new bug is Bug 363048.