From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 0AKQOHIU0GasYQEAqHPOHw:P1 (envelope-from ) for ; Thu, 29 Aug 2024 06:25:55 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 0AKQOHIU0GasYQEAqHPOHw (envelope-from ) for ; Thu, 29 Aug 2024 08:25:55 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=QJGgxncm; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=aqIz3PsA; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1724912754; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=3huhs6N00HOIM3YpYFsPeZGRj0DWNeBhtIe/yvTkrTA=; b=IABCdAS5UCVF8/kyZSFIdaBqJUUr6zLA9Cp9bpb9squA/RYd9vX3Hav8A1MXz5kPCpWy0B teTaOs3edOrOJANWCydYUzket+/d76zMCCeKTUX0Pc/rxiMx4fF1wx8PdzPyjjIfQPcr58 klIW4aMB8DOyUCnrYPDC4LpyUYt7RpAXo1CJsrwZPXHkpy/51H8qBB7vTqUukUJ0JOBNrS Ulc6IEbeIwPJyGVNjq7tHPc5C0knr61W/w+QAS871cIzBN/0+yNhYZJuTfnAuEb+VRrOzF dNmKPSRcZVlPga6WKJEgRBUchlPCX4RlOAGAbugqfbQcbLuhfdXaq+dczNduHQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=QJGgxncm; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=aqIz3PsA; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1724912754; a=rsa-sha256; cv=none; b=aWtMYcUKk/K5b9j3RZZbfJsHL2EsgHDL+Y0gr/nYA5goPiSVo743tem++1B/I97C32221T ibAigw+iuLo2GNv/LDGGQBvDAG7cOxjFweEZfChIo4CvCYQSc8mZ/b4qMEYaXKZo61o7sM gU10ULUw/L81zbg2Uou94iM/tKLfhoI/XoHkG1RxehR5t0xIaCy92+I8SDcxgxSV65pYTb 9fKLUpiP4dN4DT+FEK8Xl7TexO5rRrKOZBSHSy/8GMcbyoFjRubeetRCRT+NZ6DS86uxBl dPEOGRmtQp0ZUXm7sHdtMYvPStlGoP/RXcDUB1oQ1BlyhJorwS7WfSFVJe4p6A== 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 7F2DC659AD for ; Thu, 29 Aug 2024 08:25:54 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjYLJ-0004Wq-Lw; Thu, 29 Aug 2024 02:09:13 -0400 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 1sjYLH-0004WH-IC for guix-patches@gnu.org; Thu, 29 Aug 2024 02:09:11 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjYLH-0000Zq-76; Thu, 29 Aug 2024 02:09:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=oD0kEMycY9D3pH/lPJXrrC8i6l2fRw6j7a4EobAdJUI=; b=QJGgxncmGiogex3aPATcV7j/s+T+8CZ3B5EG4bCEB52PFgOm87Y4m4gBx/Pku/LNm8cbX4ekfq2FNQeWRD2k3Swa053CSBwjVjmUY9P9TLNDJiVrLTKwMYcgvyEOIQcT2d4/B+5BsaOMv1jimRi8Np9TaJU6d9oSb2czhd/nvLj1IGwsVxfr/Yk2FcaeNWeImG896n4ujeY+ApObSpZ4AiwL4ASdfpgOHc4BEPowkzGWClUVakZc6vCzrrtFRv3HbjpGjrh2CQ5nRvHaLhcmIyrNI7sgE8MEpBjVwaSrDQCW4vYw8Ds7UsOvRK6thbZkfwTIgmBI0jLDxOiMIbEErA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjYM5-000328-OQ; Thu, 29 Aug 2024 02:10:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks. Resent-From: Nigko Yerden Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 29 Aug 2024 06:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72867 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72867@debbugs.gnu.org Cc: Nigko Yerden , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.172491176111598 (code B ref -1); Thu, 29 Aug 2024 06:10:01 +0000 Received: (at submit) by debbugs.gnu.org; 29 Aug 2024 06:09:21 +0000 Received: from localhost ([127.0.0.1]:50151 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjYLQ-000310-Kh for submit@debbugs.gnu.org; Thu, 29 Aug 2024 02:09:21 -0400 Received: from lists.gnu.org ([209.51.188.17]:54526) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjYLP-00030s-6Z for submit@debbugs.gnu.org; Thu, 29 Aug 2024 02:09:19 -0400 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 1sjYKV-0004Sl-VV for guix-patches@gnu.org; Thu, 29 Aug 2024 02:08:23 -0400 Received: from mail-vs1-xe44.google.com ([2607:f8b0:4864:20::e44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjYKU-0000Uz-6S for guix-patches@gnu.org; Thu, 29 Aug 2024 02:08:23 -0400 Received: by mail-vs1-xe44.google.com with SMTP id ada2fe7eead31-498f08339c6so130265137.2 for ; Wed, 28 Aug 2024 23:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724911700; x=1725516500; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oD0kEMycY9D3pH/lPJXrrC8i6l2fRw6j7a4EobAdJUI=; b=aqIz3PsA1VkdLP6ZFWHhRejgJiYXB+rnYO85vishEh9p8d6fWxN2LBAynJcheXO6fS 2s6LVvguzS5deb1bXOOJ31xtaZEZ2GTftIQLfvJOKF625+TdidaU4ICTwjnv/w4xrIiI 8lAJ42CvB+yH8eZ3OKp+CRdps+qr2pjaCcG8QI107ZM2CCr/GXZaXkm2QwcZubjNIWkE IkVheoEijFO6b2Drz3bl4ArA9gxGy0vD1/ajeaC27fL7TWtNVHp7qKqrXax6I81bAcOw YwL4+bmz/+dKNImRNgFux2ctpbUtp0iB3le+lHccpziPj3Fqn82dLluAh+pQE2ZPZrWf mBVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724911700; x=1725516500; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oD0kEMycY9D3pH/lPJXrrC8i6l2fRw6j7a4EobAdJUI=; b=p04SqqEPZZ7Uk8/uca0bllTA28GkQ+lTpzjWvUOf/97Xhoyt1UvHhwHSdiW+NIxzKZ E0duUhO+bsa2bXoWAgTIKq8zGp/KJKfVLNzUrH13dQhLqeg0D2UiZ3OfoyxhwdrqMzz0 Q132QQ0cpPuJSIWa9c5NGxN0VDBxP0tLIFsAtXfvmwrP5hAjBH3Z6tNAUKQFXPXm93C+ QH4otEvViI2tWQnOAkv4qRNdNN1vFXvhHP0d2VF5OmwXajiX40ljO7hsHh5+nNOO4qLi bMMd4xRJT1AxAd9jsfkIGzJx2TCGM41D5tU01k/3vjx0Mihwr29VJ/J2YIoWMPSXREpS YvcQ== X-Gm-Message-State: AOJu0YxPgFKNEzsvMtI0msPPvYGyI7zke2R1Zk9LFN0tANGvovozA9cf SafXcxJ8XsvQPs53bRSSITHx2kahZ3MHSG2VafBUMZn3mlEnWIE+j1AuOOWT X-Google-Smtp-Source: AGHT+IE5c7P1Ji3sNfZWfb+PNlIL3DPR7ITieb9oBB2e4LW4ASUuQRef8hoa3V1WSKdQaDweW3gTRA== X-Received: by 2002:a05:6102:942:b0:48f:c062:75ae with SMTP id ada2fe7eead31-49a5ae57710mr2376640137.8.1724911700273; Wed, 28 Aug 2024 23:08:20 -0700 (PDT) Received: from localhost.localdomain ([212.75.155.9]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a806c2aeb0sm25683585a.44.2024.08.28.23.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 23:08:19 -0700 (PDT) From: Nigko Yerden Date: Thu, 29 Aug 2024 11:06:14 +0500 Message-ID: X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::e44; envelope-from=nigko.yerden@gmail.com; helo=mail-vs1-xe44.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 7F2DC659AD X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -1.28 X-Spam-Score: -1.28 X-TUID: 236r7a+gGsMm Fixes While the issue can be easily fixed (a one line change in 'absolute-dirname') by changing 'current-source-directory' so that it always follows symlinks, such a change may break someone else's code. Instead, this patch keeps the original behavior of 'current-source-directory' macro and adds optional 'follow-symlinks?' argument to it. This patch is the result of collective work of Florian Pelz and Nigko Yerden * guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory argument. (%guix-source-root-directory): Pass #f to 'absolute-dirname' 'follow-symlinks?' argument. (current-source-directory): Add 'follow-symlinks?' optional argument. * guix/gexp.scm (local-file): Pass #t to 'current-source-directory' 'follow-symlinks?' argument. Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59 --- guix/gexp.scm | 2 +- guix/utils.scm | 52 ++++++++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/guix/gexp.scm b/guix/gexp.scm index 74b4c49f90..5911ca4815 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -508,7 +508,7 @@ (define-syntax local-file (string? (syntax->datum #'file)) ;; FILE is a literal, so resolve it relative to the source directory. #'(%local-file file - (delay (absolute-file-name file (current-source-directory))) + (delay (absolute-file-name file (current-source-directory #t))) rest ...)) ((_ (assume-valid-file-name file) rest ...) ;; FILE is not a literal, so resolve it relative to the current diff --git a/guix/utils.scm b/guix/utils.scm index d8ce6ed886..b5fcf8cb28 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -1110,41 +1110,47 @@ (define (canonical-newline-port port) (define (%guix-source-root-directory) "Return the source root directory of the Guix found in %load-path." - (dirname (absolute-dirname "guix/packages.scm"))) + (dirname (absolute-dirname "guix/packages.scm" #f))) (define absolute-dirname ;; Memoize to avoid repeated 'stat' storms from 'search-path'. - (mlambda (file) + (mlambda (file follow-symlinks?) "Return the absolute name of the directory containing FILE, or #f upon -failure." +failure. Follow symlinks if FOLLOW-SYMLINKS? is true." (match (search-path %load-path file) (#f #f) ((? string? file) - ;; If there are relative names in %LOAD-PATH, FILE can be relative and - ;; needs to be canonicalized. - (if (string-prefix? "/" file) - (dirname file) - (canonicalize-path (dirname file))))))) + (if follow-symlinks? + (dirname (canonicalize-path file)) + ;; If there are relative names in %LOAD-PATH, FILE can be relative + ;; and needs to be canonicalized. + (if (string-prefix? "/" file) + (dirname file) + (canonicalize-path (dirname file)))))))) (define-syntax current-source-directory (lambda (s) "Return the absolute name of the current directory, or #f if it could not -be determined." +be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)." + (define (source-directory follow-symlinks?) + (match (assq 'filename (or (syntax-source s) '())) + (('filename . (? string? file-name)) + ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME + ;; can be relative. In that case, we try to find out at run time + ;; the absolute file name by looking at %LOAD-PATH; doing this at + ;; run time rather than expansion time is necessary to allow files + ;; to be moved on the file system. + (if (string-prefix? "/" file-name) + (dirname (if follow-symlinks? + (canonicalize-path file-name) + file-name)) + #`(absolute-dirname #,file-name #,follow-symlinks?))) + ((or ('filename . #f) #f) + ;; raising an error would upset Geiser users + #f))) (syntax-case s () - ((_) - (match (assq 'filename (or (syntax-source s) '())) - (('filename . (? string? file-name)) - ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME - ;; can be relative. In that case, we try to find out at run time - ;; the absolute file name by looking at %LOAD-PATH; doing this at - ;; run time rather than expansion time is necessary to allow files - ;; to be moved on the file system. - (if (string-prefix? "/" file-name) - (dirname file-name) - #`(absolute-dirname #,file-name))) - ((or ('filename . #f) #f) - ;; raising an error would upset Geiser users - #f)))))) + ((_) (source-directory #f)) + ((_ follow-symlinks?) (source-directory #'follow-symlinks?))))) ;;; base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a -- 2.45.2