### Eclipse Workspace Patch 1.0 #P org.eclipse.core.resources Index: src/org/eclipse/core/internal/resources/LocalMetaArea.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/LocalMetaArea.java,v retrieving revision 1.42 diff -u -r1.42 LocalMetaArea.java --- src/org/eclipse/core/internal/resources/LocalMetaArea.java 4 Mar 2010 23:02:51 -0000 1.42 +++ src/org/eclipse/core/internal/resources/LocalMetaArea.java 2 Jun 2010 10:21:02 -0000 @@ -219,6 +219,62 @@ return locationFor(target).append(sequenceNumber + F_TREE); } + void validate() throws CoreException{ + IPath treeLocation = getTreeLocationFor(getWorkspace().getRoot(), false); + IPath tempLocation = getBackupLocationFor(treeLocation); + if (!treeLocation.toFile().exists() && !tempLocation.toFile().exists()) { + //do not panic yet, it still may be possible to recover, if we can + // force the consistency between the version in the .tree name and in master table + // TODO: the same kind of checking must be done for .bak files + + // get the sequence number from the master table + String key = getWorkspace().getRoot().getFullPath().append(F_TREE).toString(); + String masterTableSequenceNumber = getWorkspace().getSaveManager().getMasterTable().getProperty(key); + + if (masterTableSequenceNumber == null){ + //nothing in the master table, it looks like first launch + //assume success + return; + } + + //get the sequence number of the stored .tree file + + //list all files + String[] files = treeLocation.removeLastSegments(1).toFile().list(); + + // find the .tree file. ensure that there is only one + // TODO: the case with many .tree files must be investigated further + String matchingTreeFile = null; + for (int i = 0; i < files.length; i++) { + if (files[i].endsWith(F_TREE) && matchingTreeFile == null) { + matchingTreeFile = files[i]; + continue; + } + if (files[i].endsWith(F_TREE)) { + //panic, more than one .tree file + throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, "More than one .tree file, you may need to delete .snap")); //$NON-NLS-1$ + } + } + + // get the sequence number from the .tree file + String fileSequenceNumber = matchingTreeFile.substring(0, matchingTreeFile.indexOf(F_TREE)); + + //fix the master table + getWorkspace().getSaveManager().getMasterTable().setProperty(key, fileSequenceNumber); + + //verify that it was successful operation + treeLocation = getTreeLocationFor(getWorkspace().getRoot(), false); + tempLocation = getBackupLocationFor(treeLocation); + + if (!treeLocation.toFile().exists() && !tempLocation.toFile().exists()) { + //panic NOW! + throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, "Corruption, please delete .snap files!")); //$NON-NLS-1$ + } + + //SUCCESS + } + } + public IPath getWorkingLocation(IResource resource, String id) { return locationFor(resource).append(id); } Index: src/org/eclipse/core/internal/resources/SaveManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java,v retrieving revision 1.105 diff -u -r1.105 SaveManager.java --- src/org/eclipse/core/internal/resources/SaveManager.java 16 Apr 2010 14:26:20 -0000 1.105 +++ src/org/eclipse/core/internal/resources/SaveManager.java 2 Jun 2010 10:21:02 -0000 @@ -966,12 +966,9 @@ */ protected void restoreTree(IProgressMonitor monitor) throws CoreException { long start = System.currentTimeMillis(); + workspace.getMetaArea().validate(); IPath treeLocation = workspace.getMetaArea().getTreeLocationFor(workspace.getRoot(), false); IPath tempLocation = workspace.getMetaArea().getBackupLocationFor(treeLocation); - if (!treeLocation.toFile().exists() && !tempLocation.toFile().exists()) { - savedStates = Collections.synchronizedMap(new HashMap(10)); - return; - } try { DataInputStream input = new DataInputStream(new SafeFileInputStream(treeLocation.toOSString(), tempLocation.toOSString(), TREE_BUFFER_SIZE)); try { @@ -987,6 +984,8 @@ System.out.println("Restore Tree for workspace: " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ } } + + /** * Restores the trees for the builders of this project from the local disk.