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

Re: Any way to allow clobbering empty files when noclobber is set?



On Thu, Jun 4, 2020 at 5:16 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> One thing I missed is that we already open the file and run fstat to
> check if it's regular.  We can simply check if it's empty at the
> same point

Exactly where my earlier question came from.

> +           if (isset(CLOBBEREMPTY) && buf.st_size == 0)
> +           {
> +               close(fd);
> +               return open(ufname, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY,
> +                           0666);
> +           }

Considering the concurrent-openers situation that Roman mentioned, I'm
debating whether there is any benefit to doing:

  int newfd = open(ufname, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
  close(fd);
  return newfd;

I have a vague sense that keeping the descriptor open until the new
file is created might prevent some races, but I can't recite an
example.



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