mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-08-12 04:30:37 +00:00
Fix windows verbatim paths (#1295)
This commit is contained in:
@@ -16,6 +16,7 @@ homepage = "https://github.com/rojo-rbx/rojo/tree/master/memofs"
|
||||
|
||||
[dependencies]
|
||||
crossbeam-channel = "0.5.12"
|
||||
dunce = "1.0.5"
|
||||
fs-err = "2.11.0"
|
||||
notify = "4.0.17"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
|
||||
@@ -644,13 +644,49 @@ mod test {
|
||||
|
||||
let vfs = Vfs::new(StdBackend::new().unwrap());
|
||||
let canonicalized = vfs.canonicalize(&file_path).unwrap();
|
||||
assert_eq!(canonicalized, file_path.canonicalize().unwrap());
|
||||
assert_eq!(canonicalized, dunce::canonicalize(&file_path).unwrap());
|
||||
assert_eq!(
|
||||
vfs.read_to_string(&canonicalized).unwrap().to_string(),
|
||||
contents.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn canonicalize_std_backend_not_verbatim() {
|
||||
use std::path::{Component, Prefix};
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let file_path = dir.path().join("file.txt");
|
||||
fs_err::write(&file_path, "hello").unwrap();
|
||||
|
||||
let vfs = Vfs::new(StdBackend::new().unwrap());
|
||||
let canonicalized = vfs.canonicalize(&file_path).unwrap();
|
||||
|
||||
let is_verbatim = matches!(
|
||||
canonicalized.components().next(),
|
||||
Some(Component::Prefix(prefix)) if matches!(
|
||||
prefix.kind(),
|
||||
Prefix::Verbatim(_) | Prefix::VerbatimDisk(_) | Prefix::VerbatimUNC(_, _)
|
||||
)
|
||||
);
|
||||
assert!(
|
||||
!is_verbatim,
|
||||
"expected a non-verbatim path, got {:?}",
|
||||
canonicalized
|
||||
);
|
||||
|
||||
// Joining a relative parent path must preserve the `..` segment. On a
|
||||
// verbatim path Rust would drop it lexically, which is the root cause
|
||||
// of the bug.
|
||||
let joined = canonicalized.join("..").join("sibling");
|
||||
assert!(
|
||||
joined.components().any(|c| c == Component::ParentDir),
|
||||
"`..` should be preserved when joining onto {:?}",
|
||||
canonicalized
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canonicalize_std_backend_missing_errors() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -107,7 +107,7 @@ impl VfsBackend for StdBackend {
|
||||
}
|
||||
|
||||
fn canonicalize(&mut self, path: &Path) -> io::Result<PathBuf> {
|
||||
fs_err::canonicalize(path)
|
||||
dunce::canonicalize(path)
|
||||
}
|
||||
|
||||
fn event_receiver(&self) -> crossbeam_channel::Receiver<VfsEvent> {
|
||||
|
||||
Reference in New Issue
Block a user