Skip to content

Commit f244f51

Browse files
Iulian Barbuiulianbarbu
authored andcommitted
Removed tempfile dependency
Removed `tempfile` crate dependency, from crates.io, which was heavily using other dependencies which Firecracker does not use. Used instead `rust-vmm/vmm-sys-util` tempfile implementation, which provides support from temporary file and directory creation. Fixes #1125 Signed-off-by: Iulian Barbu <[email protected]>
1 parent 6790156 commit f244f51

File tree

24 files changed

+227
-334
lines changed

24 files changed

+227
-334
lines changed

Cargo.lock

Lines changed: 12 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/devices/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,3 @@ utils = { path = "../utils" }
1616
net_gen = { path = "../net_gen" }
1717
rate_limiter = { path = "../rate_limiter" }
1818
virtio_gen = { path = "../virtio_gen" }
19-
20-
[dev-dependencies]
21-
utils = { path = "../utils" }
22-
tempfile = ">=3.0.2"

src/devices/src/virtio/block.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,20 +654,20 @@ impl VirtioDevice for Block {
654654

655655
#[cfg(test)]
656656
mod tests {
657-
extern crate tempfile;
657+
extern crate utils;
658658

659-
use self::tempfile::{tempfile, NamedTempFile};
660-
use super::*;
661-
662-
use libc;
663-
use memory_model::Address;
664659
use std::fs::{metadata, OpenOptions};
665660
use std::sync::mpsc::Receiver;
666661
use std::thread;
667662
use std::time::Duration;
668663
use std::u32;
669664

665+
use libc;
666+
667+
use super::*;
670668
use crate::virtio::queue::tests::*;
669+
use memory_model::Address;
670+
use utils::tempfile::TempFile;
671671

672672
const EPOLLIN: epoll::Events = epoll::Events::EPOLLIN;
673673

@@ -707,13 +707,23 @@ mod tests {
707707

708708
let epoll_config = EpollConfig::new(0, epoll_raw_fd, sender);
709709

710-
let f: File = tempfile().unwrap();
711-
f.set_len(0x1000).unwrap();
710+
let tmp_f = TempFile::new().unwrap();
711+
tmp_f.as_file().set_len(0x1000).unwrap();
712+
713+
let mut perm = tmp_f.as_file().metadata().unwrap().permissions();
714+
perm.set_readonly(!is_disk_read_only);
715+
tmp_f.as_file().set_permissions(perm).unwrap();
712716

713717
// Rate limiting is enabled but with a high operation rate (10 million ops/s).
714718
let rate_limiter = RateLimiter::new(0, None, 0, 100_000, None, 10).unwrap();
715719
DummyBlock {
716-
block: Block::new(f, is_disk_read_only, epoll_config, Some(rate_limiter)).unwrap(),
720+
block: Block::new(
721+
tmp_f.as_file().try_clone().unwrap(),
722+
is_disk_read_only,
723+
epoll_config,
724+
Some(rate_limiter),
725+
)
726+
.unwrap(),
717727
epoll_raw_fd,
718728
_receiver,
719729
}
@@ -1513,8 +1523,8 @@ mod tests {
15131523

15141524
// test block device update handler
15151525
{
1516-
let f = NamedTempFile::new().unwrap();
1517-
let path = f.path().to_path_buf();
1526+
let f = TempFile::new().unwrap();
1527+
let path = f.as_path();
15181528
let mdata = metadata(&path).unwrap();
15191529
let mut id = vec![0; VIRTIO_BLK_ID_BYTES as usize];
15201530
let str_id = format!("{}{}{}", mdata.st_dev(), mdata.st_rdev(), mdata.st_ino());

src/firecracker/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ logger = { path = "../logger" }
1414
mmds = { path = "../mmds" }
1515
seccomp = { path = "../seccomp" }
1616
vmm = { path = "../vmm" }
17-
18-
[dev-dependencies]
19-
tempfile = ">=3.0.2"

src/jailer/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ libc = ">=0.2.39"
99
regex = ">=1.0.0"
1010

1111
utils = { path = "../utils" }
12-
13-
[dev-dependencies]
14-
tempfile = ">=3.0.2"

0 commit comments

Comments
 (0)