Subject: bug#48978: 28.0.50; native-comp: Error: File error Creating file with prefix

From: Andrea Corallo <[email-masked]>
Date: Mon, 14 Jun 2021 13:04:44 +0000

Andrea Corallo via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: No Wayman <[email-masked]>
>>> Cc: [email-masked]
>>> Date: Sun, 13 Jun 2021 08:51:09 -0400
>>> 
>>> > What happens if you do the following from the shell prompt:
>>> >
>>> >   $ emacs -batch -l comp -f batch-native-compile
>>> > /usr/share/emacs/28.0.50/lisp/progmodes/etags.el
>>> 
>>> Here we get the rest of the file-error:
>>> 
>>> Debugger entered--Lisp error: (file-error 
>>> "/usr/share/emacs/28.0.50/lisp/progmodes/etags.el" "Creating file 
>>> with prefix" "Permission denied" 
>>> "/usr/share/emacs/28.0.50/lisp/progmodes/etags.elc")
>>>   signal(file-error 
>>>   ("/usr/share/emacs/28.0.50/lisp/progmodes/etags.el" "Creating 
>>>   file with prefix" "Permission denied" 
>>>   "/usr/share/emacs/28.0.50/lisp/progmodes/etags.elc"))
>>>   comp--native-compile("/usr/share/emacs/28.0.50/lisp/progmodes/etags.el")
>>>   batch-native-compile()
>>>   command-line-1(("-l" "comp" "-f" "batch-native-compile" 
>>>   "/usr/share/emacs/28.0.50/lisp/progmodes/etags.el"))
>>>   command-line()
>>>   normal-top-level()
>>> 
>>> Which is obviously a permissions error.
>>> 
>>> > Also, is /usr/share/emacs/28.0.50/lisp/progmodes writable by 
>>> > your
>>> > user?
>>>  
>>> Permissions for the directory are as follows:
>>> 
>>> drwxr-xr-x 2 root root 4.0K Jun 13 08:48 
>>> /usr/share/emacs/28.0.50/lisp/progmodes/
>>> 
>>> ^Looks like that's the problem!
>>
>> Yes, that's what I thought was happening.
>>
>>> I'm using an AUR script to install Emacs.
>>> I see now there was a recent change to that script which modifies 
>>> the permissions of directories:
>>> 
>>> https://aur.archlinux.org/cgit/aur.git/commit/?h=emacs-git&id=dca21d899ec2b1390526a300c7a617a22165dbda
>>> 
>>> Willing to bet that's the cause of the error here.
>>> I'll contact the maintainer of that installation script.
>>> Thanks for the response and sorry for the noise (though, I do 
>>> think there may be a bug with the way that file-error is being 
>>> reported).
>>
>> It isn't noise: Emacs shouldn't really try creating files in that
>> directory, not when native-compiling in the background.
>>
>> Andrea, this happens because native-compilation calls
>> byte-compilation, which then attempts to create the temporary .elc
>> file in the same directory where the .el file lives.  I show the
>> backtrace which leads to this issue below.
>>
>> Do we really need that temporary file for the purposes of
>> native-compilation, or could we disable its creation?
>
> Agree, I think we can (and should) disable its creation when
> `byte+native-compile' is non-nil.
>
>> If the latter,
>> I think we should, because in general there's no reason to assume the
>> /usr/share tree is writable by unprivileged users.
>
> Right I pushed dc4ac39b26, it should do the job.  Nick could you have a
                 ^^^
                 663fb3b774

Wasn't quick enough and had to rebase sorry :)

Andrea