diff --git a/src/node.rs b/src/node.rs index 32022fa..f0868a5 100644 --- a/src/node.rs +++ b/src/node.rs @@ -1,12 +1,7 @@ use std::fs::File; +use std::io::{Seek, SeekFrom, Write}; use std::mem::size_of; -#[cfg(unix)] -use std::os::unix::fs::FileExt; - -#[cfg(windows)] -use std::os::windows::fs::FileExt; - use crate::bucket::Bucket; use crate::cursor::PageNodeID; use crate::data::{Data, SliceParts}; @@ -241,8 +236,8 @@ impl Node { let page = unsafe { &mut *(&mut buf[0] as *mut u8 as *mut Page) }; page.write_node(self, self.num_pages)?; let offset = (self.page_id as u64) * (self.bucket.tx.meta.pagesize as u64); - // println!("WRITING PAGE: {:?} at {}", page, offset); - file.write_all_at(buf.as_slice(), offset)?; + file.seek(SeekFrom::Start(offset))?; + file.write_all(buf.as_slice())?; Ok(()) } diff --git a/src/transaction.rs b/src/transaction.rs index 9b875fe..2d7a319 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -1,14 +1,8 @@ use std::fs::File; -use std::io::Write; +use std::io::{Seek, SeekFrom, Write}; use std::pin::Pin; use std::sync::{Arc, MutexGuard}; -#[cfg(unix)] -use std::os::unix::fs::FileExt; - -#[cfg(windows)] -use std::os::windows::fs::FileExt; - use memmap::Mmap; use crate::bucket::Bucket; @@ -299,7 +293,8 @@ impl<'a> TransactionInner { page.count = page_ids.len() as u64; page.freelist_mut().copy_from_slice(page_ids.as_slice()); - file.write_all_at(buf.as_slice(), (self.db.pagesize * page_id) as u64)?; + file.seek(SeekFrom::Start((self.db.pagesize * page_id) as u64))?; + file.write_all(buf.as_slice())?; self.meta.freelist_page = page_id; } @@ -323,7 +318,9 @@ impl<'a> TransactionInner { m.freelist_page = self.meta.freelist_page; m.tx_id = self.meta.tx_id; m.hash = m.hash_self(); - file.write_all_at(buf.as_slice(), (self.db.pagesize * meta_page_id) as u64)?; + + file.seek(SeekFrom::Start((self.db.pagesize * meta_page_id) as u64))?; + file.write_all(buf.as_slice())?; } file.flush()?;