From 78e52ea9845b684c425633367dc37c45347616de Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Thu, 1 Jun 2023 03:38:35 +0800 Subject: [PATCH] Let's fix the UNC logic in mount_directory_entries() instead --- lib/virtual-fs/src/mem_fs/filesystem.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/virtual-fs/src/mem_fs/filesystem.rs b/lib/virtual-fs/src/mem_fs/filesystem.rs index 0bde1ea2de8..d5a13920030 100644 --- a/lib/virtual-fs/src/mem_fs/filesystem.rs +++ b/lib/virtual-fs/src/mem_fs/filesystem.rs @@ -47,10 +47,22 @@ impl FileSystem { &self, target_path: &Path, other: &Arc, - source_path: &Path, + mut source_path: &Path, ) -> Result<()> { let fs_lock = self.inner.read().map_err(|_| FsError::Lock)?; + if cfg!(windows) { + // We need to take some care here because + // canonicalize_without_inode() doesn't accept Windows paths that + // start with a prefix (drive letters, UNC paths, etc.). If we + // somehow get one of those paths, we'll automatically trim it away. + let mut components = source_path.components(); + + if let Some(Component::Prefix(_)) = components.next() { + source_path = components.as_path(); + } + } + let (_target_path, root_inode) = match fs_lock.canonicalize(target_path) { Ok((p, InodeResolution::Found(inode))) => (p, inode), Ok((_p, InodeResolution::Redirect(..))) => { @@ -882,7 +894,7 @@ impl FileSystemInner { let mut components = path.components(); match components.next() { - Some(Component::RootDir) | Some(Component::Prefix(..)) => {} + Some(Component::RootDir) => {} _ => return Err(FsError::InvalidInput), }