From nobody Mon Apr 29 01:40:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1596558475; cv=none; d=zohomail.com; s=zohoarc; b=VPUyM3pCwkGT80sU0kHgxMnhd5gerl4SDHvw1IAPava5/o43wee5UAXqJ8B3wGrBh1BVuGvzK7IhrNvgg/3Q8MMcljrGf+7lwf7enUoBK+0LJBFIcsWe1luEhAzGO0knOaU5DN23i8uNONZKQqSuYi9Gmdetidh3Y3oEdGqVyzI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596558475; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=KeWrBqOuQSuTVE9wP99umsDEXIT1TjnOd7Oe+V3zxdc=; b=LjpBhTvtswLfivn+qzTvvDiuBtrRKkrDYnGxsF2tQCYP8fKhikMjnr4j/9DvW3kHtUz3NAVRzxXjZuaHUS1ED7OrZUPbMczw/uwEWLcM2Yvb8q1zf5a38hYW0KNbcnhCCFPQJeYeEVJ2CsMhvavH8pKNmvb20rqXu+KlGGAA0xY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 15965584747541005.0947622448356; Tue, 4 Aug 2020 09:27:54 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-pZqAiIS_N9mUS4uXroNgVQ-1; Tue, 04 Aug 2020 12:27:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 127988017FB; Tue, 4 Aug 2020 16:27:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9699F5D9CC; Tue, 4 Aug 2020 16:27:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8ADA5A35BF; Tue, 4 Aug 2020 16:27:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 074GRDHK028022 for ; Tue, 4 Aug 2020 12:27:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 055055D9CC; Tue, 4 Aug 2020 16:27:13 +0000 (UTC) Received: from ridgehead.redhat.com (unknown [10.40.193.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B56B5DA73; Tue, 4 Aug 2020 16:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596558473; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KeWrBqOuQSuTVE9wP99umsDEXIT1TjnOd7Oe+V3zxdc=; b=CkVhfAd6x0jAaQAhE286gNbFMuFWHjUCmYM82JQXPK3UXXi2xMIUqWuXaRxGvqQ5YMdHXQ bEdpm6hLxgtEVyUFsm3M4F8ToEeGgbkj0IpXBYUE4lNAX8zYHcRR+jlHqWZfNvrqf0Mtei qwnCUH0OcGQhQfKmr5dCZfA1UBoKvp8= X-MC-Unique: pZqAiIS_N9mUS4uXroNgVQ-1 From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH] scripts: Fix meson-install-symlink.py overwriting existing links Date: Tue, 4 Aug 2020 18:27:08 +0200 Message-Id: <6bb8c51baba1d90412e6e201f5e7d2b9967504cf.1596558409.git.eskultet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Erik Skultety X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 "//scripts/meson-install-symlink.py", line 15, in 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. Signed-off-by: Erik Skultety --- scripts/meson-install-symlink.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/meson-install-symlink.py b/scripts/meson-install-symli= nk.py index e38507072d..630dfc079f 100644 --- a/scripts/meson-install-symlink.py +++ b/scripts/meson-install-symlink.py @@ -2,6 +2,7 @@ =20 import os import sys +import tempfile =20 destdir =3D os.environ.get('DESTDIR', os.sep) dirname =3D sys.argv[1] @@ -12,4 +13,7 @@ workdir =3D os.path.join(destdir, dirname.strip(os.sep)) =20 os.makedirs(workdir, exist_ok=3DTrue) os.chdir(workdir) -os.symlink(target, link) + +templink =3D tempfile.mktemp(dir=3Dworkdir) +os.symlink(target, templink) +os.replace(templink, link) --=20 2.26.2