Skip to content

Commit

Permalink
Fix paths from Windows client to non-Windows server
Browse files Browse the repository at this point in the history
Fixes #1659
Fixes #1642
  • Loading branch information
code-asher committed May 18, 2020
1 parent 8626bed commit 9cfc257
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
12 changes: 5 additions & 7 deletions ci/dev/vscode.patch
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,17 @@ index 1e16cde724..0000000000
-target "12.4.0"
-runtime "node"
diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts
index e4546b2cf6..9df12239fb 100644
index e4546b2cf6..ad2c544e89 100644
--- a/src/vs/base/common/network.ts
+++ b/src/vs/base/common/network.ts
@@ -94,16 +94,18 @@ class RemoteAuthoritiesImpl {
@@ -94,16 +94,17 @@ class RemoteAuthoritiesImpl {
if (host && host.indexOf(':') !== -1) {
host = `[${host}]`;
}
- const port = this._ports[authority];
+ // const port = this._ports[authority];
const connectionToken = this._connectionTokens[authority];
- let query = `path=${encodeURIComponent(uri.path)}`;
+ // NOTE@coder: Use fsPath for Windows support.
+ let query = `path=${encodeURIComponent(uri.fsPath)}`;
let query = `path=${encodeURIComponent(uri.path)}`;
if (typeof connectionToken === 'string') {
query += `&tkn=${encodeURIComponent(connectionToken)}`;
}
Expand Down Expand Up @@ -1054,7 +1052,7 @@ index 0000000000..0d2e93edae
+}
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
new file mode 100644
index 0000000000..8db1e17c38
index 0000000000..a93381631a
--- /dev/null
+++ b/src/vs/server/browser/worker.ts
@@ -0,0 +1,57 @@
Expand All @@ -1077,7 +1075,7 @@ index 0000000000..8db1e17c38
+ scheme: self.location.protocol.replace(':', ''),
+ authority: self.location.host,
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
+ query: `tar=${encodeURIComponent(module.extensionLocation.fsPath)}`,
+ query: `tar=${encodeURIComponent(module.extensionLocation.path)}`,
+ });
+ const response = await fetch(fetchUri.toString(true));
+ if (response.status !== 200) {
Expand Down
49 changes: 48 additions & 1 deletion src/node/app/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,53 @@ import { Args } from "../cli"
import { HttpProvider, HttpProviderOptions, HttpResponse, Route } from "../http"
import { settings } from "../settings"

/**
* Taken from vs/base/common/charCode.ts. Copied for now instead of importing so
* we don't have to set up a `vs` alias to be able to import with types (since
* the alternative is to directly import from `out`).
*/
const enum CharCode {
Slash = 47,
A = 65,
Z = 90,
a = 97,
z = 122,
Colon = 58,
}

/**
* Compute `fsPath` for the given uri.
* Taken from vs/base/common/uri.ts. It's not imported to avoid also importing
* everything that file imports.
*/
function uriToFsPath(uri: { authority?: string; path: string; scheme: string }, keepDriveLetterCasing = false): string {
const isWindows = process.platform === "win32"
let value: string
if (uri.authority && uri.path.length > 1 && uri.scheme === "file") {
// unc path: file://shares/c$/far/boo
value = `//${uri.authority}${uri.path}`
} else if (
uri.path.charCodeAt(0) === CharCode.Slash &&
((uri.path.charCodeAt(1) >= CharCode.A && uri.path.charCodeAt(1) <= CharCode.Z) ||
(uri.path.charCodeAt(1) >= CharCode.a && uri.path.charCodeAt(1) <= CharCode.z)) &&
uri.path.charCodeAt(2) === CharCode.Colon
) {
if (!keepDriveLetterCasing) {
// windows drive letter: file:///c:/far/boo
value = uri.path[1].toLowerCase() + uri.path.substr(2)
} else {
value = uri.path.substr(1)
}
} else {
// other path
value = uri.path
}
if (isWindows) {
value = value.replace(/\//g, "\\")
}
return value
}

export class VscodeHttpProvider extends HttpProvider {
private readonly serverRootPath: string
private readonly vsRootPath: string
Expand Down Expand Up @@ -151,7 +198,7 @@ export class VscodeHttpProvider extends HttpProvider {
case "/resource":
case "/vscode-remote-resource":
if (typeof route.query.path === "string") {
return this.getResource(route.query.path)
return this.getResource(uriToFsPath({ scheme: "file", path: route.query.path }))
}
break
case "/webview":
Expand Down

0 comments on commit 9cfc257

Please sign in to comment.