diff options
author | NIIBE Yutaka <[email protected]> | 2023-04-25 23:46:45 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2023-04-25 23:46:45 +0000 |
commit | d44a473e27160a35268789e14dccd0ad55af0690 (patch) | |
tree | f269b4d3cdb429eff06fd4a7f190a86d579f93aa /lang/python/examples/howto/temp-homedir-config.py | |
parent | Post release updates (diff) | |
download | gpgme-d44a473e27160a35268789e14dccd0ad55af0690.tar.gz gpgme-d44a473e27160a35268789e14dccd0ad55af0690.zip |
doc: Fix Python example code.
* lang/python/doc/src/gpgme-python-howto.org: Fix chmod race.
* lang/python/examples/howto/export-secret-key.py: Likewise.
* lang/python/examples/howto/export-secret-keys.py: Likewise.
* lang/python/examples/howto/temp-homedir-config.py: Likewise.
--
It's not for Python 2.7.
GnuPG-bug-id: 6466
Reported-by: Hanno Böck
Co-authored-by: Ingo Klöcker
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'lang/python/examples/howto/temp-homedir-config.py')
-rwxr-xr-x | lang/python/examples/howto/temp-homedir-config.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lang/python/examples/howto/temp-homedir-config.py b/lang/python/examples/howto/temp-homedir-config.py index 897d2f9a..0a80b6d2 100755 --- a/lang/python/examples/howto/temp-homedir-config.py +++ b/lang/python/examples/howto/temp-homedir-config.py @@ -112,18 +112,18 @@ else: nh = "{0}/.{1}".format(userdir, new_homedir) +def open_0o600(path, flags): + return os.open(path, flags, mode=0o600) + if os.path.exists(nh) is True: print("The {0} directory already exists.".format(nh)) else: print("Creating the {0} directory.".format(nh)) - os.mkdir(nh) - os.chmod(nh, 0o700) - with open("{0}/{1}".format(nh, "gpg.conf"), "w") as f1: + os.mkdir(nh, 0o700) + with open("{0}/{1}".format(nh, "gpg.conf"), "w", opener=open_0o600) as f1: f1.write(gpgconf) - os.chmod("{0}/{1}".format(nh, "gpg.conf"), 0o600) - with open("{0}/{1}".format(nh, "gpg-agent.conf"), "w") as f2: + with open("{0}/{1}".format(nh, "gpg-agent.conf"), "w", opener=open_0o600) as f2: f2.write(gpgconf) - os.chmod("{0}/{1}".format(nh, "gpg-agent.conf"), 0o600) print("""You may now use the {0} directory as an alternative GPG homedir: gpg --homedir {0} |