|
|
@ -354,7 +354,8 @@ pub enum LinkError {
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
mod tests {
|
|
|
|
use matches::assert_matches;
|
|
|
|
use matches::assert_matches;
|
|
|
|
use std::{cell::RefCell, env, fs::File, mem, os::unix::io::AsRawFd, rc::Rc};
|
|
|
|
use std::{cell::RefCell, fs::File, mem, os::unix::io::AsRawFd, rc::Rc};
|
|
|
|
|
|
|
|
use tempfile::tempdir;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{programs::ProgramError, sys::override_syscall};
|
|
|
|
use crate::{programs::ProgramError, sys::override_syscall};
|
|
|
|
|
|
|
|
|
|
|
@ -489,8 +490,8 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
#[cfg_attr(miri, ignore)]
|
|
|
|
#[cfg_attr(miri, ignore)]
|
|
|
|
fn test_pin() {
|
|
|
|
fn test_pin() {
|
|
|
|
let dir = env::temp_dir();
|
|
|
|
let dir = tempdir().unwrap();
|
|
|
|
let f1 = File::create(dir.join("f1")).expect("unable to create file in tmpdir");
|
|
|
|
let f1 = File::create(dir.path().join("f1")).expect("unable to create file in tmpdir");
|
|
|
|
let fd_link = FdLink::new(f1.as_raw_fd());
|
|
|
|
let fd_link = FdLink::new(f1.as_raw_fd());
|
|
|
|
|
|
|
|
|
|
|
|
// leak the fd, it will get closed when our pinned link is dropped
|
|
|
|
// leak the fd, it will get closed when our pinned link is dropped
|
|
|
@ -499,11 +500,12 @@ mod tests {
|
|
|
|
// override syscall to allow for pin to happen in our tmpdir
|
|
|
|
// override syscall to allow for pin to happen in our tmpdir
|
|
|
|
override_syscall(|_| Ok(0));
|
|
|
|
override_syscall(|_| Ok(0));
|
|
|
|
// create the file that would have happened as a side-effect of a real pin operation
|
|
|
|
// create the file that would have happened as a side-effect of a real pin operation
|
|
|
|
File::create(dir.join("f1-pin")).expect("unable to create file in tmpdir");
|
|
|
|
let pin = dir.path().join("f1-pin");
|
|
|
|
assert!(dir.join("f1-pin").exists());
|
|
|
|
File::create(&pin).expect("unable to create file in tmpdir");
|
|
|
|
|
|
|
|
assert!(pin.exists());
|
|
|
|
|
|
|
|
|
|
|
|
let pinned_link = fd_link.pin(dir.join("f1-pin")).expect("pin failed");
|
|
|
|
let pinned_link = fd_link.pin(&pin).expect("pin failed");
|
|
|
|
pinned_link.unpin().expect("unpin failed");
|
|
|
|
pinned_link.unpin().expect("unpin failed");
|
|
|
|
assert!(!dir.join("f1-pin").exists());
|
|
|
|
assert!(!pin.exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|