Skip to content

Fix FileExistsError on subsequent bazel builds on Windows#1326

Merged
walkingeyerobot merged 1 commit intoemscripten-core:mainfrom
NovaSagittarii:main
Dec 27, 2023
Merged

Fix FileExistsError on subsequent bazel builds on Windows#1326
walkingeyerobot merged 1 commit intoemscripten-core:mainfrom
NovaSagittarii:main

Conversation

@NovaSagittarii
Copy link
Copy Markdown
Contributor

Fixes #1181. os.rename() has different behaviors on Windows vs Linux, using os.replace() instead fixes the
issue when a new build is created when previous files exist from an older build.

I'm not sure if this is the best way to do this though since there's the method move_with_overwrite() in emsdk.py which does what os.replace() is supposed to do. Regarding atomicity, according to python documentation, os.replace()'s renaming is atomic as a POSIX requirement, but Windows isn't fully POSIX compliant.

emsdk/emsdk.py

Lines 547 to 553 in 8822664

# On windows, rename/move will fail if the destination exists, and there is no
# race-free way to do it. This method removes the destination if it exists, so
# the move always works
def move_with_overwrite(src, dest):
if os.path.exists(dest):
os.remove(dest)
os.rename(src, dest)

Copy link
Copy Markdown
Collaborator

@walkingeyerobot walkingeyerobot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks very much!

@walkingeyerobot walkingeyerobot merged commit 9347bc3 into emscripten-core:main Dec 27, 2023
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.

[BUILD FAILURE] Bazel builds are always failing! emsdk (3.1.31)

2 participants