Compare commits

..

2 Commits

Author SHA1 Message Date
a444a5d8d2 deb: fix bug in find_dsc_file
Some checks failed
CI / build (push) Failing after 5m35s
2026-01-09 23:15:13 +01:00
dd62baa455 context/unshare: mount proc and dev/pts 2026-01-09 23:08:59 +01:00
7 changed files with 47 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ pub trait ContextDriver {
fn copy_path(&self, src: &Path, dest: &Path) -> io::Result<()>;
fn read_file(&self, path: &Path) -> io::Result<String>;
fn write_file(&self, path: &Path, content: &str) -> io::Result<()>;
fn exists(&self, path: &Path) -> io::Result<bool>;
}
/// Represents an execution environment (Local or via SSH).
@@ -180,6 +181,11 @@ impl Context {
self.driver().as_ref().unwrap().write_file(path, content)
}
/// Check if a file or directory exists inside context
pub fn exists(&self, path: &Path) -> io::Result<bool> {
self.driver().as_ref().unwrap().exists(path)
}
/// Create and obtain a specific driver for the context
pub fn driver(
&self,

View File

@@ -78,6 +78,10 @@ impl ContextDriver for LocalDriver {
fn write_file(&self, path: &Path, content: &str) -> io::Result<()> {
std::fs::write(path, content)
}
fn exists(&self, path: &Path) -> io::Result<bool> {
Ok(path.exists())
}
}
fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> {

View File

@@ -262,4 +262,14 @@ impl ContextDriver for SchrootDriver {
}
Ok(())
}
fn exists(&self, path: &Path) -> io::Result<bool> {
let status = self.run(
"test",
&["-e".to_string(), path.to_string_lossy().to_string()],
&[],
None,
)?;
Ok(status.success())
}
}

View File

@@ -244,6 +244,15 @@ impl ContextDriver for SshDriver {
remote_file.write_all(content.as_bytes())?;
Ok(())
}
fn exists(&self, path: &Path) -> io::Result<bool> {
let sess = connect_ssh(&self.host, self.user.as_deref(), self.port)?;
let sftp = sess.sftp().map_err(io::Error::other)?;
match sftp.stat(path) {
Ok(_) => Ok(true),
Err(_) => Ok(false),
}
}
}
impl SshDriver {

View File

@@ -150,6 +150,11 @@ impl ContextDriver for UnshareDriver {
let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/'));
self.parent().write_file(&host_path, content)
}
fn exists(&self, path: &Path) -> io::Result<bool> {
let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/'));
self.parent().exists(&host_path)
}
}
impl UnshareDriver {
@@ -172,9 +177,12 @@ impl UnshareDriver {
cmd.arg("--map-user=65536")
.arg("--map-group=65536")
.arg("--mount-proc")
.arg("--pid")
.arg("--ipc")
.arg("--uts")
.arg("--user")
.arg("--cgroup")
.arg("--map-auto")
.arg("-r")
.arg("--mount")
@@ -186,7 +194,11 @@ impl UnshareDriver {
cmd.arg("-w").arg(dir);
}
cmd.arg("--").arg(program).args(args);
cmd.arg("--").arg("bash").arg("-c").arg(format!(
"mount -t devpts devpts /dev/pts; mount --bind /dev/pts/ptmx /dev/ptmx; {} {}",
program,
args.join(" ")
));
cmd
}

View File

@@ -79,6 +79,7 @@ impl EphemeralContextGuard {
.command("mmdebstrap")
.arg("--variant=buildd")
.arg("--mode=unshare")
.arg("--include=mount")
.arg("--format=tar")
.arg(series)
.arg(tarball_path.to_string_lossy().to_string())
@@ -112,7 +113,7 @@ impl EphemeralContextGuard {
impl Drop for EphemeralContextGuard {
fn drop(&mut self) {
log::debug!("Cleaning up ephemeral context...");
log::debug!("Cleaning up ephemeral context ({:?})...", &self.chroot_path);
// Reset to normal context
if let Err(e) = context::manager().set_current(&self.previous_context) {
log::error!("Failed to restore context {}: {}", self.previous_context, e);

View File

@@ -95,7 +95,9 @@ fn find_dsc_file(
let dsc_name = format!("{}_{}.dsc", package, version_without_epoch);
let dsc_path = PathBuf::from(build_root).join(&dsc_name);
if !dsc_path.exists() {
// Check if the .dsc file exists in current context
let ctx = context::current();
if !ctx.exists(&dsc_path)? {
return Err(format!("Could not find .dsc file at {}", dsc_path.display()).into());
}
Ok(dsc_path)