Commit 65ca46dc authored by Stefan Schindler's avatar Stefan Schindler
Browse files

Fix randomly ordered disks detection problem

parent 87ca7377
......@@ -111,11 +111,11 @@ fn parse_partition_file(partitions: &String) -> Vec<Arc<DiskInformation>> {
}
fn mark_mounted_disks(disks: &Vec<Arc<DiskInformation>>, mounts: String) {
let mut mount_lines = mounts.split('\n').filter(|e| {
e.starts_with("/dev/")
});
for disk in disks {
let mut mount_lines = mounts.split('\n').filter(|e: &&str| {
e.starts_with("/dev/")
});
let disk_path = format!("/dev/{}", disk.name);
if mount_lines.any(|e| e.starts_with(&*disk_path)) {
......@@ -634,4 +634,59 @@ mod test {
assert_eq!(Protected, *(*disks[0]).state.lock().unwrap());
}
#[test]
fn protect_sdb() {
let disks = vec![
Arc::new(DiskInformation {
id: 1,
name: "sda".into(),
size: Byte(0),
state: Mutex::new(Detected),
}),
Arc::new(DiskInformation {
id: 2,
name: "sdb".into(),
size: Byte(0),
state: Mutex::new(Detected),
}),
];
let mounts = r#"
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
dev on /dev type devtmpfs (rw,nosuid,relatime,size=8049952k,nr_inodes=2012488,mode=755)
run on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
/dev/sdb3 on / type btrfs (rw,relatime,space_cache,subvolid=5,subvol=/)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=36,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev)
/dev/sdb4 on /boot type ext2 (rw,relatime,block_validity,barrier,user_xattr,acl)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=1612120k,mode=700)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
"#.into();
mark_mounted_disks(&disks, mounts);
assert_eq!(Detected, *(*disks[0]).state.lock().unwrap());
assert_eq!(Protected, *(*disks[1]).state.lock().unwrap());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment