Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: mapfile and unset: Does this actually work?
- X-seq: zsh-workers 52521
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "Mark J. Reed" <markjreed@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: mapfile and unset: Does this actually work?
- Date: Sun, 4 Feb 2024 15:13:38 -0800
- Archived-at: <https://zsh.org/workers/52521>
- In-reply-to: <CAA=-s3zrbuW_oggw84EcyCFcuZTzte+X990a=usqwQ+cUv0Rxg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7ZQfwdNLPS1=Z4mWpV--Uedft3M-gSwD3Qn-3PxfK3O_A@mail.gmail.com> <CAH+w=7aVbEkov1gbFtyfrat8obZraveWA2EAjBg6rtFm6gqxJw@mail.gmail.com> <CAA=-s3zKdbqimOPos7+WLPNazLxpnLxpi9PKxigKvYPu31JWFQ@mail.gmail.com> <CAA=-s3zrbuW_oggw84EcyCFcuZTzte+X990a=usqwQ+cUv0Rxg@mail.gmail.com>
On Sun, Feb 4, 2024 at 10:04 AM Mark J. Reed <markjreed@xxxxxxxxx> wrote:
>
> I take that back. If the file is nonempty, then the file is deleted. If the file is empty, then it's not. So it seems to be an conflation of unset and empty in the mapfile logic.
Aha. In the "get" method from the gsu struct:
/* Set u.str to contents of file given by name */
if ((contents = get_contents(pm->node.nam)))
pm->u.str = contents;
else {
pm->u.str = "";
pm->node.flags |= PM_UNSET;
}
So an empty file always appears to [already] be unset, e.g.
% touch empty
% zmodload zsh/mapfile
% print ${+mapfile[empty]}
0
This in turn appears to be because get_contents() doesn't distinguish
a file it can't open from one whose contents it can't read. More
specifically, mmap() on an empty file returns -1.
The unset logic in mapfile.c is never called because the parameter is
already marked unset.
Perhaps this is more suited for the BUGS file than for an immediate repair.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author