Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 343977 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java (-7 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 225-231 Link Here
225
		IPath location = workspace.getMetaArea().getSafeTableLocationFor(ResourcesPlugin.PI_RESOURCES);
225
		IPath location = workspace.getMetaArea().getSafeTableLocationFor(ResourcesPlugin.PI_RESOURCES);
226
		IPath backup = workspace.getMetaArea().getBackupLocationFor(location);
226
		IPath backup = workspace.getMetaArea().getBackupLocationFor(location);
227
		try {
227
		try {
228
			saveMasterTable(backup);
228
			saveMasterTable(ISaveContext.FULL_SAVE, backup);
229
		} catch (CoreException e) {
229
		} catch (CoreException e) {
230
			Policy.log(e.getStatus());
230
			Policy.log(e.getStatus());
231
			backup.toFile().delete();
231
			backup.toFile().delete();
Lines 234-240 Link Here
234
		if (location.toFile().exists() && !location.toFile().delete())
234
		if (location.toFile().exists() && !location.toFile().delete())
235
			return;
235
			return;
236
		try {
236
		try {
237
			saveMasterTable(location);
237
			saveMasterTable(ISaveContext.FULL_SAVE, location);
238
		} catch (CoreException e) {
238
		} catch (CoreException e) {
239
			Policy.log(e.getStatus());
239
			Policy.log(e.getStatus());
240
			location.toFile().delete();
240
			location.toFile().delete();
Lines 1194-1200 Link Here
1194
					if (kind == ISaveContext.FULL_SAVE)
1194
					if (kind == ISaveContext.FULL_SAVE)
1195
						removeClearDeltaMarks();
1195
						removeClearDeltaMarks();
1196
					//this must be done after committing save contexts to update participant save numbers
1196
					//this must be done after committing save contexts to update participant save numbers
1197
					saveMasterTable();
1197
					saveMasterTable(kind);
1198
					broadcastLifecycle(DONE_SAVING, contexts, warnings, Policy.subMonitorFor(monitor, 1));
1198
					broadcastLifecycle(DONE_SAVING, contexts, warnings, Policy.subMonitorFor(monitor, 1));
1199
					hookEndSave(kind, project, start);
1199
					hookEndSave(kind, project, start);
1200
					return warnings;
1200
					return warnings;
Lines 1216-1229 Link Here
1216
		}
1216
		}
1217
	}
1217
	}
1218
1218
1219
	protected void saveMasterTable() throws CoreException {
1219
	protected void saveMasterTable(int kind) throws CoreException {
1220
		saveMasterTable(workspace.getMetaArea().getSafeTableLocationFor(ResourcesPlugin.PI_RESOURCES));
1220
		saveMasterTable(kind, workspace.getMetaArea().getSafeTableLocationFor(ResourcesPlugin.PI_RESOURCES));
1221
	}
1221
	}
1222
1222
1223
	protected void saveMasterTable(IPath location) throws CoreException {
1223
	protected void saveMasterTable(int kind, IPath location) throws CoreException {
1224
		long start = System.currentTimeMillis();
1224
		long start = System.currentTimeMillis();
1225
		java.io.File target = location.toFile();
1225
		java.io.File target = location.toFile();
1226
		try {
1226
		try {
1227
			if (kind == ISaveContext.FULL_SAVE || kind == ISaveContext.SNAPSHOT)
1228
				validateMasterTableBeforeSave(target);
1227
			SafeChunkyOutputStream output = new SafeChunkyOutputStream(target);
1229
			SafeChunkyOutputStream output = new SafeChunkyOutputStream(target);
1228
			try {
1230
			try {
1229
				masterTable.store(output, "master table"); //$NON-NLS-1$
1231
				masterTable.store(output, "master table"); //$NON-NLS-1$
Lines 1545-1550 Link Here
1545
			masterTable.setProperty(key, Long.toString(System.currentTimeMillis()));
1547
			masterTable.setProperty(key, Long.toString(System.currentTimeMillis()));
1546
	}
1548
	}
1547
1549
1550
	private void validateMasterTableBeforeSave(java.io.File target) throws IOException {
1551
		if (target.exists()) {
1552
			MasterTable previousMasterTable = new MasterTable();
1553
			SafeChunkyInputStream input = new SafeChunkyInputStream(target);
1554
			try {
1555
				previousMasterTable.load(input);
1556
				String stringValue = previousMasterTable.getProperty(ROOT_SEQUENCE_NUMBER_KEY);
1557
				// if there was a full save, then there must be a non-null entry for root
1558
				if (stringValue != null) {
1559
					int valueInFile = new Integer(stringValue).intValue();
1560
					int valueInMemory = new Integer(masterTable.getProperty(ROOT_SEQUENCE_NUMBER_KEY)).intValue();
1561
					// new master table must provide greater or equal sequence number for root
1562
					// throw exception if new value is lower than previous one - we cannot allow to desynchronize master table on disk
1563
					String message = "Cannot set lower sequence number for root (previous: " + valueInFile + ", new: " + valueInMemory + "). Location: " + target.getAbsolutePath(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1564
					Assert.isLegal(valueInMemory >= valueInFile, message);
1565
				}
1566
			} finally {
1567
				input.close();
1568
			}
1569
		}
1570
	}
1571
1548
	/**
1572
	/**
1549
	 * Visit the given resource (to depth infinite) and write out extra information
1573
	 * Visit the given resource (to depth infinite) and write out extra information
1550
	 * like markers and sync info. To be called during a full save and project save.
1574
	 * like markers and sync info. To be called during a full save and project save.

Return to bug 343977