File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use color_eyre::Result;
22use nix:: sys:: utsname:: UtsName ;
33use std:: {
44 fs:: File ,
5- io:: { self , Read } ,
5+ io:: { self , BufRead , BufReader } ,
66} ;
77
88pub fn get_system_info ( utsname : & UtsName ) -> nix:: Result < String > {
@@ -15,13 +15,15 @@ pub fn get_system_info(utsname: &UtsName) -> nix::Result<String> {
1515}
1616
1717pub fn get_os_pretty_name ( ) -> Result < String , io:: Error > {
18- let mut os_release_content = String :: with_capacity ( 1024 ) ;
19- File :: open ( "/etc/os-release" ) ? . read_to_string ( & mut os_release_content ) ? ;
18+ let file = File :: open ( "/etc/os-release" ) ? ;
19+ let reader = BufReader :: new ( file ) ;
2020
21- let pretty_name = os_release_content
22- . lines ( )
23- . find ( |line| line. starts_with ( "PRETTY_NAME=" ) )
24- . map ( |line| line. trim_start_matches ( "PRETTY_NAME=" ) . trim_matches ( '"' ) ) ;
21+ for line in reader. lines ( ) {
22+ let line = line?;
23+ if let Some ( pretty_name) = line. strip_prefix ( "PRETTY_NAME=" ) {
24+ return Ok ( pretty_name. trim_matches ( '"' ) . to_string ( ) ) ;
25+ }
26+ }
2527
26- Ok ( pretty_name . unwrap_or ( "Unknown" ) . to_string ( ) )
28+ Ok ( "Unknown" . to_string ( ) )
2729}
You can’t perform that action at this time.
0 commit comments