-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix lock path computation on Windows and minor simplifications #2426
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,9 +24,11 @@ | |||||||||||||
import java.io.FileInputStream; | ||||||||||||||
import java.io.FileOutputStream; | ||||||||||||||
import java.io.IOException; | ||||||||||||||
import java.io.InputStream; | ||||||||||||||
import java.io.OutputStream; | ||||||||||||||
import java.net.InetAddress; | ||||||||||||||
import java.net.MalformedURLException; | ||||||||||||||
import java.net.URISyntaxException; | ||||||||||||||
import java.net.URL; | ||||||||||||||
import java.nio.file.Files; | ||||||||||||||
import java.nio.file.Path; | ||||||||||||||
|
@@ -40,6 +42,7 @@ | |||||||||||||
import org.eclipse.core.runtime.OperationCanceledException; | ||||||||||||||
import org.eclipse.core.runtime.Platform; | ||||||||||||||
import org.eclipse.core.runtime.Status; | ||||||||||||||
import org.eclipse.core.runtime.URIUtil; | ||||||||||||||
import org.eclipse.core.runtime.jobs.Job; | ||||||||||||||
import org.eclipse.core.runtime.preferences.ConfigurationScope; | ||||||||||||||
import org.eclipse.equinox.app.IApplication; | ||||||||||||||
|
@@ -86,7 +89,7 @@ public class IDEApplication implements IApplication, IExecutableExtension { | |||||||||||||
|
||||||||||||||
private static final String VERSION_FILENAME = "version.ini"; //$NON-NLS-1$ | ||||||||||||||
|
||||||||||||||
private static final String LOCK_INFO_FILENAME = ".lock_info"; //$NON-NLS-1$ | ||||||||||||||
private static final Path LOCK_INFO_FILE = Path.of(METADATA_FOLDER, ".lock_info"); //$NON-NLS-1$ | ||||||||||||||
|
||||||||||||||
private static final String DISPLAY_VAR = "DISPLAY"; //$NON-NLS-1$ | ||||||||||||||
|
||||||||||||||
|
@@ -404,14 +407,14 @@ protected Control createCustomArea(Composite parent) { | |||||||||||||
*/ | ||||||||||||||
protected String getWorkspaceLockInfo(URL workspaceUrl) { | ||||||||||||||
try { | ||||||||||||||
File lockFile = getLockInfoFile(workspaceUrl); | ||||||||||||||
if (!lockFile.exists()) { | ||||||||||||||
Path lockFile = getLockInfoFile(workspaceUrl); | ||||||||||||||
if (!Files.exists(lockFile)) { | ||||||||||||||
return null; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
StringBuilder sb = new StringBuilder(); | ||||||||||||||
Properties props = new Properties(); | ||||||||||||||
try (FileInputStream is = new FileInputStream(lockFile)) { | ||||||||||||||
try (InputStream is = Files.newInputStream(lockFile)) { | ||||||||||||||
props.load(is); | ||||||||||||||
String prop = props.getProperty(USER); | ||||||||||||||
if (prop != null) { | ||||||||||||||
|
@@ -441,8 +444,6 @@ protected String getWorkspaceLockInfo(URL workspaceUrl) { | |||||||||||||
/** | ||||||||||||||
* Write lock owner details onto workspace lock file. Data includes user, host, | ||||||||||||||
* display and current java process id. | ||||||||||||||
* | ||||||||||||||
* @param instanceLoc | ||||||||||||||
*/ | ||||||||||||||
protected void writeWsLockInfo(URL workspaceUrl) { | ||||||||||||||
Properties props = new Properties(); | ||||||||||||||
|
@@ -468,7 +469,7 @@ protected void writeWsLockInfo(URL workspaceUrl) { | |||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
try (OutputStream output = new FileOutputStream(createLockInfoFile(workspaceUrl))) { | ||||||||||||||
try (OutputStream output = Files.newOutputStream(createLockInfoFile(workspaceUrl))) { | ||||||||||||||
props.store(output, null); | ||||||||||||||
} catch (Exception e) { | ||||||||||||||
IDEWorkbenchPlugin.log("Could not write lock info file", e); //$NON-NLS-1$ | ||||||||||||||
|
@@ -523,9 +524,12 @@ private String getHostName() { | |||||||||||||
* @param workspaceUrl | ||||||||||||||
* @return .lock_info file. | ||||||||||||||
*/ | ||||||||||||||
private File getLockInfoFile(URL workspaceUrl) { | ||||||||||||||
Path lockInfoPath = Path.of(workspaceUrl.getPath(), METADATA_FOLDER, LOCK_INFO_FILENAME); | ||||||||||||||
return lockInfoPath.toFile(); | ||||||||||||||
private static Path getLockInfoFile(URL workspaceUrl) { | ||||||||||||||
try { | ||||||||||||||
return Path.of(URIUtil.toURI(workspaceUrl)).resolve(LOCK_INFO_FILE); | ||||||||||||||
} catch (URISyntaxException e) { | ||||||||||||||
throw new IllegalArgumentException(e); | ||||||||||||||
} | ||||||||||||||
Comment on lines
+528
to
+532
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw. this reminded me of a work that I started a while ago and that I have now made a draft in Equinox: When that's available this could be further simplified to (but at the moment this is not possible yet!):
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -534,17 +538,12 @@ private File getLockInfoFile(URL workspaceUrl) { | |||||||||||||
* @param workspaceUrl | ||||||||||||||
* @return .lock_info file. | ||||||||||||||
*/ | ||||||||||||||
private File createLockInfoFile(URL workspaceUrl) throws Exception { | ||||||||||||||
File lockInfoFile = getLockInfoFile(workspaceUrl); | ||||||||||||||
|
||||||||||||||
if (lockInfoFile.exists()) | ||||||||||||||
return lockInfoFile; | ||||||||||||||
|
||||||||||||||
Path createdPath = Files.createFile(lockInfoFile.toPath()); | ||||||||||||||
if (createdPath != null) { | ||||||||||||||
return createdPath.toFile(); | ||||||||||||||
private static Path createLockInfoFile(URL workspaceUrl) throws Exception { | ||||||||||||||
Path lockInfoFile = getLockInfoFile(workspaceUrl); | ||||||||||||||
if (!Files.exists(lockInfoFile)) { | ||||||||||||||
Files.createFile(lockInfoFile); | ||||||||||||||
} | ||||||||||||||
return null; | ||||||||||||||
return lockInfoFile; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
@SuppressWarnings("rawtypes") | ||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nio was introduced by https://github.com/eclipse-platform/eclipse.platform.ui/pull/2347/files#diff-6b2613840cdec17a5b7ab1f515650cc101c4637884833261d1353c6e0b9d7535R32.
I think completely getting rid of it safe.