diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2021-02-13 23:41:29 +0100 |
---|---|---|
committer | sternenseemann <sternenseemann@systemli.org> | 2021-02-25 19:52:33 +0100 |
commit | 8cdd3cdfb3afb76b01c8dc013d95e6336e4dfb82 (patch) | |
tree | 409eff983b677a9a942d2101312b202545c11f6c /pkgs/profpatsch/nman/nman.rs | |
parent | c485d777989771305a58ac9421ea57e4dfcbfdcc (diff) |
pkgs/profpatsch/nman: use pkgs.sternenseemann.temp for TempDir
temp is essentially the old TempDir code from nman, but using libc's mkdtemp(3) directly instead of mktemp(1) and a slightly better API.
Diffstat (limited to 'pkgs/profpatsch/nman/nman.rs')
-rw-r--r-- | pkgs/profpatsch/nman/nman.rs | 48 |
1 files changed, 6 insertions, 42 deletions
diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs index c289e6ff..6e7ecf5d 100644 --- a/pkgs/profpatsch/nman/nman.rs +++ b/pkgs/profpatsch/nman/nman.rs @@ -1,46 +1,10 @@ +extern crate temp; + use std::ffi::{OsStr, OsString}; -use std::io::{Error, ErrorKind, self, Write}; use std::os::unix::ffi::OsStrExt; -use std::path::{Path, PathBuf}; -use std::process::{Command,ExitStatus}; - -struct TempDir { - inner: Vec<u8>, -} - -impl AsRef<Path> for TempDir { - fn as_ref(&self) -> &Path { - OsStr::from_bytes(&self.inner[..]).as_ref() - } -} - -impl Drop for TempDir { - fn drop(&mut self) { - std::fs::remove_dir_all(self.as_ref()); - std::fs::remove_dir(self.as_ref()); - } -} - -fn mktemp(suffix: &str) -> std::io::Result<TempDir> { - let mut mktemp = Command::new("mktemp") - .arg("-d") - .arg("--suffix") - .arg(suffix) - .output()?; - - if mktemp.status.success() { - // remove trailing newline - if mktemp.stdout.ends_with(b"\n") { - mktemp.stdout.pop(); - } - - Ok(TempDir { - inner: mktemp.stdout - }) - } else { - Err(Error::new(ErrorKind::Other, "mktemp exited with a non-zero status")) - } -} +use std::path::PathBuf; +use std::process::Command; +use temp::TempDir; enum NmanError<'a> { NoTempDir, @@ -194,7 +158,7 @@ fn build_man_page<'a>(drv: DrvWithOutput, section: &str, page: &str, tempdir: &T } fn open_man_page<'a>(attr: &'a str, section: &'a str, page: &'a str) -> Result<(), NmanError<'a>> { - let tmpdir = mktemp("-nman").map_err(|_| NmanError::NoTempDir)?; + let tmpdir = TempDir::new("nman").map_err(|_| NmanError::NoTempDir)?; let expr = format!("with (import <nixpkgs> {{}}); builtins.map (o: {}.\"${{o}}\") {}.outputs", attr, attr); let inst = Command::new("nix-instantiate") .arg("-E") |