Skip to content

dir: implement it - #249

Open
metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:dir-implementation
Open

metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:dir-implementation

Conversation

@metif12

@metif12 metif12 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

dir briefly lists directory contents, with -a, -C, -1, -R, -r, -S, -t, -w and the long -- spellings.

Listing and sorting live in common/dir; src/dir is a thin main.

-R prefixes each subdirectory with its path and separates it with a blank line, descending after its parent has been printed rather than depth-first.

Three behaviours were wrong on the first attempt and were caught by comparison rather than by reading: the default layout is columns separated by two spaces, not one line per entry; -a has to synthesise the . and .. entries because os.ls omits them; and a path that cannot be accessed exits 2 rather than 1. All three are pinned by tests.

A control run confirms the suite has teeth: breaking the column separator from two spaces to one turns test_default_is_columns_not_one_per_line, test_all_includes_dot_entries and test_reverse red.

One deliberate divergence, and the reason it is worth a reviewer's attention. GNU and uutils disagree about -S. On a tree of two 2-byte files and a directory, GNU orders sub one.txt two.txt — directories first, because a directory reports a larger size — while uutils on Windows orders one.txt two.txt sub. Both were measured on the same tree, GNU through WSL. This port follows GNU and test_size_sort_puts_directories_first pins that order with the disagreement written into the test.

Multi-column wrapping when the names do not fit the line width is not implemented; the single-line case is what the reference and the tests cover.

Briefly lists directory contents, with -a, -C, -1, -R, -r, -S, -t, -w and the long -- spellings. Listing and sorting live in common/dir; src/dir is a thin main. -R prefixes each subdirectory with its path and separates it with a blank line, and it descends after its parent has been printed rather than depth-first. Three behaviours were wrong on the first attempt and were caught by comparison rather than by reading: the default layout is columns separated by two spaces, not one line per entry; -a has to synthesise the . and .. entries because os.ls omits them; and a path that cannot be accessed exits 2 rather than 1. -S is the one case where this port deliberately does not match uutils. GNU puts directories first when sorting by size because a directory reports a larger size than a two-byte file; uutils on Windows puts them last. Both were measured on the same tree, GNU through WSL, and GNU is the authority, so the suite pins GNU's order. Multi-column wrapping when the names do not fit the line width is not implemented, and the trailing-space case is pinned by a test.
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