Skip to content

open_file(…, 'w', atomic=True) sets or resets permissions to 600, ignoring umask #1376

@andersk

Description

@andersk

Files are normally created with permission 666 & umask as expected:

>>> click.open_file('/tmp/test1', 'w').close()
>>> oct(os.stat('/tmp/test1').st_mode)
'0o100644'

However, opening a new or existing file with atomic=True sets or resets its permissions to 600 unconditionally:

>>> click.open_file('/tmp/test2', 'w', atomic=True).close()
>>> oct(os.stat('/tmp/test2').st_mode)
'0o100600'
>>> click.open_file('/tmp/test1', 'w', atomic=True).close()
>>> oct(os.stat('/tmp/test1').st_mode)
'0o100600'

I’d expect a new file created with atomic=True to be created with the usual permission 666 & umask, and an existing file opened with atomic=True to have the previous permissions preserved. (There’s probably no way to preserve permissions atomically; taking the previous permissions at the time of the initial open is fine.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions