Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2500)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/DirectoryVerification.java

Issue 245213003: fix for dartbug.com/10800 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/DirectoryVerification.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/DirectoryVerification.java (revision 35204)
+++ editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/util/DirectoryVerification.java (working copy)
@@ -25,7 +25,8 @@
import java.io.File;
import java.io.IOException;
-import java.net.URISyntaxException;
+import java.net.URI;
+import java.net.URL;
/**
* A utility class to handle checking to see if a directory is legal to open in the editor.
@@ -36,8 +37,9 @@
// disallow parent directories of the workspace
try {
Location workspaceLocation = Platform.getInstanceLocation();
- File workspaceDirectory = new File(workspaceLocation.getURL().toURI());
+ File workspaceDirectory = toFile(workspaceLocation.getURL());
+
String dirPath = directory.getCanonicalPath();
String workspacePath = workspaceDirectory.getCanonicalPath();
@@ -47,8 +49,6 @@
}
} catch (IOException e) {
- } catch (URISyntaxException e) {
-
}
// discourage user home
@@ -79,6 +79,57 @@
return status.isOK();
}
+ /**
+ * Ensures the given path string starts with exactly four leading slashes.
+ */
+ private static String ensureUNCPath(String path) {
+ int len = path.length();
+ StringBuffer result = new StringBuffer(len);
+ for (int i = 0; i < 4; i++) {
+ // if we have hit the first non-slash character, add another leading slash
+ if (i >= len || result.length() > 0 || path.charAt(i) != '/') {
+ result.append('/');
+ }
+ }
+ result.append(path);
+ return result.toString();
+ }
+
+ /**
+ * Returns the URL as a local file, or <code>null</code> if the given URL does not represent a
+ * local file.
+ *
+ * @param url The url to return the file for
+ * @return The local file corresponding to the given url, or <code>null</code>
+ */
+ private static File toFile(URL url) {
+
+ if (!"file".equalsIgnoreCase(url.getProtocol())) {
+ return null;
+ //assume all illegal characters have been properly encoded, so use URI class to unencode
+ }
+
+ String externalForm = url.toExternalForm();
+ String pathString = externalForm.substring(5);
+
+ try {
+ if (pathString.indexOf('/') == 0) {
+ if (pathString.indexOf("//") == 0) {
+ externalForm = "file:" + ensureUNCPath(pathString); //$NON-NLS-1$
+ }
+ return new File(new URI(externalForm));
+ }
+ if (pathString.indexOf(':') == 1) {
+ return new File(new URI("file:/" + pathString)); //$NON-NLS-1$
+ }
+
+ return new File(new URI(pathString).getSchemeSpecificPart());
+ } catch (Exception e) {
+ //URL contains unencoded characters
+ return new File(pathString);
+ }
+ }
+
private DirectoryVerification() {
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698