From patchwork Thu Aug 29 06:06:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nigko Yerden X-Patchwork-Id: 67390 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8573327BBEA; Thu, 29 Aug 2024 07:09:31 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5AB6D27BBE2 for ; Thu, 29 Aug 2024 07:09:30 +0100 (BST) 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 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches 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(-) base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a 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?))))) ;;;