mv: add --exchange to atomically swap two paths#13215
Conversation
Should make test tests/mv/mv-exchange.sh pass
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 4.62%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | mv_force_overwrite |
62.8 ms | 66 ms | -4.87% |
| ❌ | Simulation | sort_ascii_c_locale |
16 ms | 16.7 ms | -4.67% |
| ❌ | Simulation | sort_ascii_utf8_locale |
15.4 ms | 16.1 ms | -4.65% |
| ❌ | Simulation | mv_single_file |
62.6 ms | 65.4 ms | -4.28% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing sylvestre:mv-exchange (df4ba34) with main (b76d615)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
| fn test_mv_exchange_wrong_operand_count() { | ||
| let scene = TestScenario::new(util_name!()); | ||
| scene.fixtures.write("only", "x"); | ||
|
|
||
| // A single operand is rejected. | ||
| scene | ||
| .ucmd() | ||
| .arg("--exchange") | ||
| .arg("only") | ||
| .fails() | ||
| .code_is(1); | ||
|
|
||
| // Three operands are rejected too. | ||
| scene.fixtures.write("two", "y"); | ||
| scene.fixtures.write("three", "z"); | ||
| scene | ||
| .ucmd() | ||
| .arg("--exchange") | ||
| .arg("only") | ||
| .arg("two") | ||
| .arg("three") | ||
| .fails() | ||
| .code_is(1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_mv_exchange_missing_target() { |
There was a problem hiding this comment.
I would also check for the error messages. Currently the two tests pass even without the changes you did to mv.rs
There was a problem hiding this comment.
I would also test the scenario where source and target are the same file.
There was a problem hiding this comment.
GNU mv also supports a use case with more than two operands:
$ touch a b c
$ mkdir myfolder
$ touch myfolder/a myfolder/b myfolder/c
$ mv --exchange -v a b c myfolder/
exchanged 'a' <-> 'myfolder/a'
exchanged 'b' <-> 'myfolder/b'
exchanged 'c' <-> 'myfolder/c'
Should make test tests/mv/mv-exchange.sh pass