Skip to content

Commit 11185cb

Browse files
N3xp7im3hnez
andauthored
Apply suggestions from code review
Co-authored-by: Leonard Göhrs <[email protected]>
1 parent 4e6cbfa commit 11185cb

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ fn read_file(filename: &str) -> std::result::Result<String, String> {
5454
}
5555

5656
fn wait_for_device(root_device: &str) -> Result<()> {
57-
let mut counter = 0;
58-
while !Path::new(&root_device).exists() {
59-
let duration = time::Duration::from_millis(5);
57+
let duration = time::Duration::from_millis(5);
58+
let path = Path::new(&root_device);
6059

61-
if counter > 1000 {
62-
return Err("timout reached while waiting for the device".into());
60+
for _ in 0..1000 {
61+
if path.exists() {
62+
return Ok(());
6363
}
6464

6565
thread::sleep(duration);
66-
counter += 1;
6766
}
68-
Ok(())
67+
68+
Err("timout reached while waiting for the device".into())
6969
}
7070

7171
/*

src/mount.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,10 @@ pub fn mount_root(options: &CmdlineOptions) -> Result<()> {
4949
return Err("root= not found in /proc/cmdline".into());
5050
}
5151

52-
if options.rootfstype != Some("nfs".to_string()) &&
53-
options.rootfstype != Some("9p".to_string())
54-
{
55-
let root_device = options.root.as_ref().ok_or("No root device argument")?;
56-
wait_for_device(root_device)?;
52+
match options.rootfstype.as_deref() {
53+
Some("nfs") | Some("9p") => (),
54+
_ => wait_for_device(root)?,
5755
}
58-
5956
mkdir("/root")?;
6057

6158
debug!(

0 commit comments

Comments
 (0)