os: update mv fns, improve performance, add params struct to control overwrite behavior #20156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
rename
command that is used as first attempt by theos.mv
function, fails when the target path exists, asrename
doesn't overwrite. Then it falls back to usingmv_by_cp
which does overwrite (means the current default behavior ofmv
is to overwrite viamv_by_cp
), butmv_by_cp
is less performant.Trying to use a consistent non-overwriting behavior would result in a breaking change.
Therefore, the PR leaves overwriting on by default - equivalent to the system command
mv
, but improves it's behavior to still userename
command when possible, and by allowing to disable overwriting via a params struct.That the fallback towards overwriting by
mv_by_cp
happens quite often, becomes noticeable when disabling overwriting. E.g. CI runs:outdated
A performance example: if the target directory already exists, falling back to
os.mv_by_cp
is already less than 100% performant when just wanting to move 2 1mb files.Current master:
PR changes:
The PR also does some other changes related to the
os.mv
command as incremental refactor.🤖[deprecated] Generated by Copilot at 4cdda23
Added an
overwrite
option toos.mv
andos.mv_by_cp
functions and improved their behavior across platforms and partitions. Simplified and fixed some tools that use these functions. Updated the corresponding test function.🤖[deprecated] Generated by Copilot at 4cdda23
overwrite
parameter toos.mv
andos.mv_by_cp
functions to control whether the target should be overwritten if it exists (link,link,link)vshader
andvpm
tools, sinceos.mv
handles cross-partition and cross-platform cases consistently (link,link)vbump
tool to say 'move' instead of 'copy' (link)