Skip to content

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

Open
yunzheng wants to merge 2 commits into
mainfrom
feature/ls-tr
Open

yunzheng wants to merge 2 commits into
mainfrom
feature/ls-tr

Conversation

@yunzheng

@yunzheng yunzheng commented Feb 25, 2026 •

Copy link
Copy Markdown
Member

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
resolves #1588

@codspeed

codspeed Bot commented Feb 25, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.3

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 4 improved benchmarks
✅ 28 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_benchmark_ls_bin[cold_cache--l] 3,984.5 ms 435.5 ms ×9.1
⚡ test_benchmark_ls_bin[warm_cache--l] 3,980.9 ms 435.8 ms ×9.1
⚡ test_benchmark_ls_bin[cold_cache-] 407.1 ms 343.3 ms +18.58%
⚡ test_benchmark_ls_bin[warm_cache-] 406.9 ms 343.2 ms +18.58%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feature/ls-tr (01224b6) with main (b43db37)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (b983c57) during the generation of this report, so b43db37 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread dissect/target/tools/utils/fs.py Outdated
Comment thread dissect/target/tools/utils/fs.py Outdated
@codecov

codecov Bot commented Feb 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.30769% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.86%. Comparing base (b983c57) to head (01224b6).

Files with missing lines Patch % Lines
dissect/target/tools/utils/fs.py 81.25% 21 Missing ⚠️
dissect/target/tools/diff.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1578      +/-   ##
==========================================
+ Coverage   80.83%   80.86%   +0.02%     
==========================================
  Files         418      418              
  Lines       37167    37215      +48     
==========================================
+ Hits        30045    30094      +49     
+ Misses       7122     7121       -1     
Flag Coverage Δ
unittests 80.86% <82.30%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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

yunzheng commented Mar 10, 2026 •

Copy link
Copy Markdown
Member Author

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.

@yunzheng
yunzheng marked this pull request as ready for review April 9, 2026 16:47
@yunzheng

yunzheng commented Apr 9, 2026

Copy link
Copy Markdown
Member Author

PR open for business again.

While this PR is for adding -r (reverse sort) and -t sort by time, it does have some refactored changes to improve efficiency (see codspeed).

Short overview of the refactor to make the review a bit easier:

  • ls_scandir() function deleted
  • print_extensive_file_stat_listing() renamed to print_ls_entry() and set kwargs only
  • introduce LsEntry named tuple for readability and usability
  • test_targetcli_autocomplete: instead of Mocking, test on a real mapped directory
  • added get_ntfs_ads_ls_entries() function for NTFS alternate data streams LsEntry's
  • added file_type_from_mode() which should return most supported filetypes for LS_COLORS

@yunzheng

Copy link
Copy Markdown
Member Author

This PR now also resolves #1588 (LS_COLORS support for other file attributes)

This branch has not been deployed

No deployments
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.

LS_COLORS support for other file attributes Add sorting by time to ls command

2 participants