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. 29
      src/transaction.rs

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

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

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

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

Loading…
Cancel
Save