Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering of ls -t, which was backwards #1057

Merged
merged 1 commit into from
Jul 27, 2017
Merged

Conversation

ids1024
Copy link
Contributor

@ids1024 ids1024 commented Jul 25, 2017

No description provided.

@ebfe
Copy link
Contributor

ebfe commented Jul 26, 2017

Now -S is wrong?

@ids1024
Copy link
Contributor Author

ids1024 commented Jul 26, 2017

Oops; yes, I hadn't noticed that this code handles multiple kinds of sort.

@ids1024
Copy link
Contributor Author

ids1024 commented Jul 26, 2017

It should be correct now.

src/ls/ls.rs Outdated
@@ -196,6 +196,7 @@ fn sort_entries(entries: &mut Vec<PathBuf>, options: &getopts::Matches) {
.unwrap_or(std::time::UNIX_EPOCH)
});
}
entries.reverse(); // Newest first
Copy link
Collaborator

@Arcterus Arcterus Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it makes more sense to change sort_by_key above into:

entries.sort_by(|a, b| {
    get_mod_time(b, options).cmp(get_mod_time(a, options)))
});

where get_mod_time() is defined as:

fn get_mod_time(path: &PathBuf, options: &getopts::Matches) -> time::SystemTime {
    get_metadata(path, options)
        .and_then(|md| md.modified())
        .unwrap_or(std::time::UNIX_EPOCH)
}

That way we don't have to reverse the vector. Of course, you would also have to define a similar get_create_time method or something to that effect for Unix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; it seems the standard library has a neat struct for reversing sorts, so I used that.

@@ -191,9 +192,10 @@ fn sort_entries(entries: &mut Vec<PathBuf>, options: &getopts::Matches) {
entries.sort_by_key(|k| get_metadata(k, options).map(|md| md.ctime()).unwrap_or(0));
} else {
entries.sort_by_key(|k| {
get_metadata(k, options)
// Newest first
Reverse(get_metadata(k, options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even know this was a thing lmao

@Arcterus Arcterus merged commit 4a5b76f into uutils:master Jul 27, 2017
@@ -191,9 +192,10 @@ fn sort_entries(entries: &mut Vec<PathBuf>, options: &getopts::Matches) {
entries.sort_by_key(|k| get_metadata(k, options).map(|md| md.ctime()).unwrap_or(0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I may have merged this too quickly. Does this need to be reversed as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, I suppose it does.

Arcterus added a commit to Arcterus/coreutils that referenced this pull request Jul 27, 2017
cnd added a commit that referenced this pull request Jul 27, 2017
ls: fix line that was forgotten in #1057
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants