Skip to content

Commit

Permalink
Use tempdir everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 6, 2024
1 parent 00c644b commit 2b551b8
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 58 deletions.
6 changes: 1 addition & 5 deletions examples/all-types.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed::byteorder::BE;
use heed::types::*;
use heed::{Database, EnvOpenOptions};
use serde::{Deserialize, Serialize};

fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("target").join("heed.mdb");

fs::create_dir_all(&path)?;
let path = tempfile::tempdir()?;

let env = unsafe {
EnvOpenOptions::new()
Expand Down
7 changes: 1 addition & 6 deletions examples/clear-database.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed::types::*;
use heed::{Database, EnvOpenOptions};

// In this test we are checking that we can clear database entries and
// write just after in the same transaction without loosing the writes.
fn main() -> Result<(), Box<dyn Error>> {
let env_path = Path::new("target").join("clear-database.mdb");
let env_path = tempfile::tempdir()?;

let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
Expand Down
7 changes: 1 addition & 6 deletions examples/cursor-append.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed::types::*;
use heed::{Database, EnvOpenOptions, PutFlags};

// In this test we are checking that we can append ordered entries in one
// database even if there is multiple databases which already contain entries.
fn main() -> Result<(), Box<dyn Error>> {
let env_path = Path::new("target").join("cursor-append.mdb");
let env_path = tempfile::tempdir()?;

let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
Expand Down
8 changes: 2 additions & 6 deletions examples/custom-comparator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::Ordering;
use std::error::Error;
use std::path::Path;
use std::{fs, str};
use std::str;

use heed::EnvOpenOptions;
use heed_traits::Comparator;
Expand All @@ -21,11 +20,8 @@ impl Comparator for StringAsIntCmp {
}

fn main() -> Result<(), Box<dyn Error>> {
let env_path = Path::new("target").join("custom-key-cmp.mdb");
let env_path = tempfile::tempdir()?;

let _ = fs::remove_dir_all(&env_path);

fs::create_dir_all(&env_path)?;
let env = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
Expand Down
6 changes: 1 addition & 5 deletions examples/heed3-all-types.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed3::byteorder::BE;
use heed3::types::*;
use heed3::{Database, EnvOpenOptions};
use serde::{Deserialize, Serialize};

fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("target").join("heed3.mdb");

fs::create_dir_all(&path)?;
let path = tempfile::tempdir()?;

let env = unsafe {
EnvOpenOptions::new()
Expand Down
7 changes: 1 addition & 6 deletions examples/heed3-encrypted.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use argon2::Argon2;
use chacha20poly1305::{ChaCha20Poly1305, Key};
use heed3::types::*;
use heed3::EnvOpenOptions;

fn main() -> Result<(), Box<dyn Error>> {
let env_path = Path::new("target").join("encrypt.mdb");
let env_path = tempfile::tempdir()?;
let password = "This is the password that will be hashed by the argon2 algorithm";
let salt = "The salt added to the password hashes to add more security when stored";

let _ = fs::remove_dir_all(&env_path);
fs::create_dir_all(&env_path)?;

// We choose to use argon2 as our Key Derivation Function, but you can choose whatever you want.
// <https://github.com/RustCrypto/traits/tree/master/password-hash#supported-crates>
let mut key = Key::default();
Expand Down
9 changes: 2 additions & 7 deletions examples/multi-env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use byteorder::BE;
use heed::types::*;
Expand All @@ -9,18 +7,15 @@ use heed::{Database, EnvOpenOptions};
type BEU32 = U32<BE>;

fn main() -> Result<(), Box<dyn Error>> {
let env1_path = Path::new("target").join("env1.mdb");
let env2_path = Path::new("target").join("env2.mdb");

fs::create_dir_all(&env1_path)?;
let env1_path = tempfile::tempdir()?;
let env2_path = tempfile::tempdir()?;
let env1 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
.max_dbs(3000)
.open(env1_path)?
};

fs::create_dir_all(&env2_path)?;
let env2 = unsafe {
EnvOpenOptions::new()
.map_size(10 * 1024 * 1024) // 10MB
Expand Down
6 changes: 1 addition & 5 deletions examples/nested.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed::types::*;
use heed::{Database, EnvOpenOptions};

fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("target").join("heed.mdb");

fs::create_dir_all(&path)?;
let path = tempfile::tempdir()?;

let env = unsafe {
EnvOpenOptions::new()
Expand Down
6 changes: 1 addition & 5 deletions examples/rmp-serde.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use std::error::Error;
use std::fs;
use std::path::Path;

use heed::types::{SerdeRmp, Str};
use heed::{Database, EnvOpenOptions};
use serde::{Deserialize, Serialize};

fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("target").join("heed.mdb");

fs::create_dir_all(&path)?;
let path = tempfile::tempdir()?;

let env = unsafe {
EnvOpenOptions::new()
Expand Down
1 change: 0 additions & 1 deletion heed/src/envs/encrypted_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl EncryptedEnv {
/// use heed::types::*;
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// fs::create_dir_all(Path::new("target").join("database.mdb"))?;
/// let mut env_builder = EnvOpenOptions::new();
/// let dir = tempfile::tempdir().unwrap();
/// let env = unsafe { env_builder.open(dir.path())? };
Expand Down
1 change: 0 additions & 1 deletion heed/src/envs/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ impl Env {
/// use heed::types::*;
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// fs::create_dir_all(Path::new("target").join("database.mdb"))?;
/// let mut env_builder = EnvOpenOptions::new();
/// let dir = tempfile::tempdir().unwrap();
/// let env = unsafe { env_builder.open(dir.path())? };
Expand Down
7 changes: 2 additions & 5 deletions heed/src/envs/env_open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl EnvOpenOptions {
/// use heed::types::*;
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// fs::create_dir_all(Path::new("target").join("database.mdb"))?;
/// let mut env_builder = EnvOpenOptions::new();
/// unsafe { env_builder.flags(EnvFlags::NO_TLS | EnvFlags::NO_META_SYNC); }
/// let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -208,11 +207,10 @@ impl EnvOpenOptions {
/// use heed3::{EnvOpenOptions, Database};
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let env_path = Path::new("target").join("encrypt.mdb");
/// let env_path = tempfile::tempdir()?;
/// let password = "This is the password that will be hashed by the argon2 algorithm";
/// let salt = "The salt added to the password hashes to add more security when stored";
///
/// let _ = fs::remove_dir_all(&env_path);
/// fs::create_dir_all(&env_path)?;
///
/// let mut key = Key::default();
Expand Down Expand Up @@ -259,11 +257,10 @@ impl EnvOpenOptions {
/// use heed3_encryption::{EnvOpenOptions, Database};
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let env_path = Path::new("target").join("encrypt.mdb");
/// let env_path = tempfile::tempdir()?;
/// let password = "This is the password that will be hashed by the argon2 algorithm";
/// let salt = "The salt added to the password hashes to add more security when stored";
///
/// let _ = fs::remove_dir_all(&env_path);
/// fs::create_dir_all(&env_path)?;
///
/// let mut key = Key::default();
Expand Down

0 comments on commit 2b551b8

Please sign in to comment.