mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 11:15:38 +02:00
Bug 311189 Settings changed / lost after project set re-import. IResource#getModificationStamp doesn't honour the API contract. It may return an identical stamp even if the underlying resource has been removed and re-added.
This commit is contained in:
parent
7b265afa4e
commit
1347433fa7
2 changed files with 27 additions and 7 deletions
|
@ -286,11 +286,12 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
||||||
/**
|
/**
|
||||||
* Method to check whether the description has been modified externally.
|
* Method to check whether the description has been modified externally.
|
||||||
* If so the current read-only descriptor is nullified.
|
* If so the current read-only descriptor is nullified.
|
||||||
|
* It updates the cached modification stamp
|
||||||
* @return boolean indicating whether reload is needed
|
* @return boolean indicating whether reload is needed
|
||||||
*/
|
*/
|
||||||
protected synchronized boolean checkExternalModification() {
|
protected synchronized boolean checkExternalModification() {
|
||||||
// If loaded, and we have cached the modification stamp, reload
|
// If loaded, and we have cached the modification stamp, reload
|
||||||
long currentModificationStamp = project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME).getModificationStamp();
|
long currentModificationStamp = getModificationStamp(project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME));
|
||||||
if (projectModificaitonStamp != currentModificationStamp) {
|
if (projectModificaitonStamp != currentModificationStamp) {
|
||||||
setCurrentDescription(null, true);
|
setCurrentDescription(null, true);
|
||||||
projectModificaitonStamp = currentModificationStamp;
|
projectModificaitonStamp = currentModificationStamp;
|
||||||
|
@ -299,6 +300,22 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the modification stamp for the resource.
|
||||||
|
* If the returned value has changed since last call to
|
||||||
|
* {@link #getModificationStamp(IResource)}, then the resource has changed.
|
||||||
|
* @param resource IResource to fetch modification stamp for
|
||||||
|
* @return long modification stamp
|
||||||
|
*/
|
||||||
|
protected long getModificationStamp(IResource resource) {
|
||||||
|
// The modification stamp is based on the ResourceInfo modStamp and file store modification time. Note that
|
||||||
|
// because of bug 160728 subsequent generations of resources may have the same modStamp. Until this is fixed
|
||||||
|
// the suggested solution is to use modStamp + modTime
|
||||||
|
//
|
||||||
|
// Both values are cached in resourceInfo, so this is fast.
|
||||||
|
return resource.getModificationStamp() + resource.getLocalTimeStamp();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a writable version of the description
|
* Create a writable version of the description
|
||||||
*
|
*
|
||||||
|
@ -462,7 +479,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
||||||
InternalXmlStorageElement storage = createStorage(project, ICProjectDescriptionStorageType.STORAGE_FILE_NAME, true, false, false);
|
InternalXmlStorageElement storage = createStorage(project, ICProjectDescriptionStorageType.STORAGE_FILE_NAME, true, false, false);
|
||||||
try {
|
try {
|
||||||
// Update the modification stamp
|
// Update the modification stamp
|
||||||
projectModificaitonStamp = project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME).getModificationStamp();
|
projectModificaitonStamp = getModificationStamp(project.getFile(ICProjectDescriptionStorageType.STORAGE_FILE_NAME));
|
||||||
CProjectDescription des = new CProjectDescription(project, new XmlStorage(storage), storage, true, false);
|
CProjectDescription des = new CProjectDescription(project, new XmlStorage(storage), storage, true, false);
|
||||||
try {
|
try {
|
||||||
setThreadLocalProjectDesc(des);
|
setThreadLocalProjectDesc(des);
|
||||||
|
@ -571,7 +588,7 @@ public class XmlProjectDescriptionStorage extends AbstractCProjectDescriptionSto
|
||||||
} else {
|
} else {
|
||||||
projectFile.create(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor()); //$NON-NLS-1$
|
projectFile.create(new ByteArrayInputStream(utfString.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return projectFile.getModificationStamp();
|
return getModificationStamp(projectFile);
|
||||||
} finally {
|
} finally {
|
||||||
Job.getJobManager().endRule(rule);
|
Job.getJobManager().endRule(rule);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,13 +90,15 @@ public class XmlProjectDescriptionStorage2 extends XmlProjectDescriptionStorage
|
||||||
try {
|
try {
|
||||||
project.getFolder(STORAGE_FOLDER_NAME).accept(new IResourceProxyVisitor() {
|
project.getFolder(STORAGE_FOLDER_NAME).accept(new IResourceProxyVisitor() {
|
||||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||||
if (modificationMap.containsKey(proxy.getName()))
|
if (modificationMap.containsKey(proxy.getName())) {
|
||||||
if (modificationMap.get(proxy.getName()) != proxy.getModificationStamp()) {
|
long modStamp = getModificationStamp(proxy.requestResource());
|
||||||
|
if (modificationMap.get(proxy.getName()) != modStamp) {
|
||||||
// There may be old storages in here, ensure we don't infinite reload...
|
// There may be old storages in here, ensure we don't infinite reload...
|
||||||
modificationMap.put(proxy.getName(), proxy.getModificationStamp());
|
modificationMap.put(proxy.getName(), modStamp);
|
||||||
setCurrentDescription(null, true);
|
setCurrentDescription(null, true);
|
||||||
needReload[0] = true;
|
needReload[0] = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}, IResource.NONE);
|
}, IResource.NONE);
|
||||||
|
@ -134,7 +136,8 @@ public class XmlProjectDescriptionStorage2 extends XmlProjectDescriptionStorage
|
||||||
currEl.getAttribute(EXTERNAL_CELEMENT_KEY),
|
currEl.getAttribute(EXTERNAL_CELEMENT_KEY),
|
||||||
reCreate, createEmptyIfNotFound, readOnly);
|
reCreate, createEmptyIfNotFound, readOnly);
|
||||||
// Update the modification stamp
|
// Update the modification stamp
|
||||||
modificationMap.put(currEl.getAttribute(EXTERNAL_CELEMENT_KEY), project.getFolder(STORAGE_FOLDER_NAME).getFile(currEl.getAttribute(EXTERNAL_CELEMENT_KEY)).getModificationStamp());
|
modificationMap.put(currEl.getAttribute(EXTERNAL_CELEMENT_KEY),
|
||||||
|
getModificationStamp(project.getFolder(STORAGE_FOLDER_NAME).getFile(currEl.getAttribute(EXTERNAL_CELEMENT_KEY))));
|
||||||
|
|
||||||
ICStorageElement currParent = currEl.getParent();
|
ICStorageElement currParent = currEl.getParent();
|
||||||
// Get the storageModule element in the new Document
|
// Get the storageModule element in the new Document
|
||||||
|
|
Loading…
Add table
Reference in a new issue