Skip to content

Commit e2110d8

Browse files
vargazkripken
authored andcommitted
Avoid file creation/deletion races in emsdk_env.sh by using a temporary file(#307)
Fixes emscripten-core/emscripten#9090.
1 parent aa2812b commit e2110d8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

emsdk

+7-3
Original file line numberDiff line numberDiff line change
@@ -2603,13 +2603,17 @@ def main():
26032603

26042604
return 0
26052605
elif cmd == 'construct_env':
2606-
silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one.
2606+
if len(sys.argv) == 2:
2607+
outfile = EMSDK_SET_ENV
2608+
silentremove(EMSDK_SET_ENV) # Clean up old temp file up front, in case of failure later before we get to write out the new one.
2609+
else:
2610+
outfile = sys.argv[2]
26072611
tools_to_activate = currently_active_tools()
26082612
tools_to_activate = process_tool_list(tools_to_activate, log_errors=True)
26092613
env_string = construct_env(tools_to_activate, len(sys.argv) >= 3 and 'perm' in sys.argv[2])
2610-
open(EMSDK_SET_ENV, 'w').write(env_string)
2614+
open(outfile, 'w').write(env_string)
26112615
if LINUX or OSX:
2612-
os.chmod(EMSDK_SET_ENV, 0o755)
2616+
os.chmod(outfile, 0o755)
26132617
return 0
26142618
elif cmd == 'update':
26152619
update_emsdk()

emsdk_env.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# ./emsdk_env.sh
1515
#
1616
# which won't have any effect.
17-
1817
SRC="$BASH_SOURCE"
1918
if [ "$SRC" = "" ]; then
2019
SRC="$0"
@@ -23,7 +22,9 @@ CURDIR="$(pwd)"
2322
cd "$(dirname "$SRC")"
2423
unset SRC
2524

26-
./emsdk construct_env "$@"
27-
. ./emsdk_set_env.sh
25+
tmpfile=`mktemp` || exit 1
26+
./emsdk construct_env "$@" $tmpfile
27+
. $tmpfile
28+
rm -f $tmpfile
2829

2930
cd "$CURDIR"

0 commit comments

Comments
 (0)