Optimize rename_or_delete to stop retrying after EXDEV#1659
Merged
BillyONeal merged 4 commits intomicrosoft:mainfrom Apr 29, 2025
Merged
Optimize rename_or_delete to stop retrying after EXDEV#1659BillyONeal merged 4 commits intomicrosoft:mainfrom
BillyONeal merged 4 commits intomicrosoft:mainfrom
Conversation
Thomas1664
commented
Apr 20, 2025
| if (can_attempt_rename) | ||
| { | ||
| // if we are already on the same filesystem we can just rename into place | ||
| m_fs.rename_or_delete(zip_path, archive_path, ec); |
Contributor
Author
There was a problem hiding this comment.
Before #802, files were copied to the binary cache, meaning the original file in zip_path did still exist after this function ended. However, this file is gone with rename_or_delete()
BillyONeal
approved these changes
Apr 29, 2025
Member
BillyONeal
left a comment
There was a problem hiding this comment.
Thanks for the improvement!
dg0yt
reviewed
May 5, 2025
| this->remove_all(old_path, ec); | ||
| return false; | ||
| } | ||
| else if (ec == std::make_error_condition(std::errc::cross_device_link)) |
Contributor
There was a problem hiding this comment.
Only that ec was already lost at this point, due to L2041.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes microsoft/vcpkg#45130
Please note that there is already code in place to handle
std::errc::cross_device_linkfor binary caching:vcpkg-tool/src/vcpkg/binarycaching.cpp
Lines 232 to 249 in d092b51
However, copy-and-delete was only tried after calling
fs.rename_or_delete()which tries to move the file after increasing timeouts. I decided to not move the copy-and-delete behavior tofs.rename_or_delete()because the file is first copied to a temproary location inbinarycaching.cpp.Files on different filesystems can't be renamed:
Linux: https://man7.org/linux/man-pages/man2/rename.2.html
Windows seems to support moving files but not folders across devices: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefile
std::errc::cross_device_link: https://en.cppreference.com/w/cpp/error/errno_macrosStack Overflow: https://stackoverflow.com/questions/43206198/what-does-the-exdev-cross-device-link-not-permitted-error-mean