1- use anyhow:: { Context , Result } ;
1+ use anyhow:: { Context , Result , bail } ;
22use tokio:: fs;
33use twox_hash:: XxHash3_128 ;
44use yazi_fs:: ok_or_not_found;
@@ -22,18 +22,21 @@ impl Dependency {
2222 & [ "LICENSE" , "README.md" , "main.lua" ] [ ..]
2323 } ;
2424
25- let mut hasher = XxHash3_128 :: new ( ) ;
26- for file in files {
27- hasher . write ( file. as_bytes ( ) ) ;
28- hasher . write ( b"VpvFw9Atb7cWGOdqhZCra634CcJJRlsRl72RbZeV0vpG1\0 " ) ;
29- hasher . write ( & ok_or_not_found ( fs:: read ( dir. join ( file) ) . await ) ?) ;
25+ let mut h = XxHash3_128 :: new ( ) ;
26+ for & file in files {
27+ h . write ( file. as_bytes ( ) ) ;
28+ h . write ( b"VpvFw9Atb7cWGOdqhZCra634CcJJRlsRl72RbZeV0vpG1\0 " ) ;
29+ h . write ( & ok_or_not_found ( fs:: read ( dir. join ( file) ) . await ) ?) ;
3030 }
3131
3232 let mut assets = vec ! [ ] ;
3333 match fs:: read_dir ( dir. join ( "assets" ) ) . await {
3434 Ok ( mut it) => {
3535 while let Some ( entry) = it. next_entry ( ) . await ? {
36- assets. push ( ( entry. file_name ( ) , fs:: read ( entry. path ( ) ) . await ?) ) ;
36+ let Ok ( name) = entry. file_name ( ) . into_string ( ) else {
37+ bail ! ( "asset path is not valid UTF-8: {}" , entry. path( ) . display( ) ) ;
38+ } ;
39+ assets. push ( ( name, fs:: read ( entry. path ( ) ) . await ?) ) ;
3740 }
3841 }
3942 Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => { }
@@ -42,11 +45,11 @@ impl Dependency {
4245
4346 assets. sort_unstable_by ( |( a, _) , ( b, _) | a. cmp ( b) ) ;
4447 for ( name, data) in assets {
45- hasher . write ( name. as_encoded_bytes ( ) ) ;
46- hasher . write ( b"pQU2in0xcsu97Y77Nuq2LnT8mczMlFj22idcYRmMrglqU\0 " ) ;
47- hasher . write ( & data) ;
48+ h . write ( name. as_bytes ( ) ) ;
49+ h . write ( b"pQU2in0xcsu97Y77Nuq2LnT8mczMlFj22idcYRmMrglqU\0 " ) ;
50+ h . write ( & data) ;
4851 }
4952
50- Ok ( format ! ( "{:x}" , hasher . finish_128( ) ) )
53+ Ok ( format ! ( "{:x}" , h . finish_128( ) ) )
5154 }
5255}
0 commit comments