(
source: &str,
target: &str,
read_only: bool,
selinux_label: Option<SelinuxLabel>,
)
| 1792 | } |
| 1793 | |
| 1794 | fn docker_bind_string( |
| 1795 | source: &str, |
| 1796 | target: &str, |
| 1797 | read_only: bool, |
| 1798 | selinux_label: Option<SelinuxLabel>, |
| 1799 | ) -> Result<String, Status> { |
| 1800 | driver_mounts::validate_absolute_mount_source(source, "bind source") |
| 1801 | .map_err(Status::failed_precondition)?; |
| 1802 | // Legacy `-v` binds silently create missing source directories as empty, |
| 1803 | // root-owned paths. The structured `--mount` API that was used before this |
| 1804 | // change rejected missing sources at container-create time. Preserve that |
| 1805 | // fail-fast behaviour with an explicit existence check. |
| 1806 | if !Path::new(source).exists() { |
| 1807 | return Err(Status::failed_precondition(format!( |
| 1808 | "bind source path does not exist: {source}" |
| 1809 | ))); |
| 1810 | } |
| 1811 | driver_mounts::validate_container_mount_target(target).map_err(Status::failed_precondition)?; |
| 1812 | let normalized_target = driver_mounts::normalize_mount_target(target); |
| 1813 | |
| 1814 | let mut opts = Vec::new(); |
| 1815 | if read_only { |
| 1816 | opts.push("ro"); |
| 1817 | } |
| 1818 | match selinux_label { |
| 1819 | Some(SelinuxLabel::Shared) => opts.push("z"), |
| 1820 | Some(SelinuxLabel::Private) => opts.push("Z"), |
| 1821 | None => {} |
| 1822 | } |
| 1823 | |
| 1824 | if opts.is_empty() { |
| 1825 | Ok(format!("{source}:{normalized_target}")) |
| 1826 | } else { |
| 1827 | Ok(format!("{source}:{normalized_target}:{}", opts.join(","))) |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | /// Collect user-supplied non-bind mounts as structured `Mount` objects. |
| 1832 | fn docker_driver_mounts(config: &DockerSandboxDriverConfig) -> Result<Vec<Mount>, Status> { |
no test coverage detected