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:
@@ -95,8 +95,9 @@ impl ServeSession {
|
||||
/// currently loaded from the filesystem directly instead of through the
|
||||
/// in-memory filesystem layer.
|
||||
pub fn new<P: AsRef<Path>>(vfs: Vfs, start_path: P) -> Result<Self, ServeSessionError> {
|
||||
let start_path = start_path.as_ref();
|
||||
let start_time = Instant::now();
|
||||
let start_path = vfs.canonicalize(start_path.as_ref())?;
|
||||
let start_path = start_path.as_path();
|
||||
|
||||
log::trace!("Starting new ServeSession at path {}", start_path.display());
|
||||
|
||||
@@ -240,3 +241,39 @@ pub enum ServeSessionError {
|
||||
source: anyhow::Error,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use memofs::StdBackend;
|
||||
|
||||
#[test]
|
||||
fn tree_is_keyed_by_canonical_paths() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(
|
||||
dir.path().join("default.project.json"),
|
||||
r#"{ "name": "test", "tree": { "$className": "Folder" } }"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// `std::fs::canonicalize` yields a verbatim path on Windows.
|
||||
// On other platforms it simply resolves the path (e.g. symlinks),
|
||||
// which the session must also handle.
|
||||
let start_path = std::fs::canonicalize(dir.path()).unwrap();
|
||||
|
||||
let vfs = Vfs::new(StdBackend::new().unwrap());
|
||||
let session = ServeSession::new(vfs, &start_path).unwrap();
|
||||
|
||||
let project_file = start_path.join("default.project.json");
|
||||
let canonical = session.vfs().canonicalize(&project_file).unwrap();
|
||||
|
||||
assert!(
|
||||
!session.tree().get_ids_at_path(&canonical).is_empty(),
|
||||
"project file {} should be tracked in the tree under its canonical \
|
||||
path {}, matching what the watcher reports",
|
||||
project_file.display(),
|
||||
canonical.display(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user