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

Erik Skultety posted 1 patch 3 years, 9 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/310fe90f2201247d1c83dd3551544afefd534d37.1596618127.git.eskultet@redhat.com
scripts/meson-install-symlink.py | 4 ++++
1 file changed, 4 insertions(+)
[libvirt PATCH v2] scripts: Fix meson-install-symlink.py overwriting existing links
Posted by Erik Skultety 3 years, 9 months ago
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 - remove the existing link first and then try re-creating
it.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
---

This version suffers from the same problem as v1, but I didn't bother putting
that into the commit message anymore as the consensus seems to be that we don't
care.

 scripts/meson-install-symlink.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/meson-install-symlink.py b/scripts/meson-install-symlink.py
index e38507072d..d8817fb9be 100644
--- a/scripts/meson-install-symlink.py
+++ b/scripts/meson-install-symlink.py
@@ -12,4 +12,8 @@ workdir = os.path.join(destdir, dirname.strip(os.sep))
 
 os.makedirs(workdir, exist_ok=True)
 os.chdir(workdir)
+
+if os.path.exists(link):
+    os.remove(link)
+
 os.symlink(target, link)
-- 
2.26.2

Re: [libvirt PATCH v2] scripts: Fix meson-install-symlink.py overwriting existing links
Posted by Pavel Hrdina 3 years, 9 months ago
On Wed, Aug 05, 2020 at 11:06:29AM +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 - remove the existing link first and then try re-creating
> it.
> 
> Signed-off-by: Erik Skultety <eskultet@redhat.com>
> ---
> 
> This version suffers from the same problem as v1, but I didn't bother putting
> that into the commit message anymore as the consensus seems to be that we don't
> care.
> 
>  scripts/meson-install-symlink.py | 4 ++++
>  1 file changed, 4 insertions(+)

I guess this is good enough.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>