Repository: nushell/nushell
File: crates/nu-glob/src/lib.rs (Rust)

Code before:
                                e.path()
                                    .file_name()
                                    .expect("internal error: missing filename"),
                            )
                        } else {
                            e.path()
                        }
                    })
                })
                .collect::<Result<Vec<_>, _>>()
            });
            match dirs {
                Ok(mut children) => {
                    // FIXME: This check messes up a lot of tests for some reason
                    // if options.require_literal_leading_dot {
                    //     children.retain(|x| {
                    //         !x.file_name()
                    //             .expect("internal error: getting filename")
                    //             .to_str()
                    //             .expect("internal error: filename to_str")
                    //             .starts_with('.')
                    //     });
                    // }
                    children.sort_by(|p1, p2| {
                        if signals.interrupted() {
                            std::cmp::Ordering::Equal
                        } else {
                            p2.file_name().cmp(&p1.file_name())
                        }
                    });
                    todo.extend(children.into_iter().map(|x| Ok((x, idx))));

                    // Matching the special directory entries . and .. that
                    // refer to the current and parent directory respectively
                    // requires that the pattern has a leading dot, even if the
                    // `MatchOptions` field `require_literal_leading_dot` is not
                    // set.
                    if !pattern.tokens.is_empty() && pattern.tokens[0] == Char('.') {
                        for &special in &[".", ".."] {
                            if pattern.matches_with(special, options) {
                                add(todo, path.join(special));
                            }
                        }
                    }
                }
                Err(e) => {
                    todo.push(Err(GlobError {
                        path: path.to_path_buf(),
                        error: e,
                    }));
                }

Review comment (suggestion):
Can this `Ordering::Equal` cause any weirdness? 

I think we should check below again for `signals.interrupted` and explicitly return the error.

Code after:
                                e.path()
                                    .file_name()
                                    .expect("internal error: missing filename"),
                            )
                        } else {
                            e.path()
                        }
                    })
                })
                .collect::<Result<Vec<_>, _>>()
            });
            match dirs {
                Ok(mut children) => {
                    // FIXME: This check messes up a lot of tests for some reason
                    // if options.require_literal_leading_dot {
                    //     children.retain(|x| {
                    //         !x.file_name()
                    //             .expect("internal error: getting filename")
                    //             .to_str()
                    //             .expect("internal error: filename to_str")
                    //             .starts_with('.')
                    //     });
                    // }
                    children.sort_by(|p1, p2| p2.file_name().cmp(&p1.file_name()));
                    todo.extend(children.into_iter().map(|x| Ok((x, idx))));

                    // Matching the special directory entries . and .. that
                    // refer to the current and parent directory respectively
                    // requires that the pattern has a leading dot, even if the
                    // `MatchOptions` field `require_literal_leading_dot` is not
                    // set.
                    if !pattern.tokens.is_empty() && pattern.tokens[0] == Char('.') {
                        for &special in &[".", ".."] {
                            if pattern.matches_with(special, options) {
                                add(todo, path.join(special));
                            }
                        }
                    }
                }
                Err(e) => {
                    todo.push(Err(GlobError {
                        path: path.to_path_buf(),
                        error: e,
                    }));
                }
            }
        }
        None => {
            // not a directory, nothing more to find
        }
    }