Skip to content

Commit

Permalink
Merge pull request #5 from CQCL/deps/replace-tempdir
Browse files Browse the repository at this point in the history
Remove deprecated tempdir dependency
  • Loading branch information
johnchildren authored May 26, 2023
2 parents 957974b + 272e80f commit 5208745
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tmp-postgrust"
version = "0.5.1"
version = "0.6.0"
authors = ["John Children <john.children@cambridgequantum.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -15,7 +15,7 @@ maintenance = { status = "experimental" }
[dependencies]
glob = "0.3"
nix = "0.26"
tempdir = "0.3"
tempfile = "3"
thiserror = "1.0"
tokio = { version = "1.8", features = ["parking_lot", "rt", "sync", "io-util", "process", "macros", "fs"], default-features = false, optional = true }
tracing = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use std::process::Stdio;
use std::sync::Arc;

use tempdir::TempDir;
use tempfile::TempDir;
use tokio::io::Lines;
use tokio::process::{ChildStderr, ChildStdout};

Expand Down
34 changes: 23 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{fs::File, io::Write};

use nix::unistd::{Gid, Uid, User};
use once_cell::sync::Lazy;
use tempdir::TempDir;
use tempfile::{Builder, TempDir};
use tracing::{debug, info, instrument};

use crate::errors::{TmpPostgrustError, TmpPostgrustResult};
Expand Down Expand Up @@ -101,10 +101,14 @@ impl TmpPostgrustFactory {
/// Try to create a new factory by creating temporary directories and the necessary config.
#[instrument]
pub fn try_new() -> TmpPostgrustResult<TmpPostgrustFactory> {
let socket_dir = TempDir::new("tmp-postgrust-socket")
let socket_dir = Builder::new()
.prefix("tmp-postgrust-socket")
.tempdir()
.map_err(TmpPostgrustError::CreateSocketDirFailed)?;
let cache_dir =
TempDir::new("tmp-postgrust-cache").map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let cache_dir = Builder::new()
.prefix("tmp-postgrust-cache")
.tempdir()
.map_err(TmpPostgrustError::CreateCacheDirFailed)?;

synchronous::chown_to_non_root(cache_dir.path())?;
synchronous::chown_to_non_root(socket_dir.path())?;
Expand All @@ -124,10 +128,14 @@ impl TmpPostgrustFactory {
#[cfg(feature = "tokio-process")]
#[instrument]
pub async fn try_new_async() -> TmpPostgrustResult<TmpPostgrustFactory> {
let socket_dir = TempDir::new("tmp-postgrust-socket")
let socket_dir = Builder::new()
.prefix("tmp-postgrust-socket")
.tempdir()
.map_err(TmpPostgrustError::CreateSocketDirFailed)?;
let cache_dir =
TempDir::new("tmp-postgrust-cache").map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let cache_dir = Builder::new()
.prefix("tmp-postgrust-cache")
.tempdir()
.map_err(TmpPostgrustError::CreateCacheDirFailed)?;

asynchronous::chown_to_non_root(cache_dir.path()).await?;
asynchronous::chown_to_non_root(socket_dir.path()).await?;
Expand All @@ -146,8 +154,10 @@ impl TmpPostgrustFactory {
/// up when dropped.
#[instrument(skip(self))]
pub fn new_instance(&self) -> TmpPostgrustResult<synchronous::ProcessGuard> {
let data_directory =
TempDir::new("tmp-postgrust-db").map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let data_directory = Builder::new()
.prefix("tmp-postgrust-db")
.tempdir()
.map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let data_directory_path = data_directory.path();

set_permissions(
Expand Down Expand Up @@ -230,8 +240,10 @@ impl TmpPostgrustFactory {
.await
.unwrap();

let data_directory =
TempDir::new("tmp-postgrust-db").map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let data_directory = Builder::new()
.prefix("tmp-postgrust-db")
.tempdir()
.map_err(TmpPostgrustError::CreateCacheDirFailed)?;
let data_directory_path = data_directory.path();

set_permissions(
Expand Down
2 changes: 1 addition & 1 deletion src/synchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::Arc;
use nix::sys::signal;
use nix::sys::signal::Signal;
use nix::unistd::{Pid, Uid};
use tempdir::TempDir;
use tempfile::TempDir;
use tracing::{debug, instrument};

use crate::errors::{ProcessCapture, TmpPostgrustError, TmpPostgrustResult};
Expand Down

0 comments on commit 5208745

Please sign in to comment.