0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

fix(cli/disk_cache): Support UNC paths in the typescript DiskCache (#6495)

This commit is contained in:
Andrey Filatkin 2020-06-26 20:25:13 +03:00 committed by GitHub
parent 9107b1ea3f
commit b049504bee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::path::Prefix;
use std::str;
use url::Url;
use url::{Host, Url};
#[derive(Clone)]
pub struct DiskCache {
@ -80,6 +80,14 @@ impl DiskCache {
let disk = (disk_byte as char).to_string();
out.push(disk);
}
Prefix::UNC(server, share)
| Prefix::VerbatimUNC(server, share) => {
out.push("UNC");
let host = Host::parse(server.to_str().unwrap()).unwrap();
let host = host.to_string().replace(":", "_");
out.push(host);
out.push(share);
}
_ => unreachable!(),
}
}
@ -201,6 +209,21 @@ mod tests {
if cfg!(target_os = "windows") {
test_cases.push(("file:///D:/a/1/s/format.ts", "file/D/a/1/s/format.ts"));
// IPv4 localhost
test_cases.push((
"file://127.0.0.1/d$/a/1/s/format.ts",
"file/UNC/127.0.0.1/d$/a/1/s/format.ts",
));
// IPv6 localhost
test_cases.push((
"file://[0:0:0:0:0:0:0:1]/d$/a/1/s/format.ts",
"file/UNC/[__1]/d$/a/1/s/format.ts",
));
// shared folder
test_cases.push((
"file://comp/t-share/a/1/s/format.ts",
"file/UNC/comp/t-share/a/1/s/format.ts",
));
} else {
test_cases.push((
"file:///std/http/file_server.ts",