Subject: Re: bug#37884: 27.0.50; Cannot write to a file in VirtualBox shared directory

From: Andreas Schwab <[email-masked]>
Date: Tue, 29 Oct 2019 10:04:01 +0100

On Okt 29 2019, Bernardo wrote:

> diff --git a/src/filelock.c b/src/filelock.c
> index ff25d6475d..046a1b014f 100644
> --- a/src/filelock.c
> +++ b/src/filelock.c
> @@ -732,6 +732,16 @@ unlock_file (Lisp_Object fn)
>    int err = current_lock_owner (0, lfname);
>    if (err == -2 && unlink (lfname) != 0 && errno != ENOENT)
>      err = errno;
> +  /* On certain filesystems the file must be writable for unlink to
> +     succeed (Bug#37784).  */
> +  if (errno == EPERM)

You need to move this check under the condition above, otherwise you may
get a false positive if unlink didn't fail or wasn't called at all.

> +    {
> +      chmod (lfname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
> +      err = 0;
> +      errno = 0;

No need to clear errno here.

> +      if (unlink (lfname) != 0 && errno != ENOENT)
> +       err = errno;
> +    }

Andreas.

-- 
Andreas Schwab, SUSE Labs, [email-masked]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."