pub use std::os::unix::process::CommandExt;
pub use std::os::unix::fs::DirBuilderExt;
pub use std::os::linux::fs::MetadataExt; // todo why linux for st_mode??
+pub use std::path;
pub use std::process::{Command, Stdio};
pub type AE = anyhow::Error;
}
#[throws(AE)]
-fn prepare_tmpdir(opts: &Opts, current_exe: &str) -> String {
+fn prepare_tmpdir(opts: &Opts, current_exe: &str) -> (String, String) {
(||{
match fs::metadata(&opts.tmp_dir) {
Ok(m) => {
Err(e) if e.kind() == ErrorKind::NotFound => {},
Err(e) => throw!(AE::from(e).context("remove previous directory")),
};
- fs::DirBuilder::new().mode(0o700).create(&leaf)
+
+ fs::DirBuilder::new().create(&leaf)
.context("create fresh subdirectory")?;
+
+ env::set_current_dir(&leaf)
+ .context("chdir into it")?;
+
Ok::<_,AE>(())
})()
.with_context(|| our_tmpdir.to_owned())
.context("prepare/create our tmp subdir")?;
- our_tmpdir
+ let abstmp =
+ env::current_dir().context("canonicalise our tmp subdi (getcwd)r")?
+ .to_str()
+ .ok_or_else(|| anyhow!("tmp path is not UTF-8"))?
+ .to_owned();
+
+ (our_tmpdir, abstmp)
}
#[throws(AE)]
}
#[throws(AE)]
-fn prepare_xserver(cln: &cleanup_notify::Handle) {
+fn prepare_xserver(cln: &cleanup_notify::Handle, abstmp: &str) {
const DISPLAY : u16 = 12;
let mut xcmd = Command::new("Xvfb");
-terminate \
-wr \
-displayfd 1".split(' '))
+ .args(&["-fbdir", abstmp])
.arg(format!(":{}", DISPLAY));
let l = fork_something_which_prints(xcmd, cln).context("Xvfb")?;
impl Drop for FinalInfoCollection {
fn drop(&mut self) {
match (||{
+ fs::copy("Xvfb_screen0","final-auto.xwd")
+ .context("copy")?;
+
let mut cmd = Command::new("xwd");
cmd.args("-root \
-silent \
}
let cln = cleanup_notify::Handle::new()?;
+ let (tmp, abstmp) = prepare_tmpdir(&opts, ¤t_exe)?;
- let tmp = prepare_tmpdir(&opts, ¤t_exe)?;
-
- prepare_xserver(&cln).context("setup X server")?;
+ prepare_xserver(&cln, &abstmp).context("setup X server")?;
let final_hook = FinalInfoCollection;