diff options
author | Thomas Watson | 2019-03-28 14:06:11 +0000 |
---|---|---|
committer | Thomas Watson | 2019-03-28 14:08:23 +0000 |
commit | 39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d (patch) | |
tree | 81adcdd91d61a28373cb962a3b11b9317dd56805 | |
parent | b8ef56795cacdff976ba95a295f678a60f2dab57 (diff) | |
download | rt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.tar.gz rt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.tar.xz rt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.zip |
Bug 545788 - Add a check for cache versionI20190331-1800I20190330-1800I20190329-1800I20190329-0120I20190328-1800
A cache version is needed incase the format
of the cache needs to change in the future.
Change-Id: If5cf8d7efde1b0bee1381a570191c0d38627b1bd
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
3 files changed, 16 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java index 446523df5..67518dc83 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java @@ -231,7 +231,7 @@ public class Activator implements BundleActivator { try { service.load(bundleCtx, logService, mtpTracker); } catch (IOException e) { - logService.log(LogTracker.LOG_ERROR, "Error loading cached metatype info.", e); //$NON-NLS-1$ + logService.log(LogTracker.LOG_WARNING, "Error loading cached metatype info.", e); //$NON-NLS-1$ } ServiceRegistration<?> registration = bundleCtx.registerService(new String[] {MetaTypeService.class.getName(), EquinoxMetaTypeService.class.getName()}, service, properties); synchronized (this) { @@ -260,7 +260,7 @@ public class Activator implements BundleActivator { try { service.save(bundleCtx); } catch (IOException e) { - logService.log(LogTracker.LOG_ERROR, "Error saving metatype cache.", e); //$NON-NLS-1$ + logService.log(LogTracker.LOG_WARNING, "Error saving metatype cache.", e); //$NON-NLS-1$ } } } diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java index a87275e3d..31f56fdb1 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java @@ -145,7 +145,10 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB BundleContext systemContext = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext(); if (cache.isFile()) { try (Reader reader = new Reader(new DataInputStream(new BufferedInputStream(new FileInputStream(cache))))) { - + if (!reader.isValidPersistenceVersion()) { + logger.log(LogTracker.LOG_INFO, "Metatype cache version is not supported. Ignoring cache."); //$NON-NLS-1$ + return; + } int numService = reader.readInt(); for (int i = 0; i < numService; i++) { long id = reader.readLong(); @@ -171,6 +174,7 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB void save(BundleContext context) throws IOException { File cache = context.getDataFile(CACHE_FILE); try (Writer writer = new Writer(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(cache))))) { + writer.writePersistenceVersion(); List<MetaTypeInformation> serviceInfos = new ArrayList<>(); List<MetaTypeInformationImpl> xmlInfos = new ArrayList<>(); synchronized (_mtps) { diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java index da3212b10..a0e6ea2fb 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java @@ -18,7 +18,7 @@ import java.util.*; *******************************************************************************/ public class Persistence { - + private static final int PERSISTENCE_VERSION = 0; private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$ private static final byte NULL = 0; private static final byte OBJECT = 1; @@ -36,6 +36,10 @@ public class Persistence { this.in = in; } + public boolean isValidPersistenceVersion() throws IOException { + return in.readInt() == PERSISTENCE_VERSION; + } + public void readIndexedStrings() throws IOException { int num = in.readInt(); for (int i = 0; i < num; i++) { @@ -117,6 +121,10 @@ public class Persistence { this.out = out; } + public void writePersistenceVersion() throws IOException { + out.writeInt(PERSISTENCE_VERSION); + } + public void writeIndexedStrings(Set<String> strings) throws IOException { strings.remove(null); // do not index null out.writeInt(strings.size()); |