Last active
March 19, 2017 03:28
-
-
Save KodrAus/69a405497676536e8b494cc151633e03 to your computer and use it in GitHub Desktop.
Test deleting an mmapped file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate memmap; | |
extern crate tempdir; | |
use std::path::PathBuf; | |
use std::fs::{File, remove_file}; | |
use std::io::Write; | |
use std::str; | |
use tempdir::TempDir; | |
use memmap::{Mmap, Protection}; | |
fn mkdir(dir: &TempDir) -> PathBuf { | |
let path = dir.path().join("file"); | |
let mut f = File::create(&path).unwrap(); | |
f.write_all(b"all the bits").unwrap(); | |
f.sync_all().unwrap(); | |
path.into() | |
} | |
fn main() { | |
let dir = TempDir::new("memmap_test").unwrap(); | |
let filepath = mkdir(&dir); | |
let mapped = Mmap::open_path(&filepath, Protection::Read).unwrap(); | |
// Windows: OsError: Access is Denied | |
remove_file(&filepath).unwrap(); | |
println!("{}", str::from_utf8(unsafe { mapped.as_slice() }).unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Windows: