diff options
author | Todor Boev | 2015-11-20 10:09:51 +0000 |
---|---|---|
committer | Todor Boev | 2015-11-20 13:45:47 +0000 |
commit | 3ec205e365e062eeaa6fad720ed40c3684fb567b (patch) | |
tree | d3e86110e2a366c1597a56ce14f1bfe835f2aefa | |
parent | f9a4df947e4da913325b8523f9812b59da0cdacb (diff) | |
download | rt.equinox.framework-3ec205e365e062eeaa6fad720ed40c3684fb567b.tar.gz rt.equinox.framework-3ec205e365e062eeaa6fad720ed40c3684fb567b.tar.xz rt.equinox.framework-3ec205e365e062eeaa6fad720ed40c3684fb567b.zip |
Bug 482624 Reformatted according to the org.eclipse.osgi project codeI20151201-0800I20151124-1000I20151124-0800
style.
Signed-off-by: Todor Boev <rinsvind@gmail.com>
Change-Id: I21ea94e5cd512805938996dc512962795d84acdf
4 files changed, 79 insertions, 14 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java index ee0e69d63..357fb7b38 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/debug/Debug.java @@ -40,6 +40,10 @@ public class Debug implements DebugOptionsListener { */ public static final String OPTION_DEBUG_LOADER = ECLIPSE_OSGI + "/debug/loader"; //$NON-NLS-1$ /** + * Storage Debug option key. + */ + public static final String OPTION_DEBUG_STORAGE = ECLIPSE_OSGI + "/debug/storage"; //$NON-NLS-1$ + /** * Events Debug option key. */ public static final String OPTION_DEBUG_EVENTS = ECLIPSE_OSGI + "/debug/events"; //$NON-NLS-1$ @@ -108,6 +112,10 @@ public class Debug implements DebugOptionsListener { */ public boolean DEBUG_LOADER = false; // "debug.loader" /** + * Storage debug flag. + */ + public boolean DEBUG_STORAGE = false; // "debug.storage" + /** * Events debug flag. */ public boolean DEBUG_EVENTS = false; // "debug.events" @@ -169,6 +177,7 @@ public class Debug implements DebugOptionsListener { DEBUG_GENERAL = dbgOptions.getBooleanOption(OPTION_DEBUG_GENERAL, false); DEBUG_BUNDLE_TIME = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_TIME, false) || dbgOptions.getBooleanOption("org.eclipse.core.runtime/timing/startup", false); //$NON-NLS-1$ DEBUG_LOADER = dbgOptions.getBooleanOption(OPTION_DEBUG_LOADER, false); + DEBUG_STORAGE = dbgOptions.getBooleanOption(OPTION_DEBUG_STORAGE, false); DEBUG_EVENTS = dbgOptions.getBooleanOption(OPTION_DEBUG_EVENTS, false); DEBUG_SERVICES = dbgOptions.getBooleanOption(OPTION_DEBUG_SERVICES, false); DEBUG_HOOKS = dbgOptions.getBooleanOption(OPTION_DEBUG_HOOKS, false); 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 5bed93d0b..e04e6d29f 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 @@ -267,19 +267,19 @@ public final class BundleInfo { public void storeContent(File destination, InputStream in, boolean nativeCode) throws IOException { /* the entry has not been cached */ - if (getStorage().getConfiguration().getDebug().DEBUG_GENERAL) + if (getStorage().getConfiguration().getDebug().DEBUG_STORAGE) 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) + if (getStorage().getConfiguration().getDebug().DEBUG_STORAGE) 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)) { + if (destination.exists() || !StorageUtil.move(tempDest, destination, getStorage().getConfiguration().getDebug().DEBUG_STORAGE)) { // maybe because some other thread already beat us there. if (destination.exists()) { // just delete our copy that could not get renamed @@ -436,7 +436,7 @@ public final class BundleInfo { public File getDataFile(String path) { File dataRoot = getStorage().getFile(getBundleId() + "/" + Storage.BUNDLE_DATA_DIR, false); //$NON-NLS-1$ if (!Storage.secureAction.isDirectory(dataRoot) && (storage.isReadOnly() || !(Storage.secureAction.mkdirs(dataRoot) || Storage.secureAction.isDirectory(dataRoot)))) { - if (getStorage().getConfiguration().getDebug().DEBUG_GENERAL) + if (getStorage().getConfiguration().getDebug().DEBUG_STORAGE) Debug.println("Unable to create bundle data directory: " + dataRoot.getAbsolutePath()); //$NON-NLS-1$ return null; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java index 521466724..65d7b4394 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java @@ -359,7 +359,7 @@ public class Storage { } private void cleanOSGiStorage(Location location, File root) { - if (location.isReadOnly() || !StorageUtil.rm(root, getConfiguration().getDebug().DEBUG_GENERAL)) { + if (location.isReadOnly() || !StorageUtil.rm(root, getConfiguration().getDebug().DEBUG_STORAGE)) { equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "The -clean (osgi.clean) option was not successful. Unable to clean the storage area: " + root.getAbsolutePath(), null); //$NON-NLS-1$ } } @@ -765,7 +765,7 @@ public class Storage { throw new BundleException("Could not create generation directory: " + generationRoot.getAbsolutePath()); //$NON-NLS-1$ } contentFile = new File(generationRoot, BUNDLE_FILE_NAME); - if (!staged.renameTo(contentFile)) { + if (!StorageUtil.move(staged, contentFile, getConfiguration().getDebug().DEBUG_STORAGE)) { throw new BundleException("Error while renaming bundle file to final location: " + contentFile); //$NON-NLS-1$ } } else { @@ -942,7 +942,7 @@ public class Storage { } private void compact(File directory) { - if (getConfiguration().getDebug().DEBUG_GENERAL) + if (getConfiguration().getDebug().DEBUG_STORAGE) Debug.println("compact(" + directory.getPath() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ String list[] = directory.list(); if (list == null) @@ -960,13 +960,13 @@ public class Storage { // and the directory is marked for delete if (delete.exists()) { // if rm fails to delete the directory and .delete was removed - if (!StorageUtil.rm(target, getConfiguration().getDebug().DEBUG_GENERAL) && !delete.exists()) { + if (!StorageUtil.rm(target, getConfiguration().getDebug().DEBUG_STORAGE) && !delete.exists()) { try { // recreate .delete FileOutputStream out = new FileOutputStream(delete); out.close(); } catch (IOException e) { - if (getConfiguration().getDebug().DEBUG_GENERAL) + if (getConfiguration().getDebug().DEBUG_STORAGE) Debug.println("Unable to write " + delete.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -996,7 +996,7 @@ public class Storage { } void delete0(File delete) throws IOException { - if (!StorageUtil.rm(delete, getConfiguration().getDebug().DEBUG_GENERAL)) { + if (!StorageUtil.rm(delete, getConfiguration().getDebug().DEBUG_STORAGE)) { /* create .delete */ FileOutputStream out = new FileOutputStream(new File(delete, DELETE_FLAG)); out.close(); @@ -1759,7 +1759,7 @@ public class Storage { try { sManager.open(!isReadOnly()); } catch (IOException ex) { - if (getConfiguration().getDebug().DEBUG_GENERAL) { + if (getConfiguration().getDebug().DEBUG_STORAGE) { Debug.println("Error reading framework.info: " + ex.getMessage()); //$NON-NLS-1$ Debug.printStackTrace(ex); } @@ -1779,7 +1779,7 @@ public class Storage { try { storageStream = storageManager.getInputStream(FRAMEWORK_INFO); } catch (IOException ex) { - if (getConfiguration().getDebug().DEBUG_GENERAL) { + if (getConfiguration().getDebug().DEBUG_STORAGE) { Debug.println("Error reading framework.info: " + ex.getMessage()); //$NON-NLS-1$ Debug.printStackTrace(ex); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java index 1dadd7e2e..1cc6f9705 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java @@ -16,6 +16,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; import java.util.Hashtable; +import java.util.concurrent.TimeUnit; import org.eclipse.osgi.internal.debug.Debug; import org.osgi.framework.*; @@ -117,7 +118,7 @@ public class StorageUtil { if (DEBUG) { if (!success) { - Debug.println(" rm failed!!"); //$NON-NLS-1$ + Debug.println(" rm failed!"); //$NON-NLS-1$ } } @@ -196,7 +197,7 @@ public class StorageUtil { if (readcount <= 0) /* if we didn't read anything */ break; /* leave the loop */ } - } else /* does not know its own length! */{ + } else /* does not know its own length! */ { length = BUF_SIZE; classbytes = new byte[length]; readloop: while (true) { @@ -225,4 +226,59 @@ public class StorageUtil { } return classbytes; } + + /** + * To remain Java 6 compatible work around the unreliable renameTo() via + * retries: http://bugs.java.com/view_bug.do?bug_id=6213298 + * + * @param from + * @param to + */ + public static boolean move(File from, File to, boolean DEBUG) { + // Try several attempts with incremental sleep + final int maxTries = 10; + final int sleepStep = 200; + for (int tryCount = 0, sleep = sleepStep;; sleep += sleepStep, tryCount++) { + if (from.renameTo(to)) { + return true; + } + + if (DEBUG) { + Debug.println("move: failed to rename " + from + " to " + to + " (" + (maxTries - tryCount) + " attempts remaining)"); + } + + if (tryCount >= maxTries) { + break; + } + + try { + TimeUnit.MILLISECONDS.sleep(sleep); + } catch (InterruptedException e) { + // Ignore + } + } + + // Try a copy + try { + if (from.isDirectory()) { + copyDir(from, to); + } else { + readFile(new FileInputStream(from), to); + } + + if (!rm(from, DEBUG)) { + Debug.println("move: failed to delete " + from + " after copy to " + to + ". Scheduling for delete on JVM exit."); + from.deleteOnExit(); + } + return true; + } catch (IOException e) { + if (DEBUG) { + Debug.println("move: failed to copy " + from + " to " + to); + Debug.printStackTrace(e); + } + + // Give up + return false; + } + } } |