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

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

Return to bug 343977