fix: keep a path's bytes, so a filename that is not utf-8 survives

This commit is contained in:
2026-09-09 12:01:59 +00:00
parent b4b6d5918f
commit e146b0460a
8 changed files with 172 additions and 72 deletions

View File

@@ -1,3 +1,6 @@
use std::ffi::OsString;
use std::path::Path;
use super::{Argv, Cmd};
// docker exec, around a command that runs inside the container
@@ -47,24 +50,25 @@ impl Cmd for Exec {
}
}
// docker cp, in either direction
// docker cp, in either direction. the local side stays an OsString: it is a
// path the user named, and a lossy one would copy something else
pub struct Cp {
from: String,
to: String,
from: OsString,
to: OsString,
}
impl Cp {
pub fn into_container(local: &str, container: &str, remote: &str) -> Self {
pub fn into_container(local: &Path, container: &str, remote: &str) -> Self {
Self {
from: local.to_string(),
to: format!("{container}:{remote}"),
from: local.as_os_str().to_owned(),
to: OsString::from(format!("{container}:{remote}")),
}
}
pub fn out_of_container(container: &str, remote: &str, local: &str) -> Self {
pub fn out_of_container(container: &str, remote: &str, local: &Path) -> Self {
Self {
from: format!("{container}:{remote}"),
to: local.to_string(),
from: OsString::from(format!("{container}:{remote}")),
to: local.as_os_str().to_owned(),
}
}
}