Re: 'sed -i' fails if the file has sufficient perms but not its directory

Jim Meyering <[email protected]> Fri, 3 Jul 2015 15:02:48 -0700
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <CA+8g5KH+m7dMJuNYMu3PjzUD6DZf93WMXQOuieP=T4fUActoQQ@mail.gmail.com>
On Fri, Jul 3, 2015 at 11:22 AM, Toralf Förster <[email protected]> wrote:
> I tried this, which won't work :
>
> tinderbox@tor-relay ~ $ sed -i -e 's/j1/j2/g' perl-5.22/etc/portage/make.conf
> sed: couldn't open temporary file perl-5.22/etc/portage/sedw9SFZf: Permission denied
>
> whereas I'm allowed to edit that file as the user tinderbox
>
> tinderbox@tor-relay ~ $ vi perl-5.22/etc/portage/make.conf
>
> /me wonders if sed relies on having a temp copy of that file in the same dir or not.

Yes, sed -i does require write access to each directory
containing a file that it modifies.  That is necessary so that
the temporary file it creates can be renamed atomically back
onto the original, assuming all processing is successful.