@@ -10,6 +10,7 @@ use aes_gcm_siv::{
1010} ;
1111use anyhow:: { anyhow, Context , Result } ;
1212use colored:: Colorize ;
13+ use die_exit:: die;
1314use futures_util:: { stream:: FuturesOrdered , StreamExt } ;
1415use log:: { debug, info} ;
1516use sha3:: { Digest , Sha3_224 } ;
@@ -150,7 +151,7 @@ pub async fn encrypt_file(file: impl AsRef<Path>, repo: &Repo) -> anyhow::Result
150151 . with_context ( || format ! ( "{:?}" , file) ) ?;
151152 let ( compressed, new_file) = try_compress ( & bytes, new_file, repo. conf . zstd_level ) ?;
152153 let ( encrypted, new_file) =
153- encrypt_change_path ( repo. get_key ( ) ? . as_bytes ( ) , & compressed, new_file) ?;
154+ encrypt_change_path ( repo. get_key ( ) . as_bytes ( ) , & compressed, new_file) ?;
154155 compio:: fs:: write ( & new_file, encrypted) . await . 0 ?;
155156 compio:: fs:: remove_file ( file) . await ?;
156157 debug ! ( "Encrypted filename: {:?}" , new_file) ;
@@ -168,7 +169,7 @@ pub async fn decrypt_file(file: impl AsRef<Path>, repo: &Repo) -> anyhow::Result
168169 . await
169170 . with_context ( || format ! ( "{:?}" , file. as_ref( ) ) ) ?;
170171 let ( decrypted, new_file) =
171- try_decrypt_change_path ( repo. get_key ( ) ? . as_bytes ( ) , & bytes, new_file) ?;
172+ try_decrypt_change_path ( repo. get_key ( ) . as_bytes ( ) , & bytes, new_file) ?;
172173 let ( decompressed, new_file) = try_decompress ( & decrypted, new_file) ?;
173174 compio:: fs:: write ( & new_file, decompressed) . await . 0 ?;
174175 compio:: fs:: remove_file ( & file) . await ?;
@@ -177,7 +178,11 @@ pub async fn decrypt_file(file: impl AsRef<Path>, repo: &Repo) -> anyhow::Result
177178}
178179
179180pub async fn encrypt_repo ( repo : & Repo ) -> anyhow:: Result < ( ) > {
181+ assert ! ( !repo. get_key( ) . is_empty( ) , "Key must not be empty" ) ;
180182 let patterns = & repo. conf . crypt_list ;
183+ if patterns. is_empty ( ) {
184+ die ! ( "No file to encrypt, please exec `git-se add <FILE>` first." ) ;
185+ }
181186 repo. add_all ( ) ?;
182187 let mut encrypt_futures = repo
183188 . ls_files_absolute_with_given_patterns (
@@ -199,6 +204,7 @@ pub async fn encrypt_repo(repo: &Repo) -> anyhow::Result<()> {
199204}
200205
201206pub async fn decrypt_repo ( repo : & Repo ) -> anyhow:: Result < ( ) > {
207+ assert ! ( !repo. get_key( ) . is_empty( ) , "Key must not be empty" ) ;
202208 let dot_pattern = String :: from ( "*." ) + ENCRYPTED_EXTENSION ;
203209 let mut decrypt_futures = repo
204210 . ls_files_absolute_with_given_patterns ( & [ dot_pattern. as_str ( ) ] ) ?
0 commit comments