Skip to content

Commit b06fb47

Browse files
committed
fix workspace considered not writable on a smb home share #2225
#2225 java.io.File.canWrite() and java.nio.file.Files.isWritable(Path) can not be trusted on windows. they may return wrong values. see for example JDK-8282720, JDK-8148211, JDK-8154915 => allow the user to press "Launch" even if jdk states the directory is not writable
1 parent a801237 commit b06fb47

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,33 +474,38 @@ protected String getUnexpectedPathHint() {
474474
}
475475
String normalisedPath = path.normalize().toString();
476476
String normalisedPathWithSeperator = normalisedPath + File.separator;
477-
if (!isWritable(path)) {
478-
return NLS.bind(IDEWorkbenchMessages.ChooseWorkspaceDialog_NotWriteablePathWarning, normalisedPath);
479-
}
480477
if (normalisedPathWithSeperator.contains(TILDE)) {
481478
return NLS.bind(IDEWorkbenchMessages.ChooseWorkspaceDialog_TildeNonExpandedWarning, normalisedPath);
482479
}
483480
if (!workspaceLocation.equalsIgnoreCase(normalisedPath)
484481
&& !workspaceLocation.equalsIgnoreCase(normalisedPathWithSeperator)) {
485482
return NLS.bind(IDEWorkbenchMessages.ChooseWorkspaceDialog_ResolvedAbsolutePath, normalisedPath);
486483
}
484+
if (!maybeWritable(path)) {
485+
return NLS.bind(IDEWorkbenchMessages.ChooseWorkspaceDialog_NotWriteablePathWarning, normalisedPath);
486+
}
487487
}
488488
return ""; //$NON-NLS-1$
489489
}
490490

491-
/**
492-
* @param path
493-
* @return
494-
*/
495-
private boolean isWritable(Path path) {
496-
if (Files.exists(path)) {
497-
return Files.isWritable(path);
498-
}
499-
Path parent = path.getParent();
500-
if (parent != null) {
501-
return isWritable(parent);
491+
/** the returned value may be wrong **/
492+
private boolean maybeWritable(Path path) {
493+
try {
494+
if (Files.exists(path)) {
495+
// both java.io.File.canWrite() and
496+
// java.nio.file.Files.isWritable(Path)
497+
// can not be trusted on windows. they may return wrong values.
498+
// for example JDK-8282720, JDK-8148211, JDK-8154915
499+
return Files.isWritable(path);
500+
}
501+
Path parent = path.getParent();
502+
if (parent == null) {
503+
return false;
504+
}
505+
return maybeWritable(parent);
506+
} catch (SecurityException se) {
507+
return false;
502508
}
503-
return true;
504509
}
505510

506511
protected Composite createBrowseComposite(Composite parent) {
@@ -545,7 +550,8 @@ protected Combo createPathCombo(Composite panel) {
545550
*/
546551
private boolean isValidPath(String path) {
547552
try {
548-
return isWritable(new File(path).toPath());
553+
Path.of(path);
554+
return true;
549555
} catch (InvalidPathException e) {
550556
return false;
551557
}

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ ChooseWorkspaceDialog_recentWorkspaces=&Recent Workspaces
10491049
ChooseWorkspaceDialog_ResolvedAbsolutePath=Full path: {0}
10501050
ChooseWorkspaceDialog_TildeNonExpandedWarning=\u26A0\uFE0F '~' is not expanded, full path: {0}
10511051
ChooseWorkspaceDialog_InvalidPathWarning=\u26A0\uFE0F The path is invalid on this system: {0}
1052-
ChooseWorkspaceDialog_NotWriteablePathWarning=\u26A0\uFE0F The path is not writable by the current user: {0}
1052+
ChooseWorkspaceDialog_NotWriteablePathWarning=\u26A0\uFE0F The path may not be writable by the current user: {0}
10531053
ChooseWorkspaceDialog_useDefaultMessage=&Use this as the default and do not ask again
10541054

10551055
ChooseWorkspaceWithSettingsDialog_SettingsGroupName=&Copy Settings

0 commit comments

Comments
 (0)