Skip to content

cp, mv: add a -progress option - #230

Merged
JalonSolov merged 4 commits into
vlang:mainfrom
metif12:feat/cp-mv-progress
Oct 6, 2026
Merged

JalonSolov merged 4 commits into
vlang:mainfrom
metif12:feat/cp-mv-progress

Conversation

@metif12

@metif12 metif12 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Implements the -progress option for both tools, off by default.

$ cp --progress -r src dst
[=============                           ] 33%
[===============================         ] 77%
[========================================] 100%

The bar is forty columns wide and shows a percentage, drawn on standard error with
a carriage return so each update overwrites the last rather than scrolling. It is
on stderr because that is where advcpmv draws, and because it keeps the tool's own
stdout clean.

The size of the source is stat'd before the first byte moves. That is what the bar
needs in order to show a percentage, and it is why --progress is slower than a
plain copy. The bar itself lives in common/progress.v so both tools share it.

Two things I hit that are worth knowing:

  • A long option with no short form is spelled with two dashes. cp -progress
    leaves it as a free argument and the copy fails; cp --progress works.
  • mv's directory move removes the source tree after copying, file by file,
    because rmdir only takes an empty directory.

cp and mv had no test files before this, so both are new. Suite: 43 passed,
3 failed, 8 skipped, of 54. The three that fail all read standard input, which is
the Windows binary mode problem in the V compiler rather than in this repository.

…output as bytes

Two regressions on main, both found by running the suite.

numfmt did not compile: number_str is called at numfmt.v:74 and :169 but not
defined anywhere. The vlang#224 merge removed the definition at :99, and the other copy
that was in the file came from a branch that is not on main, so main was left with
no definition at all. Restored the one with the GNU parity comment, which is the
one that was there before.

sort's -z test failed for a different reason than it looked. sort -z is correct:
on b\0c\nd\0e\n it writes b\0c\nd\0e\n\0, nine bytes, matching GNU. The test read the
output through os.execute, which hands the captured bytes over as a string, and the
NUL bytes do not survive that: os.execute reported six bytes with the NULs gone.
The test now captures to a file and reads it back with os.read_bytes, so the
comparison is on the real bytes.

Suite after: 41 passed, 3 failed, 8 skipped of 52. The three that fail all read
standard input, which the Windows build of this V does not put in binary mode, and
that is a change in the V compiler rather than in this repository.
csplit and join were merged as vlang#221 and vlang#222 but never marked, and od was merged
as vlang#228. The count was 76 of 109; it is 79.
GNU writes --input-range=LO-HI, and the descriptions in vlang#193 differ from that.
The flag module puts a space between the option name and its argument description,
so this gets --input-range =LO-HI rather than --input-range=LO-HI. The equals sign
is the part that carries the meaning, and the space is a limitation of the flag
module rather than something this repository can change.
Implements the feature request in vlang#174. Both tools take a --progress option, off by
default, which draws a bar on standard error while the bytes move.

The bar is a fixed forty columns wide and shows a percentage, drawn with a
carriage return so each update overwrites the last rather than scrolling. It is
on standard error because that is where advcpmv draws, and because it keeps the
tool's own standard output clean.

The size of the source is stat'd before the first byte moves, which is what the
bar needs in order to show a percentage and which is why -progress is slower
than a plain copy. The bar itself lives in common/progress.v so both tools share
it.

Two things worth recording:

- A long option with no short form is spelled with two dashes. \cp -progress\
  leaves it as a free argument and the copy fails; \cp --progress\ works.
- mv's directory move removes the source tree after copying, file by file,
  because rmdir only takes an empty directory.

Suite: 43 passed, 3 failed, 8 skipped, of 54. The two new files are cp and mv. The
three that fail all read standard input, which is the Windows binary mode
problem in the V compiler, not in this repository.
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.

2 participants