Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 55087 Details for
Bug 59780
[IDE] Better handling of lock file issue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
patch against the latest from HEAD, but still a bad solution and I do not endorse it
bug59780.txt (text/plain), 9.50 KB, created by
Wassim Melhem
on 2006-12-05 19:27:33 EST
(
hide
)
Description:
patch against the latest from HEAD, but still a bad solution and I do not endorse it
Filename:
MIME Type:
Creator:
Wassim Melhem
Created:
2006-12-05 19:27:33 EST
Size:
9.50 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.ide >Index: src/org/eclipse/ui/internal/ide/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v >retrieving revision 1.136 >diff -u -r1.136 messages.properties >--- src/org/eclipse/ui/internal/ide/messages.properties 23 Nov 2006 17:50:02 -0000 1.136 >+++ src/org/eclipse/ui/internal/ide/messages.properties 6 Dec 2006 00:00:52 -0000 >@@ -768,6 +768,12 @@ > {0}\n\n\ > Updating the workspace may make it incompatible with other versions of the product.\n\ > Press OK to update the workspace and open it. Press Cancel to select a different workspace. >+IDEApplication_confirmOpenWorkspaceWOLockTitle=Open Workspace >+IDEApplication_confirmOpenWorkspaceWOLockMessage=\ >+ The workspace is on a file system which does not support file locking. \ >+ Do you want to open the workspace without locking? \ >+ Please note that opening the same workspace a second time might cause data corruption and data loss.\n\ >+ Open workspace? > > CleanDialog_buildCleanAuto=Clean will discard all build problems and built states. The projects will be rebuilt from scratch. > CleanDialog_buildCleanManual=Clean will discard all build problems and built states. The next time a build occurs the projects will be rebuilt from scratch. >Index: src/org/eclipse/ui/internal/ide/IDEApplication.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEApplication.java,v >retrieving revision 1.43 >diff -u -r1.43 IDEApplication.java >--- src/org/eclipse/ui/internal/ide/IDEApplication.java 30 Jul 2006 07:48:55 -0000 1.43 >+++ src/org/eclipse/ui/internal/ide/IDEApplication.java 6 Dec 2006 00:00:50 -0000 >@@ -17,6 +17,7 @@ > import java.io.OutputStream; > import java.net.MalformedURLException; > import java.net.URL; >+import java.nio.channels.FileLock; > import java.util.Properties; > > import org.eclipse.core.runtime.CoreException; >@@ -41,7 +42,7 @@ > * @since 3.0 > */ > public class IDEApplication implements IPlatformRunnable, IExecutableExtension { >- >+ private static final String PROP_OSGI_LOCKING = "osgi.locking"; //$NON-NLS-1$ > /** > * The name of the folder containing metadata information for the workspace. > */ >@@ -128,6 +129,9 @@ > public void setInitializationData(IConfigurationElement config, > String propertyName, Object data) throws CoreException { > // There is nothing to do for IDEApplication >+ // This code will never be executed but the eclipse warning will go away ;) >+ if (false) >+ throw new CoreException(null); > } > > /** >@@ -308,41 +312,119 @@ > * otherwise. > */ > private boolean checkValidWorkspace(Shell shell, URL url) { >- // a null url is not a valid workspace >- if (url == null) { >- return false; >+ boolean toBeReturned = false; >+ // a null url is not a valid workspace >+ if (url != null) { >+ String version = readWorkspaceVersion(url); >+ >+ // if the version could not be read, then there is not any existing >+ // workspace data to trample, e.g., perhaps its a new directory that >+ // is just starting to be used as a workspace >+ if (version == null) { >+ toBeReturned = true; >+ } else { >+ final int ide_version = Integer.parseInt(WORKSPACE_VERSION_VALUE); >+ int workspace_version = Integer.parseInt(version); >+ // equality test is required since any version difference (newer >+ //or older) may result in data being trampled >+ if (workspace_version == ide_version) { >+ toBeReturned = true; >+ } else { >+ // At this point workspace has been detected to be from a version >+ // other than the current ide version -- find out if the user wants >+ // to use it anyhow. >+ String title = IDEWorkbenchMessages.IDEApplication_versionTitle; >+ String message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage, url.getFile()); >+ >+ MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL >+ | SWT.ICON_WARNING | SWT.APPLICATION_MODAL); >+ mbox.setText(title); >+ mbox.setMessage(message); >+ toBeReturned = mbox.open() == SWT.OK; >+ } >+ } >+ } >+ toBeReturned &= checkLockingAllowed(shell,url); >+ return toBeReturned; >+ } >+ /** >+ * Check if the given workspace url points to a filesystem which supports locking. >+ * If locking is not possible, a message is displayed asking whether >+ * locking should be disabled. >+ * If locking is disabled, true is returned otherwise false. >+ * @param shell >+ * @param url the workspace location >+ * @return true if workspace locking is possible (or disabled), false otherwise >+ */ >+ private boolean checkLockingAllowed(Shell shell, URL url) { >+ // try locking >+ File versionFile = new File(getVersionFile(url, true).getParentFile(),".lock"); //$NON-NLS-1$ >+ if (versionFile == null) { >+ // don't know what's wrong here >+ return true; > } >- >- String version = readWorkspaceVersion(url); >- >- // if the version could not be read, then there is not any existing >- // workspace data to trample, e.g., perhaps its a new directory that >- // is just starting to be used as a workspace >- if (version == null) { >+ boolean lockingAllowed = isLockingAllowed(versionFile); >+ if (lockingAllowed) { > return true; > } >- >- final int ide_version = Integer.parseInt(WORKSPACE_VERSION_VALUE); >- int workspace_version = Integer.parseInt(version); >- >- // equality test is required since any version difference (newer >- // or older) may result in data being trampled >- if (workspace_version == ide_version) { >+ boolean disableLocking = MessageDialog.openQuestion(shell, >+ IDEWorkbenchMessages.IDEApplication_confirmOpenWorkspaceWOLockTitle, >+ IDEWorkbenchMessages.IDEApplication_confirmOpenWorkspaceWOLockMessage >+ ); >+ if (disableLocking) { >+ System.setProperty(PROP_OSGI_LOCKING, "none"); //$NON-NLS-1$ > return true; > } >+ // locking not allowed, let user choose another workspace >+ return false; >+ } > >- // At this point workspace has been detected to be from a version >- // other than the current ide version -- find out if the user wants >- // to use it anyhow. >- String title = IDEWorkbenchMessages.IDEApplication_versionTitle; >- String message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage, url.getFile()); >- >- MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL >- | SWT.ICON_WARNING | SWT.APPLICATION_MODAL); >- mbox.setText(title); >- mbox.setMessage(message); >- return mbox.open() == SWT.OK; >- } >+ /** >+ * This is basically a copy of the Platforms checks >+ * @see BasicLocation >+ * Can't use that one here since it's not yet loaded when >+ * this method is invoked (it's also internal). >+ * >+ * @param lockFile The file that is locked (or tried to) >+ * @return boolean indicator >+ */ >+ private static boolean isLockingAllowed(File lockFile) { >+ String lockMode = System.getProperties().getProperty(PROP_OSGI_LOCKING); >+ if (lockMode == null) >+ lockMode = "java.nio"; //$NON-NLS-1$ >+ if ("none".equals(lockMode)) //$NON-NLS-1$ >+ return true; >+ else if ("java.io".equals(lockMode)) {//$NON-NLS-1${ >+ // io locking means removing the file, can't check that here! >+ return true; >+ } else if ("java.nio".equals(lockMode)) {//$NON-NLS-1$ >+ FileOutputStream stream = null; >+ FileLock lock = null; >+ try { >+ stream = new FileOutputStream(lockFile, true); >+ lock = stream.getChannel().tryLock(); >+ } catch (IOException e) { >+ // ignored >+ } finally { >+ if (lock != null) { >+ try { >+ lock.release(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ if (stream != null) { >+ try { >+ stream.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ return lock != null; >+ } >+ return false; >+ } > > /** > * Look at the argument URL for the workspace's version information. Return >Index: src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java,v >retrieving revision 1.44 >diff -u -r1.44 IDEWorkbenchMessages.java >--- src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 23 Nov 2006 17:50:02 -0000 1.44 >+++ src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 6 Dec 2006 00:00:51 -0000 >@@ -15,6 +15,7 @@ > private static final String BUNDLE_NAME = "org.eclipse.ui.internal.ide.messages";//$NON-NLS-1$ > // package: org.eclipse.ui.ide > >+ > public static String IDEWorkbenchAdvisor_noPerspective; > > public static String IDE_noFileEditorFound; >@@ -737,6 +738,8 @@ > public static String IDEApplication_workspaceCannotBeSetMessage; > public static String IDEApplication_workspaceCannotLockTitle; > public static String IDEApplication_workspaceCannotLockMessage; >+ public static String IDEApplication_confirmOpenWorkspaceWOLockTitle; >+ public static String IDEApplication_confirmOpenWorkspaceWOLockMessage; > public static String IDEApplication_versionTitle; > public static String IDEApplication_versionMessage; > public static String GlobalBuildAction_BuildRunningTitle;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 59780
:
38396
| 55087 |
55130