Avoid creating an empty netrc file in $TEMP

The code to load .netrc file copies it to a temporary file
named $TEMP/XXXXXXXXXgerrit_util/netrc before loading it
to workaround crbug.com/664664.

However, using a netrc file is deprecated (in favor of a
gitcookies file instead) so most of the time, the file is
empty. Instead of creating an empty file, load data from
/dev/null (named os.devnull).

This avoid leaving an empty file lying around (since the
temporary file is not deleted), and avoid race-conditions
on Windows when multiple processes/threads try to create
the same file.

Bug: none
Change-Id: I873b72402038ca3f0d32387353dc89b731aaa927
Reviewed-on: https://chromium-review.googlesource.com/1132998
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Ryan Tseng <hinoka@chromium.org>
changes/98/1132998/3
Sylvain Defresne 7 years ago committed by Commit Bot
parent 32e3d1e37c
commit 2b138f742b

@ -134,16 +134,17 @@ class CookiesAuthenticator(Authenticator):
def _get_netrc(cls):
# Buffer the '.netrc' path. Use an empty file if it doesn't exist.
path = cls.get_netrc_path()
content = ''
if os.path.exists(path):
st = os.stat(path)
if st.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
print >> sys.stderr, (
'WARNING: netrc file %s cannot be used because its file '
'permissions are insecure. netrc file permissions should be '
'600.' % path)
with open(path) as fd:
content = fd.read()
if not os.path.exists(path):
return netrc.netrc(os.devnull)
st = os.stat(path)
if st.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
print >> sys.stderr, (
'WARNING: netrc file %s cannot be used because its file '
'permissions are insecure. netrc file permissions should be '
'600.' % path)
with open(path) as fd:
content = fd.read()
# Load the '.netrc' file. We strip comments from it because processing them
# can trigger a bug in Windows. See crbug.com/664664.

Loading…
Cancel
Save