Author eryksun
Recipients SilentGhost, eryksun, opensource-assist, steven.daprano
Date 2020-01-28.18:34:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580236497.55.0.831445725763.issue39468@roundup.psfhosted.org>
In-reply-to
Content
This issue is due to a bug in GNU Readline (actually GNU History). It's documented that write_history [1] returns an errno value. But the internal history_do_write [2] function in this case returns the value from a rename() system call, via the value from histfile_restore [3]. rename() returns -1 on failure, which is being mishandled here as an errno value.

Actually, write permission to the original history file isn't required. GNU History writes to a temp file and then replaces the original via rename(). Normally this just requires write access to the directory. But if the directory or target file has the immutable file attribute set, then rename() fails with errno set to EPERM (at least in Linux; maybe it's a different error in BSD or macOS).

If not for the GNU History bug, this failed call would raise a PermissionError, which is already handled. Maybe it could also write an error message to stderr that write_history failed. For example:

            def write_history():
                try:
                    readline.write_history_file(history)
                except OSError as e:
                    # bpo-19891: home directory does not exist or is not
                    # writable
                    if not (isinstance(e, (FileNotFoundError, PermissionError))
                    # bpo-39468: GNU History may return -1 as an errno value
                            or e.errno == -1):
                        raise
                    print('write_history failed: {!r}'.format(history),
                        file=sys.stderr)

I agree with Steven that the handler should not presume to modify file permissions or attributes.

[1] https://tiswww.case.edu/php/chet/readline/history.html#IDX29
[2] http://git.savannah.gnu.org/cgit/readline.git/tree/histfile.c#n630
[3] http://git.savannah.gnu.org/cgit/readline.git/tree/histfile.c#n458
History
Date User Action Args
2020-01-28 18:34:57eryksunsetrecipients: + eryksun, steven.daprano, SilentGhost, opensource-assist
2020-01-28 18:34:57eryksunsetmessageid: <1580236497.55.0.831445725763.issue39468@roundup.psfhosted.org>
2020-01-28 18:34:57eryksunlinkissue39468 messages
2020-01-28 18:34:57eryksuncreate