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 qLriBfZT1WZo8gAAqHPOHw:P1 (envelope-from ) for ; Mon, 02 Sep 2024 05:58:14 +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 qLriBfZT1WZo8gAAqHPOHw (envelope-from ) for ; Mon, 02 Sep 2024 07:58:14 +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=TroVGaMK; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=VWNMDzuU; 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=1725256693; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=rxlkiDQ4Owtdaj8Gihw83RYKyRYRlKJlfDR61efZ+6w=; b=WYOiRFCuv/c+WsGSQtnoeLfjySMPGWII8WiNUVC/GIRIQGi3mp+zU+1WeDQk6SY48UMAUf ggmJxFVsV1ypCrOA483ApEwFEoHSfuijcrO2lqb+8fF6WucsgjAHqvjMDFPVE8v5gYrM/1 prCVXUyYgQj7cknHlhjCf5MAkNnnGZ9WC63Qtd11zCEMbc5QlFyh4liVPIQq+tPRCYohar UPHUfvQxsUxQNZ3AdW5W+gD329Zef80FqYI3PjCIXDMGbUVS4ADFzNIog+1QF39vo3e3pv X41ESpRFKEka52533+/sp9nzI0N3JiIEVnRShm7u54cq7rKXCsoEZalaBMyJGg== 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=TroVGaMK; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=VWNMDzuU; 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=1725256693; a=rsa-sha256; cv=none; b=I/ed6VmqJ3HWZmpWk16fG8NFGXfJiHjAcnUaKksMIC8fRmaK3F0AbZc9VN3+YWuuROwWnm ONZp/qptEub6bP6ngADvAsMdGhC+1eJ0E7SxZxaOU1oFlkFNJi4ZIWPC+8Nn7feOF7sp/y EkRgNWW/UAmyhR/0jxM5R2GGocOH9KvP9vTbOuyue33EeJWN5BlR6XdVzkVjrkLdw2R92y oPjHpKhIbm46WQkpdyNjLmr73abslL/ScBWRtJWrzlSdPrS8x3Bh+pL9PMtAheiLdK23mi /3VefG1iWLHr9NM8qUqdMZNRVrl5C2yxQ1s0fnpWChMyPsNeYGqL8n978aWbdQ== 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 B23333B1FB for ; Mon, 2 Sep 2024 07:58:13 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1skzYp-0005CL-7a; Mon, 02 Sep 2024 01:25:07 -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 1skzYn-0005Bl-UG for guix-patches@gnu.org; Mon, 02 Sep 2024 01:25:06 -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 1skzYm-0001mG-MO; Mon, 02 Sep 2024 01:25:04 -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:In-Reply-To:References:Subject; bh=zejtdo0J87SFBzYbjXQy5nY9TsabxKK2J2c9hZ/a8Ss=; b=TroVGaMKHHx3RlRXPq2VeYjq+a+ReBofVNb3+jRfJ3kfvBpNtT746j9HqROJd3bIs2+3pPp1Y9a/+VgqrSQ9FCJJozFPQIWvdKri57nV1ox0050xU3wsjxvHa0cO6UrycqrAn0O5LP9QrMtGqk/KtRfJkus2baRvR5v5Ua42BpBtAk9BATSLX4rSZNCxiWA5nq+ro4XWhXQAKSM4tjiLnCDKg5ryCVEl6gTydYM7M3EOcCMurxCzG+L5Moky2aCihOsbOHE7ock83iRD6CX4wi2DjtYXIuaIT7DrZsva/mZbZKQFMOeYbrL4owvl7XePbqrtdHLrJefhOJctXo1PYA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1skzZi-0005f2-GR; Mon, 02 Sep 2024 01:26:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72867] [PATCH v2] gexp: Make 'local-file' follow symlinks. References: In-Reply-To: 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: Mon, 02 Sep 2024 05:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72867 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72867@debbugs.gnu.org Cc: pelzflorian@pelzflorian.de, Nigko Yerden , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice 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 72867-submit@debbugs.gnu.org id=B72867.172525471621649 (code B ref 72867); Mon, 02 Sep 2024 05:26:02 +0000 Received: (at 72867) by debbugs.gnu.org; 2 Sep 2024 05:25:16 +0000 Received: from localhost ([127.0.0.1]:43100 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skzYx-0005d6-Rf for submit@debbugs.gnu.org; Mon, 02 Sep 2024 01:25:16 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:51495) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skyy6-0003ZO-Sd for 72867@debbugs.gnu.org; Mon, 02 Sep 2024 00:47:11 -0400 Received: by mail-lj1-f196.google.com with SMTP id 38308e7fff4ca-2f50966c469so42150111fa.3 for <72867@debbugs.gnu.org>; Sun, 01 Sep 2024 21:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725252303; x=1725857103; darn=debbugs.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=zejtdo0J87SFBzYbjXQy5nY9TsabxKK2J2c9hZ/a8Ss=; b=VWNMDzuUoWIRRmgevL9084vA2m2do/KpMvqahkY6CylKUWgoQIcmdCa5YwXjZTqbbo FsfjaIEpNqAMMMOje1uK3vocaaKTsVpGL/sOMiQsQNU0m8/YPa++oCXoMHLXLEv1XARP jTsl3mMnITg+nzcomJbLUvT79ZOhknC9lSt0RJWwKaO7CJnWHDs3bxMnhQRrr+SBzHDo +SHqaLpcWhvj3hbErHDHnljEFDi0BDyWZCjdnz7QHWb9k04BJHtBwoGhzU4CIA2kebrs 81WRTpZEbAzo1UmqggrXHWDSpeIdPmgpBLFiUkW7BHXdrTQrfqNLwxl/4Et2jw0OFzkF JKQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725252303; x=1725857103; 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=zejtdo0J87SFBzYbjXQy5nY9TsabxKK2J2c9hZ/a8Ss=; b=Sgu3MXXZjOGoyHxMObqt4mvVTX4WD3M8C60JcaLvUZy/Xd8ZuDNAvo/ahtVrH340iR ETcxXlZAYlttwZvnfaHe1BtYcB+dSTd2YbApiJUWSMM8pWZywukRN4teydUr52Zq/B6Z hd4hYJMmA6babUk0iCaVoWl9nMLm/Y+ehcC41z3/GcBLxEQ8e/YPnHi8uyvPSau+3Y2L lJvTkWVKWfzPIdEasxSO0UbaqRlJxtECShZwNHW6E2xAw9mMLeCpGiI5jXvw8ND+SpKq i5sShOXLtDgif76p7nh03eO+WeEZdxkWe9+AfoQUDexn7CJBgSkZKgvNh+zwfhef7Nvz J1Jg== X-Gm-Message-State: AOJu0Yznx9EACVrn4q3GoRPwgQLSFEXcGejrBHEMW2vRgHeMvH5ZgpE9 i5tfsQJHDsXFWludh/R1/TbOfV1V9G7Q3B8WcQPQpDo61B16kS/Vlkks+EB4 X-Google-Smtp-Source: AGHT+IFU2tt/wevjZbrLOsnDGi1MgSksByyxKIf/2zqKA0R7Y4eHnOLnaEt+bRV2eKgbIHOheF/G7w== X-Received: by 2002:a05:6512:6cc:b0:530:ae4f:337a with SMTP id 2adb3069b0e04-53546afaddamr6289499e87.3.1725252302422; Sun, 01 Sep 2024 21:45:02 -0700 (PDT) Received: from localhost.localdomain ([188.68.137.106]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-535407b8727sm1452656e87.119.2024.09.01.21.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Sep 2024 21:45:02 -0700 (PDT) From: Nigko Yerden Date: Mon, 2 Sep 2024 09:41:59 +0500 Message-ID: X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: B23333B1FB X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -3.38 X-Spam-Score: -3.38 X-TUID: yMVsBuT4wZgd 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. * tests/gexp.scm ("local-file, load through symlink"): New test. Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59 --- Hello Ludo, Florian, Add test to 'local-file'. Regards, Nigko guix/gexp.scm | 2 +- guix/utils.scm | 52 ++++++++++++++++++++++++++++---------------------- tests/gexp.scm | 23 ++++++++++++++++++++++ 3 files changed, 53 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?))))) ;;; diff --git a/tests/gexp.scm b/tests/gexp.scm index b35bfc920f..843037fa84 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -292,6 +292,29 @@ (define %extension-package (equal? (scandir (string-append dir "/tests")) '("." ".." "gexp.scm")))))) +(test-assert "local-file, load through symlink" + ;; See . + (call-with-temporary-directory + (lambda (tmp-dir) + (chdir tmp-dir) + ;; create content file + (call-with-output-file "content" + (lambda (port) (display "Hi!" port))) + ;; create code that call 'local-file' + ;; with the content file and returns its + ;; absolute file-name. An error is raised + ;; if the content file can't be found. + (call-with-output-file "code.scm" + (lambda (port) (display "\ +(use-modules (guix gexp)) +(define file (local-file \"content\" \"test-file\")) +(local-file-absolute-file-name file)" port))) + (mkdir "dir") + (chdir "dir") + (symlink "../code.scm" "link-to-code.scm") + ;; call 'local-file' through symlink + (primitive-load (string-append tmp-dir "/dir/link-to-code.scm"))))) + (test-assert "one plain file" (let* ((file (plain-file "hi" "Hello, world!")) (exp (gexp (display (ungexp file)))) base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a -- 2.45.2