Skip to content

fix(stdout): --depth ignores --show-apparent-size when sorting - #630

Open
VXNCXNX wants to merge 1 commit into
dundee:masterfrom
VXNCXNX:fix/depth-apparent-size-sort
Open

fix(stdout): --depth ignores --show-apparent-size when sorting#630
VXNCXNX wants to merge 1 commit into
dundee:masterfrom
VXNCXNX:fix/depth-apparent-size-sort

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

With --depth, children are sorted by disk usage even when --show-apparent-size is set, so the rows print out of order against the sizes shown next to them. A directory holding a 50M sparse file next to one with a 5M dense file:

$ gdu -np -a --depth 1 DIR

before    55.0 MiB DIR
           5.0 MiB DIR/realdir
          50.0 MiB DIR/sparsedir     <- larger, printed last

after     55.0 MiB DIR
          50.0 MiB DIR/sparsedir
           5.0 MiB DIR/realdir

showDir already picks SortByApparentSize when the flag is set, but printDirWithDepth hardcoded SortBySize. The selection now lives in a small sortSettings helper that both call, so they cannot drift again. Without -a the output is byte-identical to before, which I checked separately.

Test added in stdout_test.go; reverting the sort field fails it with "largest apparent size should be printed first". go test ./... passes, 18 packages. gofmt and vet clean.

AI disclosure: written with Claude Code. I ran the binary before and after against a sparse file and checked the mutation myself.

printDirWithDepth was hardcoding fs.SortBySize, causing children to be ordered by disk usage even when apparent sizes were displayed. Extract sort field and order selection into a shared sortSettings helper used by both showDir and printDirWithDepth.
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.04%. Comparing base (a313834) to head (4f8739c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #630   +/-   ##
=======================================
  Coverage   87.04%   87.04%           
=======================================
  Files          69       69           
  Lines        7211     7211           
=======================================
  Hits         6277     6277           
  Misses        718      718           
  Partials      216      216           

☔ 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.

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.

1 participant