11use std:: path:: { Path , PathBuf } ;
22
3- use anyhow:: { Context , Result , bail } ;
3+ use anyhow:: { Context , Result } ;
44use tokio:: fs;
55use yazi_fs:: { copy_and_seal, maybe_exists, remove_dir_clean} ;
66use yazi_macro:: outln;
@@ -15,44 +15,27 @@ impl Dependency {
1515 self . is_flavor = maybe_exists ( & from. join ( "flavor.toml" ) ) . await ;
1616
1717 let to = self . target ( ) ;
18- if maybe_exists ( & to) . await && self . hash != self . hash ( ) . await ? {
19- bail ! (
20- "You have modified the contents of the `{}` {}. For safety, the operation has been aborted.
21- Please manually delete it from `{}` and re-run the command." ,
22- self . name,
23- if self . is_flavor { "flavor" } else { "plugin" } ,
24- to. display( )
25- ) ;
18+ let exists = maybe_exists ( & to) . await ;
19+ if exists {
20+ self . hash_check ( ) . await ?;
2621 }
2722
2823 fs:: create_dir_all ( & to) . await ?;
29- if let Err ( e) = Self :: deploy_sources ( & from, & to, self . is_flavor ) . await {
30- remove_dir_clean ( & to) . await ;
31- return Err ( e) ;
32- }
33-
3424 self . delete_assets ( ) . await ?;
35- Self :: deploy_assets ( from. join ( "assets" ) , to. join ( "assets" ) ) . await ?;
36-
37- self . hash = self . hash ( ) . await ?;
38- outln ! ( "Done!" ) ?;
3925
40- Ok ( ( ) )
41- }
26+ let res1 = Self :: deploy_assets ( from. join ( "assets" ) , to. join ( "assets" ) ) . await ;
27+ let res2 = Self :: deploy_sources ( & from, & to, self . is_flavor ) . await ;
28+ if !exists && ( res2. is_err ( ) || res1. is_err ( ) ) {
29+ self . delete_assets ( ) . await ?;
30+ self . delete_sources ( ) . await ?;
31+ }
4232
43- async fn deploy_sources ( from : & Path , to : & Path , is_flavor : bool ) -> Result < ( ) > {
44- let files = if is_flavor {
45- & [ "flavor.toml" , "tmtheme.xml" , "README.md" , "preview.png" , "LICENSE" , "LICENSE-tmtheme" ] [ ..]
46- } else {
47- & [ "main.lua" , "README.md" , "LICENSE" ] [ ..]
48- } ;
33+ remove_dir_clean ( & to) . await ;
34+ self . hash = self . hash ( ) . await ?;
35+ res2?;
36+ res1?;
4937
50- for file in files {
51- let ( from, to) = ( from. join ( file) , to. join ( file) ) ;
52- copy_and_seal ( & from, & to)
53- . await
54- . with_context ( || format ! ( "failed to copy `{}` to `{}`" , from. display( ) , to. display( ) ) ) ?;
55- }
38+ outln ! ( "Done!" ) ?;
5639 Ok ( ( ) )
5740 }
5841
@@ -72,4 +55,20 @@ Please manually delete it from `{}` and re-run the command.",
7255 }
7356 Ok ( ( ) )
7457 }
58+
59+ async fn deploy_sources ( from : & Path , to : & Path , is_flavor : bool ) -> Result < ( ) > {
60+ let files = if is_flavor {
61+ & [ "flavor.toml" , "tmtheme.xml" , "README.md" , "preview.png" , "LICENSE" , "LICENSE-tmtheme" ] [ ..]
62+ } else {
63+ & [ "main.lua" , "README.md" , "LICENSE" ] [ ..]
64+ } ;
65+
66+ for file in files {
67+ let ( from, to) = ( from. join ( file) , to. join ( file) ) ;
68+ copy_and_seal ( & from, & to)
69+ . await
70+ . with_context ( || format ! ( "failed to copy `{}` to `{}`" , from. display( ) , to. display( ) ) ) ?;
71+ }
72+ Ok ( ( ) )
73+ }
7574}
0 commit comments