From e9b280afe00815cced8c50ca6e97d7987e5782ec Mon Sep 17 00:00:00 2001 From: KyleBarton Date: Fri, 3 Apr 2026 14:55:12 -0700 Subject: [PATCH] Account for windows absolute paths in bind mounts (#53093) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Addresses an auxiliary windows bug found in #52924 - bind mounts are not working in Windows because MountDefinition is not accounting for absolute Windows paths. Release Notes: - Fixed windows bind mount issue with dev containers --- crates/dev_container/src/devcontainer_json.rs | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/crates/dev_container/src/devcontainer_json.rs b/crates/dev_container/src/devcontainer_json.rs index 4429c63a37a87d1b54455b8169359ddf40511e24..f034026a8de4c4a6c3186c97870e25f3510ebc85 100644 --- a/crates/dev_container/src/devcontainer_json.rs +++ b/crates/dev_container/src/devcontainer_json.rs @@ -72,7 +72,11 @@ impl Display for MountDefinition { f, "type={},source={},target={},consistency=cached", self.mount_type.clone().unwrap_or_else(|| { - if self.source.starts_with('/') { + if self.source.starts_with('/') + || self.source.starts_with("\\\\") + || self.source.get(1..3) == Some(":\\") + || self.source.get(1..3) == Some(":/") + { "bind".to_string() } else { "volume".to_string() @@ -1355,4 +1359,52 @@ mod test { assert_eq!(devcontainer.build_type(), DevContainerBuildType::Dockerfile); } + + #[test] + fn mount_definition_should_use_bind_type_for_unix_absolute_paths() { + let mount = MountDefinition { + source: "/home/user/project".to_string(), + target: "/workspaces/project".to_string(), + mount_type: None, + }; + + let rendered = mount.to_string(); + + assert!( + rendered.starts_with("type=bind,"), + "Expected mount type 'bind' for Unix absolute path, but got: {rendered}" + ); + } + + #[test] + fn mount_definition_should_use_bind_type_for_windows_unc_paths() { + let mount = MountDefinition { + source: "\\\\server\\share\\project".to_string(), + target: "/workspaces/project".to_string(), + mount_type: None, + }; + + let rendered = mount.to_string(); + + assert!( + rendered.starts_with("type=bind,"), + "Expected mount type 'bind' for Windows UNC path, but got: {rendered}" + ); + } + + #[test] + fn mount_definition_should_use_bind_type_for_windows_absolute_paths() { + let mount = MountDefinition { + source: "C:\\Users\\mrg\\cli".to_string(), + target: "/workspaces/cli".to_string(), + mount_type: None, + }; + + let rendered = mount.to_string(); + + assert!( + rendered.starts_with("type=bind,"), + "Expected mount type 'bind' for Windows absolute path, but got: {rendered}" + ); + } }