Completely remove old_io

without.crypto
Dan Burkert 10 years ago
parent 735bd511c9
commit e33598b9b0
  1. 13
      src/cursor.rs
  2. 41
      src/environment.rs
  3. 8
      src/lib.rs
  4. 33
      src/transaction.rs

@ -290,7 +290,6 @@ impl <'txn> Iterator for IterDup<'txn> {
#[cfg(test)]
mod test {
use std::old_io as io;
use std::{fs, ptr};
use test::{Bencher, black_box};
@ -305,7 +304,7 @@ mod test {
#[test]
fn test_get() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -335,7 +334,7 @@ mod test {
#[test]
fn test_get_dup() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.create_db(None, DUP_SORT).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -381,7 +380,7 @@ mod test {
#[test]
fn test_get_dupfixed() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.create_db(None, DUP_SORT | DUP_FIXED).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -403,7 +402,7 @@ mod test {
#[test]
fn test_iter() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let items = vec!((b"key1", b"val1"),
@ -435,7 +434,7 @@ mod test {
#[test]
fn test_iter_dup() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.create_db(None, DUP_SORT).unwrap();
let items = vec!((b"a", b"1"),
@ -482,7 +481,7 @@ mod test {
#[test]
fn test_put_del() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let mut txn = env.begin_rw_txn().unwrap();

@ -1,7 +1,6 @@
use libc::{c_uint, size_t, mode_t};
use std::ffi::{AsOsStr, CString};
use std::os::unix::OsStrExt;
use std::old_io::FilePermission;
use std::path::Path;
use std::ptr;
use std::sync::Mutex;
@ -165,8 +164,19 @@ impl EnvironmentBuilder {
/// Open an environment.
///
/// On UNIX, the database files will be opened with 644 permissions.
///
/// The path may not contain the null character.
pub fn open(&self, path: &Path, mode: FilePermission) -> Result<Environment> {
pub fn open(&self, path: &Path) -> Result<Environment> {
self.open_with_permissions(path, 0o644)
}
/// Open an environment with the provided UNIX permissions.
///
/// On Windows, the permissions will be ignored.
///
/// The path may not contain the null character.
pub fn open_with_permissions(&self, path: &Path, mode: mode_t) -> Result<Environment> {
let mut env: *mut ffi::MDB_env = ptr::null_mut();
unsafe {
lmdb_try!(ffi::mdb_env_create(&mut env));
@ -185,11 +195,11 @@ impl EnvironmentBuilder {
lmdb_try_with_cleanup!(ffi::mdb_env_open(env,
CString::new(path.as_os_str().as_bytes()).unwrap().as_ptr(),
self.flags.bits(),
mode.bits() as mode_t),
mode),
ffi::mdb_env_close(env));
}
Ok(Environment { env: env,
dbi_open_mutex: Mutex::new(()) })
Ok(Environment { env: env, dbi_open_mutex: Mutex::new(()) })
}
pub fn set_flags(&mut self, flags: EnvironmentFlags) -> &mut EnvironmentBuilder {
@ -242,7 +252,6 @@ impl EnvironmentBuilder {
#[cfg(test)]
mod test {
use std::old_io as io;
use std::fs;
use flags::*;
@ -255,15 +264,15 @@ mod test {
// opening non-existent env with read-only should fail
assert!(Environment::new().set_flags(READ_ONLY)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.is_err());
// opening non-existent env should succeed
assert!(Environment::new().open(dir.path(), io::USER_RWX).is_ok());
assert!(Environment::new().open(dir.path()).is_ok());
// opening env with read-only should succeed
assert!(Environment::new().set_flags(READ_ONLY)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.is_ok());
}
@ -272,7 +281,7 @@ mod test {
let dir = fs::TempDir::new("test").unwrap();
{ // writable environment
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
assert!(env.begin_rw_txn().is_ok());
assert!(env.begin_ro_txn().is_ok());
@ -280,7 +289,7 @@ mod test {
{ // read-only environment
let env = Environment::new().set_flags(READ_ONLY)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.unwrap();
assert!(env.begin_rw_txn().is_err());
@ -292,7 +301,7 @@ mod test {
fn test_open_db() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(1)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.unwrap();
assert!(env.open_db(None).is_ok());
@ -303,7 +312,7 @@ mod test {
fn test_create_db() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(11)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.unwrap();
assert!(env.open_db(Some("testdb")).is_err());
assert!(env.create_db(Some("testdb"), DatabaseFlags::empty()).is_ok());
@ -314,7 +323,7 @@ mod test {
fn test_close_database() {
let dir = fs::TempDir::new("test").unwrap();
let mut env = Environment::new().set_max_dbs(10)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.unwrap();
let db = env.create_db(Some("db"), DatabaseFlags::empty()).unwrap();
@ -326,11 +335,11 @@ mod test {
fn test_sync() {
let dir = fs::TempDir::new("test").unwrap();
{
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
assert!(env.sync(true).is_ok());
} {
let env = Environment::new().set_flags(READ_ONLY)
.open(dir.path(), io::USER_RWX)
.open(dir.path())
.unwrap();
assert!(env.sync(true).is_err());
}

@ -1,8 +1,8 @@
//! Idiomatic and safe APIs for interacting with the
//! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/).
#![feature(core, libc, old_io, optin_builtin_traits, path, std_misc, unsafe_destructor)]
#![cfg_attr(test, feature(fs, tempdir, test))]
#![feature(core, libc, optin_builtin_traits, path, std_misc, unsafe_destructor)]
#![cfg_attr(test, feature(fs, io, tempdir, test))]
extern crate libc;
extern crate "lmdb-sys" as ffi;
@ -60,8 +60,6 @@ mod transaction;
#[cfg(test)]
mod test_utils {
use std::old_io as io;
use std::fs;
use super::*;
@ -76,7 +74,7 @@ mod test_utils {
pub fn setup_bench_db<'a>(num_rows: u32) -> (fs::TempDir, Environment) {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
{
let db = env.open_db(None).unwrap();

@ -1,7 +1,6 @@
use libc::{c_uint, c_void, size_t};
use std::{mem, ptr, raw};
use std::marker::{PhantomData, PhantomFn} ;
use std::old_io::BufWriter;
use ffi;
@ -280,7 +279,7 @@ impl <'env> RwTransaction<'env> {
key: &[u8],
len: size_t,
flags: WriteFlags)
-> Result<BufWriter<'txn>> {
-> Result<&'txn mut [u8]> {
let mut key_val: ffi::MDB_val = ffi::MDB_val { mv_size: key.len() as size_t,
mv_data: key.as_ptr() as *mut c_void };
let mut data_val: ffi::MDB_val = ffi::MDB_val { mv_size: len,
@ -291,12 +290,10 @@ impl <'env> RwTransaction<'env> {
&mut key_val,
&mut data_val,
flags.bits() | ffi::MDB_RESERVE)));
let slice: &'txn mut [u8] =
mem::transmute(raw::Slice {
data: data_val.mv_data as *const u8,
len: data_val.mv_size as usize
});
Ok(BufWriter::new(slice))
Ok(mem::transmute(raw::Slice {
data: data_val.mv_data as *const u8,
len: data_val.mv_size as usize
}))
}
}
@ -362,10 +359,10 @@ impl <'env> Transaction<'env> for RwTransaction<'env> {
#[cfg(test)]
mod test {
use std::old_io as io;
use std::{fs, ptr};
use rand::{Rng, XorShiftRng};
use std::io::Write;
use std::sync::{Arc, Barrier, Future};
use std::{fs, ptr};
use test::{Bencher, black_box};
use ffi::*;
@ -379,7 +376,7 @@ mod test {
#[test]
fn test_put_get_del() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -401,7 +398,7 @@ mod test {
#[test]
fn test_reserve() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -422,7 +419,7 @@ mod test {
#[test]
fn test_inactive_txn() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
{
@ -440,7 +437,7 @@ mod test {
#[test]
fn test_nested_txn() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
let mut txn = env.begin_rw_txn().unwrap();
@ -460,7 +457,7 @@ mod test {
#[test]
fn test_clear_db() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let env = Environment::new().open(dir.path()).unwrap();
let db = env.open_db(None).unwrap();
{
@ -484,7 +481,7 @@ mod test {
fn test_drop_db() {
let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(2)
.open(dir.path(), io::USER_RWX).unwrap();
.open(dir.path()).unwrap();
let db = env.create_db(Some("test"), DatabaseFlags::empty()).unwrap();
{
@ -504,7 +501,7 @@ mod test {
#[test]
fn test_concurrent_readers_single_writer() {
let dir = fs::TempDir::new("test").unwrap();
let env: Arc<Environment> = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap());
let env: Arc<Environment> = Arc::new(Environment::new().open(dir.path()).unwrap());
let n = 10usize; // Number of concurrent readers
let barrier = Arc::new(Barrier::new(n + 1));
@ -546,7 +543,7 @@ mod test {
#[test]
fn test_concurrent_writers() {
let dir = fs::TempDir::new("test").unwrap();
let env = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap());
let env = Arc::new(Environment::new().open(dir.path()).unwrap());
let n = 10usize; // Number of concurrent writers
let mut futures: Vec<Future<bool>> = Vec::with_capacity(n);

Loading…
Cancel
Save