@@ -14,15 +14,7 @@ const ENV_EDITOR: &str = "EDITOR";
1414
1515pub fn _bulk_rename ( context : & mut AppContext ) -> JoshutoResult < ( ) > {
1616 const PREFIX : & str = "joshuto-" ;
17- let editor = match std:: env:: var ( ENV_EDITOR ) {
18- Ok ( s) => s,
19- Err ( _) => {
20- return Err ( JoshutoError :: new (
21- JoshutoErrorKind :: EnvVarNotPresent ,
22- format ! ( "{} environment variable not set" , ENV_EDITOR ) ,
23- ) ) ;
24- }
25- } ;
17+ let editor = std:: env:: var ( ENV_EDITOR ) ?;
2618
2719 /* generate a random file name to write to */
2820 let mut rand_str = String :: with_capacity ( PREFIX . len ( ) + 10 ) ;
@@ -36,13 +28,11 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult<()> {
3628 let mut file_path = path:: PathBuf :: from ( "/tmp" ) ;
3729 file_path. push ( rand_str) ;
3830
39- let paths = {
40- let curr_tab = context. tab_context_ref ( ) . curr_tab_ref ( ) ;
41- match curr_tab. curr_list_ref ( ) {
42- Some ( s) => s. get_selected_paths ( ) ,
43- None => vec ! [ ] ,
44- }
45- } ;
31+ let paths = context
32+ . tab_context_ref ( )
33+ . curr_tab_ref ( )
34+ . curr_list_ref ( )
35+ . map_or ( vec ! [ ] , |s| s. get_selected_paths ( ) ) ;
4636
4737 {
4838 let mut file = std:: fs:: File :: create ( & file_path) ?;
@@ -57,13 +47,14 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult<()> {
5747 let mut command = process:: Command :: new ( editor) ;
5848 command. arg ( & file_path) ;
5949
60- let time = std:: time :: SystemTime :: now ( ) ;
50+ let last_modified = std:: fs :: metadata ( & file_path ) ? . modified ( ) ? ;
6151 {
6252 let mut handle = command. spawn ( ) ?;
6353 handle. wait ( ) ?;
6454 }
55+ // check if the file was modified since it was created
6556 let metadata = std:: fs:: metadata ( & file_path) ?;
66- if time >= metadata. modified ( ) ? {
57+ if metadata. modified ( ) ? <= last_modified {
6758 return Ok ( ( ) ) ;
6859 }
6960
0 commit comments