Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] fc -p allows invalid path without error



On Mon, Oct 13, 2025 at 11:35 PM J R Becker <jrbecker002@xxxxxxxxxxxxxx> wrote:
>
> zsh 5.9 (x86_64-pc-linux-gnu)
>
> Expected behavior:
> Errors immediately.
> Actual behavior:
> No error until pop/write.
>
> % fc -p /nonexistent/path/file
> % fc -P
> 2: zsh: locking failed for /nonexistent/path/file: no such file or directory
>
> The absence of immediate path validation in fc -p seems atypical compared to the behavior of most Unix utilities, which generally report an error as soon as an invalid path is provided.
> Thank you to everyone on this list for your dedication to zsh and the collective effort that has kept it reliable and well-maintained; I hope this report contributes towards that reliability. I’d appreciate a quick reply to confirm whether this issue is of interest to the team.

History files are opened and written to only when you run fc -P (or
when running a command if you have incappendhistory or similar set),
so checking its existence when running fc -p would do nothing to
guarantee the open+write would be successful, these events could be
seconds or even months apart. Eg,

% fc -p /tmp/nonexistent/file
% fc -P
zsh: failed to write history file /tmp/nonexistent/file: no such file
or directory
% fc -p /tmp/nonexistent/file
% mkdir /tmp/nonexistent
% fc -P
% fc -p /tmp/nonexistent/file # imagine a successful check is done here
% rm -r /tmp/nonexistent
removed '/tmp/nonexistent/file'
removed directory '/tmp/nonexistent'
% fc -P # this must still fail
zsh: failed to write history file /tmp/nonexistent/file: no such file
or directory


-- 
Mikael Magnusson




Messages sorted by: Reverse Date, Date, Thread, Author