[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt PATCH] scripts: Fix meson-install-symlink.py overwriting existing links

On Tue, Aug 04, 2020 at 19:48:15 +0200, Martin Kletzander wrote:
> On Tue, Aug 04, 2020 at 06:27:08PM +0200, Erik Skultety wrote:
> > By default, symlink re-creation fails if the link already exists, more
> > specifically in case of meson-install-symlink.py:
> > 
> > Traceback (most recent call last):
> >  File "/<path_to_libvirt_repo>/scripts/meson-install-symlink.py",
> >    line 15, in <module>
> >        os.symlink(target, link)
> > FileExistsError: File exists: '../default.xml' -> 'default.xml'
> > 
> > Unfortunately, Python can't mimic "ln -sf", so we have to fix this
> > differently - create a temporary name which is then going to be used
> > for the temporary link followed by a rename with the original link's
> > name.
> > Note that this solution is racy as mktemp() doesn't guarantee
> > atomicity in link creation, so theoretically another process could come
> > and create a file with the same name as the temporary link name, but
> > a proper solution would be longer and not as elegant.
> > 
> Well, you could do subprocess.check_output(['ln', '-sf', ...]) (yuck), but it
> does essentially the same thing anyway.

In that case, we should throw away python and stick to the shell script
Pavel had before. This python is just a vanity thing to have less shell
scripts, but doesn't really make much sense in this case.

> I don't think a race here would cause anything.  I would probably remove the
> file and then create the symlink and if there is something/someone else
> installing the same file than it is good that we error our because there are
> bigger issues than that.  The whole installation process should not be
> interfered with and you cannot make it atomic anyway.
> Thoughts?

I agree with deleting anything pre-existing first.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]