Compare commits
2 Commits
464e25de24
...
a444a5d8d2
| Author | SHA1 | Date | |
|---|---|---|---|
|
a444a5d8d2
|
|||
|
dd62baa455
|
@@ -33,6 +33,7 @@ pub trait ContextDriver {
|
|||||||
fn copy_path(&self, src: &Path, dest: &Path) -> io::Result<()>;
|
fn copy_path(&self, src: &Path, dest: &Path) -> io::Result<()>;
|
||||||
fn read_file(&self, path: &Path) -> io::Result<String>;
|
fn read_file(&self, path: &Path) -> io::Result<String>;
|
||||||
fn write_file(&self, path: &Path, content: &str) -> io::Result<()>;
|
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).
|
/// Represents an execution environment (Local or via SSH).
|
||||||
@@ -180,6 +181,11 @@ impl Context {
|
|||||||
self.driver().as_ref().unwrap().write_file(path, content)
|
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
|
/// Create and obtain a specific driver for the context
|
||||||
pub fn driver(
|
pub fn driver(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ impl ContextDriver for LocalDriver {
|
|||||||
fn write_file(&self, path: &Path, content: &str) -> io::Result<()> {
|
fn write_file(&self, path: &Path, content: &str) -> io::Result<()> {
|
||||||
std::fs::write(path, content)
|
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<()> {
|
fn copy_dir_recursive(src: &Path, dest: &Path) -> io::Result<()> {
|
||||||
|
|||||||
@@ -262,4 +262,14 @@ impl ContextDriver for SchrootDriver {
|
|||||||
}
|
}
|
||||||
Ok(())
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,6 +244,15 @@ impl ContextDriver for SshDriver {
|
|||||||
remote_file.write_all(content.as_bytes())?;
|
remote_file.write_all(content.as_bytes())?;
|
||||||
Ok(())
|
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 {
|
impl SshDriver {
|
||||||
|
|||||||
@@ -150,6 +150,11 @@ impl ContextDriver for UnshareDriver {
|
|||||||
let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/'));
|
let host_path = Path::new(&self.path).join(path.to_string_lossy().trim_start_matches('/'));
|
||||||
self.parent().write_file(&host_path, content)
|
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 {
|
impl UnshareDriver {
|
||||||
@@ -172,9 +177,12 @@ impl UnshareDriver {
|
|||||||
|
|
||||||
cmd.arg("--map-user=65536")
|
cmd.arg("--map-user=65536")
|
||||||
.arg("--map-group=65536")
|
.arg("--map-group=65536")
|
||||||
|
.arg("--mount-proc")
|
||||||
.arg("--pid")
|
.arg("--pid")
|
||||||
.arg("--ipc")
|
.arg("--ipc")
|
||||||
.arg("--uts")
|
.arg("--uts")
|
||||||
|
.arg("--user")
|
||||||
|
.arg("--cgroup")
|
||||||
.arg("--map-auto")
|
.arg("--map-auto")
|
||||||
.arg("-r")
|
.arg("-r")
|
||||||
.arg("--mount")
|
.arg("--mount")
|
||||||
@@ -186,7 +194,11 @@ impl UnshareDriver {
|
|||||||
cmd.arg("-w").arg(dir);
|
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
|
cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ impl EphemeralContextGuard {
|
|||||||
.command("mmdebstrap")
|
.command("mmdebstrap")
|
||||||
.arg("--variant=buildd")
|
.arg("--variant=buildd")
|
||||||
.arg("--mode=unshare")
|
.arg("--mode=unshare")
|
||||||
|
.arg("--include=mount")
|
||||||
.arg("--format=tar")
|
.arg("--format=tar")
|
||||||
.arg(series)
|
.arg(series)
|
||||||
.arg(tarball_path.to_string_lossy().to_string())
|
.arg(tarball_path.to_string_lossy().to_string())
|
||||||
@@ -112,7 +113,7 @@ impl EphemeralContextGuard {
|
|||||||
|
|
||||||
impl Drop for EphemeralContextGuard {
|
impl Drop for EphemeralContextGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
log::debug!("Cleaning up ephemeral context...");
|
log::debug!("Cleaning up ephemeral context ({:?})...", &self.chroot_path);
|
||||||
// Reset to normal context
|
// Reset to normal context
|
||||||
if let Err(e) = context::manager().set_current(&self.previous_context) {
|
if let Err(e) = context::manager().set_current(&self.previous_context) {
|
||||||
log::error!("Failed to restore context {}: {}", self.previous_context, e);
|
log::error!("Failed to restore context {}: {}", self.previous_context, e);
|
||||||
|
|||||||
@@ -95,7 +95,9 @@ fn find_dsc_file(
|
|||||||
let dsc_name = format!("{}_{}.dsc", package, version_without_epoch);
|
let dsc_name = format!("{}_{}.dsc", package, version_without_epoch);
|
||||||
let dsc_path = PathBuf::from(build_root).join(&dsc_name);
|
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());
|
return Err(format!("Could not find .dsc file at {}", dsc_path.display()).into());
|
||||||
}
|
}
|
||||||
Ok(dsc_path)
|
Ok(dsc_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user