diff options
author | Thomas Watson | 2014-03-10 13:24:42 +0000 |
---|---|---|
committer | Thomas Watson | 2014-03-10 13:24:42 +0000 |
commit | fd27fc11ad0ef046510ef4ec4a20fb3638d243ce (patch) | |
tree | bf2cc8a909b5c7c1831127d3a734d01ebe371da0 | |
parent | 180bc899f1560e348940b0e981ba115a5904da7c (diff) | |
download | rt.equinox.framework-fd27fc11ad0ef046510ef4ec4a20fb3638d243ce.tar.gz rt.equinox.framework-fd27fc11ad0ef046510ef4ec4a20fb3638d243ce.tar.xz rt.equinox.framework-fd27fc11ad0ef046510ef4ec4a20fb3638d243ce.zip |
Bug 429921 - consistency issues with extracting bundle content to cacheI20140311-1200I20140311-0800
-rw-r--r-- | bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java | 31 | ||||
-rw-r--r-- | bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/ZipBundleFile.java | 20 |
2 files changed, 35 insertions, 16 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java index 4f03e86d5..5bed93d0b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java @@ -25,10 +25,12 @@ import org.eclipse.osgi.internal.framework.EquinoxConfiguration; import org.eclipse.osgi.internal.framework.EquinoxContainer; import org.eclipse.osgi.internal.hookregistry.StorageHookFactory; import org.eclipse.osgi.internal.hookregistry.StorageHookFactory.StorageHook; +import org.eclipse.osgi.internal.messages.Msg; import org.eclipse.osgi.storage.bundlefile.BundleEntry; import org.eclipse.osgi.storage.bundlefile.BundleFile; import org.eclipse.osgi.storage.url.BundleResourceHandler; import org.eclipse.osgi.storage.url.bundleentry.Handler; +import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleException; public final class BundleInfo { @@ -263,6 +265,35 @@ public final class BundleInfo { return getStorage().getFile(builder.toString(), true); } + public void storeContent(File destination, InputStream in, boolean nativeCode) throws IOException { + /* the entry has not been cached */ + if (getStorage().getConfiguration().getDebug().DEBUG_GENERAL) + Debug.println("Creating file: " + destination.getPath()); //$NON-NLS-1$ + /* create the necessary directories */ + File dir = new File(destination.getParent()); + if (!dir.mkdirs() && !dir.isDirectory()) { + if (getStorage().getConfiguration().getDebug().DEBUG_GENERAL) + Debug.println("Unable to create directory: " + dir.getPath()); //$NON-NLS-1$ + throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath())); + } + /* copy the entry to the cache */ + File tempDest = File.createTempFile("staged", ".tmp", dir); //$NON-NLS-1$ //$NON-NLS-2$ + StorageUtil.readFile(in, tempDest); + if (destination.exists() || !tempDest.renameTo(destination)) { + // maybe because some other thread already beat us there. + if (destination.exists()) { + // just delete our copy that could not get renamed + tempDest.delete(); + } else { + throw new IOException("Failed to store the extracted content: " + destination); //$NON-NLS-1$ + } + } + + if (nativeCode) { + getBundleInfo().getStorage().setPermissions(destination); + } + } + public BundleInfo getBundleInfo() { return BundleInfo.this; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/ZipBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/ZipBundleFile.java index 05a96cc9a..853ad370b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/ZipBundleFile.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/ZipBundleFile.java @@ -18,10 +18,11 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent; import org.eclipse.osgi.container.ModuleRevision; +import org.eclipse.osgi.framework.log.FrameworkLogEntry; import org.eclipse.osgi.internal.debug.Debug; +import org.eclipse.osgi.internal.framework.EquinoxContainer; import org.eclipse.osgi.internal.messages.Msg; import org.eclipse.osgi.storage.BundleInfo; -import org.eclipse.osgi.storage.StorageUtil; import org.eclipse.osgi.util.NLS; /** @@ -182,21 +183,7 @@ public class ZipBundleFile extends BundleFile { InputStream in = zipFile.getInputStream(zipEntry); if (in == null) return null; - /* the entry has not been cached */ - if (debug.DEBUG_GENERAL) - Debug.println("Creating file: " + nested.getPath()); //$NON-NLS-1$ - /* create the necessary directories */ - File dir = new File(nested.getParent()); - if (!dir.mkdirs() && !dir.isDirectory()) { - if (debug.DEBUG_GENERAL) - Debug.println("Unable to create directory: " + dir.getPath()); //$NON-NLS-1$ - throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath())); - } - /* copy the entry to the cache */ - StorageUtil.readFile(in, nested); - if (nativeCode) { - generation.getBundleInfo().getStorage().setPermissions(nested); - } + generation.storeContent(nested, in, nativeCode); } } @@ -205,6 +192,7 @@ public class ZipBundleFile extends BundleFile { } catch (IOException e) { if (debug.DEBUG_GENERAL) Debug.printStackTrace(e); + generation.getBundleInfo().getStorage().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Unable to extract content: " + generation.getRevision() + ": " + entry, e); //$NON-NLS-1$ //$NON-NLS-2$ } return null; } |