Skip to content

Allow ls -tr to allow sorting by time and reverse order#1578

Draft
yunzheng wants to merge 3 commits intomainfrom
feature/ls-tr
Draft

Allow ls -tr to allow sorting by time and reverse order#1578
yunzheng wants to merge 3 commits intomainfrom
feature/ls-tr

Conversation

@yunzheng
Copy link
Member

@yunzheng yunzheng commented Feb 25, 2026

This PR allows you to sort the ls output based on time and also able to reverse the order via:

  • ls -t sort by time
  • ls -r reverse sort
  • ls -tr sort by time in reverse.

resolves #1577

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 25, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing feature/ls-tr (a6779a5) with main (54808a5)

Open in CodSpeed

Comment on lines +169 to +170
entry = target_path.get()
entry_stat = entry.lstat()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
entry = target_path.get()
entry_stat = entry.lstat()
entry_stat = target_path.lstat()

I think this works too.

Copy link
Member Author

Choose a reason for hiding this comment

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

later in the loop the lstat() and entry() is again looked up for printing the data, maybe we can just put them directly in the contents list as a tuple so we don't have to call it again.

Copy link
Member Author

Choose a reason for hiding this comment

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

I now return a DirScanEntry namedtuple with some commonly used fields. Which includes lstat(), note this means when doing a ls_scandir this is always called per entry, even if the timestamp is not used in the display.

I'm not sure if this is a big issue but otherwise we could add a boolean to the function to make this optional.

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 64.44444% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.00%. Comparing base (54808a5) to head (a6779a5).

Files with missing lines Patch % Lines
dissect/target/tools/utils/fs.py 57.89% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1578      +/-   ##
==========================================
- Coverage   81.02%   81.00%   -0.03%     
==========================================
  Files         400      400              
  Lines       34965    34985      +20     
==========================================
+ Hits        28332    28340       +8     
- Misses       6633     6645      +12     
Flag Coverage Δ
unittests 81.00% <64.44%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yunzheng yunzheng requested a review from Schamper February 25, 2026 20:59
@yunzheng yunzheng marked this pull request as draft March 10, 2026 13:14
@yunzheng
Copy link
Member Author

yunzheng commented Mar 10, 2026

I still have some outstanding changes locally and that I want to test, so i'm putting this PR in Draft until those are pushed and is in reviewable state.

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.

Add sorting by time to ls command

2 participants