sbuild options: unshare, build directory context: retrieve files
This commit is contained in:
@@ -77,6 +77,30 @@ impl ContextDriver for SshDriver {
|
||||
})
|
||||
}
|
||||
|
||||
fn retrieve_path(&self, src: &Path, dest: &Path) -> io::Result<()> {
|
||||
let sess = connect_ssh(&self.host, self.user.as_deref(), self.port)?;
|
||||
let sftp = sess.sftp().map_err(io::Error::other)?;
|
||||
|
||||
debug!("Downloading remote {:?} to {:?}", src, dest);
|
||||
Self::download_recursive(&sftp, src, dest)
|
||||
}
|
||||
|
||||
fn list_files(&self, path: &Path) -> io::Result<Vec<PathBuf>> {
|
||||
let sess = connect_ssh(&self.host, self.user.as_deref(), self.port)?;
|
||||
let sftp = sess.sftp().map_err(io::Error::other)?;
|
||||
|
||||
let mut files = Vec::new();
|
||||
let entries = sftp.readdir(path).map_err(io::Error::other)?;
|
||||
for (p, _) in entries {
|
||||
let file_name = p.file_name().unwrap();
|
||||
if file_name == "." || file_name == ".." {
|
||||
continue;
|
||||
}
|
||||
files.push(p);
|
||||
}
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
fn prepare_work_dir(&self) -> io::Result<String> {
|
||||
let sess = connect_ssh(&self.host, self.user.as_deref(), self.port)?;
|
||||
let mut channel = sess.channel_session().map_err(io::Error::other)?;
|
||||
@@ -118,6 +142,30 @@ impl SshDriver {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn download_recursive(sftp: &ssh2::Sftp, src: &Path, dest: &Path) -> io::Result<()> {
|
||||
let stat = sftp
|
||||
.stat(src)
|
||||
.map_err(|e| io::Error::other(format!("Remote stat failed for {:?}: {}", src, e)))?;
|
||||
|
||||
if stat.is_dir() {
|
||||
fs::create_dir_all(dest)?;
|
||||
let entries = sftp.readdir(src).map_err(io::Error::other)?;
|
||||
for (path, _) in entries {
|
||||
let file_name = path.file_name().unwrap();
|
||||
if file_name == "." || file_name == ".." {
|
||||
continue;
|
||||
}
|
||||
let new_dest = dest.join(file_name);
|
||||
Self::download_recursive(sftp, &path, &new_dest)?;
|
||||
}
|
||||
} else {
|
||||
let mut remote_file = sftp.open(src).map_err(io::Error::other)?;
|
||||
let mut local_file = fs::File::create(dest)?;
|
||||
io::copy(&mut remote_file, &mut local_file)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SshRunner {
|
||||
|
||||
Reference in New Issue
Block a user