pub fn possibly_update_paths(&self, command: &str, exit_code: Option<i32>) {
        let successful = exit_code.is_none() || exit_code.unwrap() == 0;
        let is_move = |c:&str| c.to_lowercase().starts_with("mv ")
            && !c.contains('*')
            && !c.contains('?');
        if successful && is_move(command) {
            let parts = path_update_helpers::parse_mv_command(command);
            if parts.len() == 2 {
                let normalized_from = path_update_helpers::normalize_path(&parts[0]);
                let normalized_to = path_update_helpers::normalize_path(&parts[1]);

                // If $to/$(base_name($from)) exists, and is a directory, assume we've moved $from into $to.
                // If not, assume we've renamed $from to $to.

                if let Some(basename) = PathBuf::from(&normalized_from).file_name() {
                    if let Some(utf8_basename) = basename.to_str() {
                        if utf8_basename.contains('.') {
                            // It was probably a file.
                            return;
                        }
                        let maybe_moved_directory = PathBuf::from(&normalized_to).join(utf8_basename);
                        if maybe_moved_directory.exists() {
                            if maybe_moved_directory.is_dir() {
                                self.update_paths(&normalized_from, maybe_moved_directory.to_str().unwrap(), false);
                            } else {
                                // The source must have been a file, so ignore it.
                            }
                            return;
                        }
                    } else {
                        // Don't try to handle non-utf8 filenames, at least for now.
                        return;
                    }
                }

                let to_pathbuf = PathBuf::from(&normalized_to);
                if to_pathbuf.exists() && to_pathbuf.is_dir() {
                    self.update_paths(&normalized_from, &normalized_to, false);
                }
            }
        }
    }
// Update historical paths in our database if a directory has been renamed or moved.
Update historical paths in our database if a directory has been renamed or moved.
Update historical paths in our database if a directory has been renamed or moved .
pub fn possibly_update_paths(&self, command: &str, exit_code: Option<i32>) {
        let successful = exit_code.is_none() || exit_code.unwrap() == 0;
        let is_move = |c:&str| c.to_lowercase().starts_with("mv ")
            && !c.contains('*')
            && !c.contains('?');
        if successful && is_move(command) {
            let parts = path_update_helpers::parse_mv_command(command);
            if parts.len() == 2 {
                let normalized_from = path_update_helpers::normalize_path(&parts[0]);
                let normalized_to = path_update_helpers::normalize_path(&parts[1]);
                // If $to/$(base_name($from)) exists, and is a directory, assume we've moved $from into $to.
                // If not, assume we've renamed $from to $to.
                if let Some(basename) = PathBuf::from(&normalized_from).file_name() {
                    if let Some(utf8_basename) = basename.to_str() {
                        if utf8_basename.contains('.') {
                            // It was probably a file.
                            return;
                        }
                        let maybe_moved_directory = PathBuf::from(&normalized_to).join(utf8_basename);
                        if maybe_moved_directory.exists() {
                            if maybe_moved_directory.is_dir() {
                                self.update_paths(&normalized_from, maybe_moved_directory.to_str().unwrap(), false);
                            } else {
                                // The source must have been a file, so ignore it.
                            }
                            return;
                        }
                    } else {
                        // Don't try to handle non-utf8 filenames, at least for now.
                        return;
                    }
                }
                let to_pathbuf = PathBuf::from(&normalized_to);
                if to_pathbuf.exists() && to_pathbuf.is_dir() {
                    self.update_paths(&normalized_from, &normalized_to, false);
                }
            }
        }
    }
pub fn possibly_update_paths ( & self , command : & str , exit_code : Option < i32 > ) { let successful = exit_code . is_none ( ) || exit_code . unwrap ( ) == 0 ; let is_move = | c : & str | c . to_lowercase ( ) . starts_with ( " " ) && ! c . contains ( '*' ) && ! c . contains ( '?' ) ; if successful && is_move ( command ) { let parts = path_update_helpers :: parse_mv_command ( command ) ; if parts . len ( ) == 2 { let normalized_from = path_update_helpers :: normalize_path ( & parts [ 0 ] ) ; let normalized_to = path_update_helpers :: normalize_path ( & parts [ 1 ] ) ; // If $to/$(base_name($from)) exists, and is a directory, assume we've moved $from into $to. // If not, assume we've renamed $from to $to. if let Some ( basename ) = PathBuf :: from ( & normalized_from ) . file_name ( ) { if let Some ( utf8_basename ) = basename . to_str ( ) { if utf8_basename . contains ( '.' ) { // It was probably a file. return ; } let maybe_moved_directory = PathBuf :: from ( & normalized_to ) . join ( utf8_basename ) ; if maybe_moved_directory . exists ( ) { if maybe_moved_directory . is_dir ( ) { self . update_paths ( & normalized_from , maybe_moved_directory . to_str ( ) . unwrap ( ) , false ) ; } else { // The source must have been a file, so ignore it. } return ; } } else { // Don't try to handle non-utf8 filenames, at least for now. return ; } } let to_pathbuf = PathBuf :: from ( & normalized_to ) ; if to_pathbuf . exists ( ) && to_pathbuf . is_dir ( ) { self . update_paths ( & normalized_from , & normalized_to , false ) ; } } } }
Update historical paths in our database if a directory has been renamed or moved.
Update historical paths in our database if a directory has been renamed or moved .
&self
command
&str
exit_code
Option<i32>
&self
command
&str
exit_code
Option<i32>