Skip to content

Commit

Permalink
Use file system encoding for LUCI_CONTEXT env var value.
Browse files Browse the repository at this point in the history
Otherwise run_isolated.py on Windows complains:
https://chromium-swarm-dev.appspot.com/task?id=37768d5221b8ac10&show_raw=1

Also make sure write(...) restores original os.environ upon exit.

[email protected]
BUG=730878

Review-Url: https://codereview.chromium.org/2987523002
  • Loading branch information
vadimsht authored and Commit Bot committed Jul 20, 2017
1 parent 6f9c609 commit 650536b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/libs/luci_context/luci_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import logging
import os
import sys
import tempfile
import threading

Expand Down Expand Up @@ -97,6 +98,7 @@ def _initial_load():

ctx_path = os.environ.get(_ENV_KEY)
if ctx_path:
ctx_path = ctx_path.decode(sys.getfilesystemencoding())
_LOGGER.debug('Loading LUCI_CONTEXT: %r', ctx_path)
try:
with open(ctx_path, 'r') as f:
Expand Down Expand Up @@ -231,13 +233,15 @@ def write(_tmpdir=None, **section_values):
old_value = _CUR_CONTEXT
old_envvar = os.environ.get(_ENV_KEY, None)

os.environ[_ENV_KEY] = name
os.environ[_ENV_KEY] = name.encode(sys.getfilesystemencoding())
_CUR_CONTEXT = new_val
yield
finally:
_CUR_CONTEXT = old_value
if old_envvar is None:
del os.environ[_ENV_KEY]
else:
os.environ[_ENV_KEY] = old_envvar
finally:
_WRITE_LOCK.release()

Expand Down

0 comments on commit 650536b

Please sign in to comment.