From a444a5d8d247ee4d772ac81e79ea5bdfadff3b67 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Fri, 9 Jan 2026 23:15:13 +0100 Subject: [PATCH] deb: fix bug in find_dsc_file --- src/context/api.rs | 6 ++++++ src/context/local.rs | 4 ++++ src/context/schroot.rs | 10 ++++++++++ src/context/ssh.rs | 9 +++++++++ src/context/unshare.rs | 5 +++++ src/deb/mod.rs | 4 +++- 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/context/api.rs b/src/context/api.rs index 0403886..7ee38b3 100644 --- a/src/context/api.rs +++ b/src/context/api.rs @@ -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; fn write_file(&self, path: &Path, content: &str) -> io::Result<()>; + fn exists(&self, path: &Path) -> io::Result; } /// 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 { + self.driver().as_ref().unwrap().exists(path) + } + /// Create and obtain a specific driver for the context pub fn driver( &self, diff --git a/src/context/local.rs b/src/context/local.rs index ac118b4..7d391cc 100644 --- a/src/context/local.rs +++ b/src/context/local.rs @@ -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 { + Ok(path.exists()) + } } fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> { diff --git a/src/context/schroot.rs b/src/context/schroot.rs index ddd284a..a490d2a 100644 --- a/src/context/schroot.rs +++ b/src/context/schroot.rs @@ -262,4 +262,14 @@ impl ContextDriver for SchrootDriver { } Ok(()) } + + fn exists(&self, path: &Path) -> io::Result { + let status = self.run( + "test", + &["-e".to_string(), path.to_string_lossy().to_string()], + &[], + None, + )?; + Ok(status.success()) + } } diff --git a/src/context/ssh.rs b/src/context/ssh.rs index 69b4ab8..382f58f 100644 --- a/src/context/ssh.rs +++ b/src/context/ssh.rs @@ -244,6 +244,15 @@ impl ContextDriver for SshDriver { remote_file.write_all(content.as_bytes())?; Ok(()) } + + fn exists(&self, path: &Path) -> io::Result { + 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 { diff --git a/src/context/unshare.rs b/src/context/unshare.rs index 8f70667..c1d86de 100644 --- a/src/context/unshare.rs +++ b/src/context/unshare.rs @@ -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 { + let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/')); + self.parent().exists(&host_path) + } } impl UnshareDriver { diff --git a/src/deb/mod.rs b/src/deb/mod.rs index 3624098..261bd27 100644 --- a/src/deb/mod.rs +++ b/src/deb/mod.rs @@ -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)