11use std:: { borrow:: Cow , collections:: { HashMap , HashSet } , ffi:: { OsStr , OsString } , os:: { fd:: AsFd , unix:: { ffi:: { OsStrExt , OsStringExt } , fs:: MetadataExt } } , time:: Duration } ;
22
3- use anyhow:: Result ;
3+ use anyhow:: { Context , Result } ;
44use tokio:: { io:: { Interest , unix:: AsyncFd } , time:: sleep} ;
55use tracing:: error;
66use yazi_shared:: { natsort, replace_cow, replace_vec_cow} ;
@@ -43,7 +43,7 @@ impl Partitions {
4343 tokio:: spawn ( async move {
4444 loop {
4545 if let Err ( e) = wait_mounts ( me_. clone ( ) , cb) . await {
46- error ! ( "Error encountered while monitoring ` /proc/mounts` : {e:?}" ) ;
46+ error ! ( "Error encountered while monitoring /proc/mounts: {e:?}" ) ;
4747 }
4848 sleep ( Duration :: from_secs ( 5 ) ) . await ;
4949 }
@@ -52,7 +52,7 @@ impl Partitions {
5252 tokio:: spawn ( async move {
5353 loop {
5454 if let Err ( e) = wait_partitions ( me. clone ( ) , cb) . await {
55- error ! ( "Error encountered while monitoring ` /proc/partitions` : {e:?}" ) ;
55+ error ! ( "Error encountered while monitoring /proc/partitions: {e:?}" ) ;
5656 }
5757 sleep ( Duration :: from_secs ( 5 ) ) . await ;
5858 }
@@ -71,7 +71,7 @@ impl Partitions {
7171 }
7272
7373 fn all ( & self ) -> Result < Vec < Partition > > {
74- let mut mounts = Self :: mounts ( ) ?;
74+ let mut mounts = Self :: mounts ( ) . context ( "Parsing /proc/mounts" ) ?;
7575 {
7676 let set = & self . linux_cache ;
7777 let mut set: HashSet < & OsStr > = set. iter ( ) . map ( AsRef :: as_ref) . collect ( ) ;
@@ -80,7 +80,7 @@ impl Partitions {
8080 mounts. sort_unstable_by ( |a, b| natsort ( a. src . as_bytes ( ) , b. src . as_bytes ( ) , false ) ) ;
8181 } ;
8282
83- let labels = Self :: labels ( ) ? ;
83+ let labels = Self :: labels ( ) ;
8484 for mount in & mut mounts {
8585 if !mount. src . as_bytes ( ) . starts_with ( b"/dev/" ) {
8686 continue ;
@@ -126,10 +126,15 @@ impl Partitions {
126126 Ok ( set)
127127 }
128128
129- fn labels ( ) -> Result < HashMap < ( u64 , u64 ) , OsString > > {
129+ fn labels ( ) -> HashMap < ( u64 , u64 ) , OsString > {
130130 let mut map = HashMap :: new ( ) ;
131- for entry in std:: fs:: read_dir ( "/dev/disk/by-label" ) ?. flatten ( ) {
132- let meta = std:: fs:: metadata ( entry. path ( ) ) ?;
131+ let Ok ( it) = std:: fs:: read_dir ( "/dev/disk/by-label" ) else {
132+ error ! ( "Cannot read /dev/disk/by-label" ) ;
133+ return map;
134+ } ;
135+
136+ for entry in it. flatten ( ) {
137+ let Ok ( meta) = std:: fs:: metadata ( entry. path ( ) ) else { continue } ;
133138 let name = entry. file_name ( ) ;
134139 map. insert (
135140 ( meta. dev ( ) , meta. ino ( ) ) ,
@@ -139,7 +144,7 @@ impl Partitions {
139144 } ,
140145 ) ;
141146 }
142- Ok ( map)
147+ map
143148 }
144149
145150 // Unmangle '\t', '\n', ' ', '#', and r'\'
0 commit comments