From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id oIRHJTZybGNbRAEAbAwnHQ (envelope-from ) for ; Thu, 10 Nov 2022 04:38:30 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 8FyJJDZybGNWewEAG6o9tA (envelope-from ) for ; Thu, 10 Nov 2022 04:38:30 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5059FE888 for ; Thu, 10 Nov 2022 04:38:26 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osyOF-0004Vv-K7; Wed, 09 Nov 2022 22:38:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osyOC-0004Vd-5A for guix-patches@gnu.org; Wed, 09 Nov 2022 22:38:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1osyOB-0007qF-4e for guix-patches@gnu.org; Wed, 09 Nov 2022 22:38:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1osyOA-0003tm-Ft for guix-patches@gnu.org; Wed, 09 Nov 2022 22:38:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#58812] [PATCH 0/5] Add --symlink option to 'guix shell'. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 10 Nov 2022 03:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58812 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 58812@debbugs.gnu.org Received: via spool by 58812-submit@debbugs.gnu.org id=B58812.166805147614971 (code B ref 58812); Thu, 10 Nov 2022 03:38:02 +0000 Received: (at 58812) by debbugs.gnu.org; 10 Nov 2022 03:37:56 +0000 Received: from localhost ([127.0.0.1]:41536 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1osyO3-0003tP-LP for submit@debbugs.gnu.org; Wed, 09 Nov 2022 22:37:55 -0500 Received: from mail-qv1-f41.google.com ([209.85.219.41]:43758) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1osyO1-0003tC-U0 for 58812@debbugs.gnu.org; Wed, 09 Nov 2022 22:37:54 -0500 Received: by mail-qv1-f41.google.com with SMTP id c8so624495qvn.10 for <58812@debbugs.gnu.org>; Wed, 09 Nov 2022 19:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=wScroshOceDh1u4oPcLjbsF0sxENs65vlMlss7qGC+E=; b=JEBiQo+xwnULrJVmQW3pAx9N2VwumH4corCGfK+bIG4GRT6/hlzdx1hlH7k0fwM3ri s8B81a14DH1vSRrMCA6FckYSGGMdGFHNw6q+uL29KFNuGMKqf87inuXTlybHRfJA9uM9 7rInRJQKJFdfBsxSuea+Rmcu8WDj2ST387QJV4oGcdCXh2itPkCJy8RyM8BGw55eqbIc 7dpsL5/8mDSylHC6JNz98wwasJvt1/0KZ1A5lmrHAUVfQZYPyWuXqa7IZxXmwxg/DnJm TkbYGtbLItMQXquQAHEfyvq9v6jKiI6xUuZXiZo3rsKtkNNXfGJaaorclr2VyHOEBr4F QpKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wScroshOceDh1u4oPcLjbsF0sxENs65vlMlss7qGC+E=; b=tPeyw+oejjLz/INPpb49OvIytDz6CeU9Y3Fv47T3ndRPudAzBWNXrFkEc5ipz71LwR sF7PfarRNdH3V+J8kz3MEuz+dJPiYwW5sqOc70xBwcshNNvbwuZoBvrEK3kQmdVcAQrK brFnQyJv0yKUbxl2zgQlKnSeTnpo96e5HTG9Cz0sQyfoB6ezqR7wem3ESRiH3jKfRizo CgqxldcCMyNCZksYlWl9hGWIKlwIPbFuMsNxr2WhWPLxt4vSNSW3KoHsBP9XFWVgw7qZ uc6ulaxeufVQduzvlJAYEJCt2twM5aZDizLYyM0UNoBgsQWuNE2biKZlsVQQ1tbWGEB0 qxlg== X-Gm-Message-State: ACrzQf0RPu/NJV4Y8z8OM31xfzHcZbIAZXP2qsOqLYSn0+3115HBjULb Ibn33egu/ha2s4JQClyJJY8Z0XWSe6M= X-Google-Smtp-Source: AMsMyM46ZTUXDHXyn9jNKqaGr+QMK0tffTOEk+QMBe2B0o1yMH+vJAhprv9l8tb7E/Qt1wgKWA/Z6w== X-Received: by 2002:a05:6214:c27:b0:4bb:7a35:b344 with SMTP id a7-20020a0562140c2700b004bb7a35b344mr58661512qvd.29.1668051467935; Wed, 09 Nov 2022 19:37:47 -0800 (PST) Received: from hurd ([2607:fad8:4:3::1001]) by smtp.gmail.com with ESMTPSA id t12-20020a37ea0c000000b006bb82221013sm12201440qkj.0.2022.11.09.19.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 19:37:47 -0800 (PST) From: Maxim Cournoyer References: <20221027035100.28852-1-maxim.cournoyer@gmail.com> <20221027035100.28852-3-maxim.cournoyer@gmail.com> <87leojon1z.fsf_-_@gnu.org> Date: Wed, 09 Nov 2022 22:37:46 -0500 In-Reply-To: <87leojon1z.fsf_-_@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Wed, 09 Nov 2022 22:06:16 +0100") Message-ID: <877d03xywl.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1668051506; 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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=wScroshOceDh1u4oPcLjbsF0sxENs65vlMlss7qGC+E=; b=TKdBXg6eOR9N3DLgYP2HNxrk5GLI/O4zBYxSukVUu4GSITDy6aGf4Qej7WAmERUmznt0Xu hUqlP7ZNroB/mygg0Owqh1lrskiVnem0pcONP3Jg//oucRvZRgPA65vJwm45LY9ppMly6W TJRkyxKxNNy8wyFhT1zj7cKIdiKKr45Agor781ijAVPB+5Xdj07g4BL0nG0boBmVR3H7FW cGekNVH3X39Y9uTH8TN7n0aSu7Ynlq6uPIk9FMP3GAdbGnlWHvdSN6YhcB7ddsWEnOxc+x AaOUo/ACJIV2VFM6hH0KbG/tJI3O1FdmpdoFOccrhxBCPfJeJs89v2+UK1ut9w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1668051506; a=rsa-sha256; cv=none; b=bzNpLiQ6q8+82yh9grFpGb7xrs05IbnKDPx9NajIGxhXQZpXcpdqyWOJF28+sR7piyYRUr y9uhGm1mq6MyDCJMxJoBQ89hpw654/7BgloKUObmc9mu7s3QeGKGDIU5GBI1Vi4/731YC3 ZzsZN/1KatBn3ePe16SUXgNQNhLjzc8QVpiZZGtubFi/CMqjqxOyzK63oFAWDWYa0Za5wn p8MzLKgqU/CT6pJ/AMQXkY0tWJjw88pXmRrR1/VZauUpswjyMMvikeVuyyoYOr1m3GCPkc VxU/wtojHhagaQUrJdx1ET7vO1TnDnHVFcbC0okqDZdo3laDwx0c6xt2xANPQw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=JEBiQo+x; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.48 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=JEBiQo+x; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5059FE888 X-Spam-Score: 7.48 X-Migadu-Scanner: scn1.migadu.com X-TUID: fBwuKAX8OUSY Hi again, Ludovic Court=C3=A8s writes: > Maxim Cournoyer skribis: > >> * gnu/build/install.scm (evaluate-populate-directive): By default, error= when >> the target of a symlink doesn't exist. Always ensure TARGET ends with "= /". >> (populate-root-file-system): Call evaluate-populate-directive with >> #:error-on-dangling-symlink #t and add comment. > > [...] > >> + (define target* (if (string-suffix? "/" target) >> + target >> + (string-append target "/"))) > > Maybe make it: > > (let ((target (if =E2=80=A6))) > =E2=80=A6) > > so there=E2=80=99s only one =E2=80=98target=E2=80=99 in scope (and no =E2= =80=98target*=E2=80=99); otherwise it=E2=80=99s > easy to forget the =E2=80=98*=E2=80=99 and refer to wrong one. It's a pattern I've used at other places; I find it more hygienic to not shadow existing variables; it signal to the reader "be careful, this is not the same as the argument-bound one, though they are closely related". >> + (when error-on-dangling-symlink? >> + ;; When the symbolic link points to a relative pat= h, >> + ;; checking if its target exists must be done rela= tive to >> + ;; the link location. >> + (with-directory-excursion (if (string-prefix? "/" = old) >> + (getcwd) >> + (dirname new*)) ;rel= ative >> + (unless (file-exists? old) >> + (error (format #f "symlink `~a' points to none= xistent \ >> +file `~a'" new* old))))) >> + (symlink old new*)) > > I would avoid the directory excursion when unnecessary: > > (unless (if (string-prefix? "/" old) > (file-exists? old) > (with-directory-excursion (dirname new) > (file-exists? old))) > =E2=80=A6) Done: --8<---------------cut here---------------start------------->8--- modified gnu/build/install.scm @@ -99,14 +99,14 @@ (define target* (if (string-suffix? "/" target) (lambda () (when error-on-dangling-symlink? ;; When the symbolic link points to a relative path, - ;; checking if its target exists must be done relativ= e to - ;; the link location. - (with-directory-excursion (if (string-prefix? "/" old) - (getcwd) - (dirname new*)) ;relati= ve - (unless (file-exists? old) - (error (format #f "symlink `~a' points to nonexis= tent \ -file `~a'" new* old))))) + ;; checking if its target exists must be done relativ= ely + ;; to the link location. + (unless (if (string-prefix? "/" old) + (file-exists? old) + (with-directory-excursion (dirname new*) + (file-exists? old))) + (error (format #f "symlink `~a' points to nonexiste= nt \ +file `~a'" new* old)))) (symlink old new*)) --8<---------------cut here---------------end--------------->8--- > (We could use =E2=80=98lstat=E2=80=99 instead of =E2=80=98file-exists?=E2= =80=99 if we want to allow > symlinks to dangling symlinks=E2=80=A6) It seems better to leave it as-is; the odd use case of symlinking to a dangling symlink can be accomplished via "#:error-on-dangling-symlink #f" :-). --=20 Thanks, Maxim