From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id YH4/N8hx1WagGwEA62LTzQ:P1 (envelope-from ) for ; Mon, 02 Sep 2024 08:05:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id YH4/N8hx1WagGwEA62LTzQ (envelope-from ) for ; Mon, 02 Sep 2024 10:05:29 +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=Xvboj9b1; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=PF76Bl84; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1725264328; 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=nEYaUZy9tsjYdhBy+AjBU1Oho61zmZdIA4qR9HbxnZI=; b=OwIOOc8rsZarrY0axkB4tS9T1/CE3Uc/nsOHf72X1d3peHWryrlfW9QP4yA/7TdooZ333R TmIMZVQk27hdY27qoszM97jU/Bcq+qPhJJq4DhANugvPM8RtKCOQKjws8rf1cc8jV9kcpD HIUVnD4waNy7JS9E4WGkWY7FB1m9meFtfhBMi7gTeygZJnvJJEZsrpchzm6qkdhvp8h3Yn qyyi6l5Pp/u9KSObD8YPwKgen+a7nzMPfqm0v/6BWwFTcSB2GFEhOxMVQ55ffmwF1Z65t4 mbxcukFQTsvGFHRNcoSrpqt9ADGbHzQquybdr1W+jkVoT35SH6h81EyPSk/Wug== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1725264328; a=rsa-sha256; cv=none; b=QwiupYFv20QHD3pwz0M8EsI6k0kvYSx/Jukx4oP/v2w80wXoiJ/eCoXSVokrQoxBlUzJJm PJ/nmMMoLXzecGe6EUIwKYiYRibfNPyL2M1HcmxGTAjkpXdFpS0DRCVchUCUaNeCSLsfLx VFlU33AVvC+ZNco+C3WVyUQEgfv6FlqKBnbLtqCpCUp9N8hoRHNdljsXJT75x+A6MpHJXD o31baxnVT10PKNdNPWaWXNrNkkRuOg+ohjM8rZkK0Z/65Q1WNVycuWvmnjnotzxo/fbcdk 3DMMj8aoKrKGPtOyjFA5Oeinlya/WQpLov80yh8TXlRW/e74eyKojRwYMmO5gA== 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=Xvboj9b1; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20230601 header.b=PF76Bl84; 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" 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 726AE7372F for ; Mon, 2 Sep 2024 10:05:27 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sl23d-0006yv-TM; Mon, 02 Sep 2024 04:05:06 -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 1sl23b-0006yZ-3q for guix-patches@gnu.org; Mon, 02 Sep 2024 04:05:03 -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 1sl23a-0000Vi-Ly; Mon, 02 Sep 2024 04:05:02 -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=ao860WMWNrVRDzs/GEQFsN8DTsCi/x7LOg2QxgAv34M=; b=Xvboj9b1GtyiRFvs4K9AQ7cNE39TRf70UDM/Sklnjl2Qk7YaDgSlSrnJ5eC7nGzKP8SwSvPGySVM7hOa83FZbRthfxTS+jnNQ7Xkbyi+neXPEz+WhkKRatMam3RCDhntzbPhmR/zR0YIo87P6CDH55hShFktRaBWZaV1VyIl/jDQfaWATvhzp85QVmtVldJcDMUdsjwtrNZlJ70sFiQdrtBGcMxn10isrVXISGXcCkKN5GAYESbhpV+TiaujUiUAlk+NVtcCPUjpX1IHxr5owENUH1ixxaPfqhI47SGp6BflvGooRj0JgOBqwPffvP1I6JIMDrog/I5GcBp0Fc78nQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sl24X-0005U3-Pu; Mon, 02 Sep 2024 04:06:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72867] [PATCH v3] 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 08:06:01 +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.172526431420956 (code B ref 72867); Mon, 02 Sep 2024 08:06:01 +0000 Received: (at 72867) by debbugs.gnu.org; 2 Sep 2024 08:05:14 +0000 Received: from localhost ([127.0.0.1]:43619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sl23m-0005Ru-7g for submit@debbugs.gnu.org; Mon, 02 Sep 2024 04:05:14 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:61487) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sl23k-0005Rb-FK for 72867@debbugs.gnu.org; Mon, 02 Sep 2024 04:05:13 -0400 Received: by mail-ed1-f66.google.com with SMTP id 4fb4d7f45d1cf-5c24c92f699so1482584a12.2 for <72867@debbugs.gnu.org>; Mon, 02 Sep 2024 01:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725264185; x=1725868985; 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=ao860WMWNrVRDzs/GEQFsN8DTsCi/x7LOg2QxgAv34M=; b=PF76Bl84BS/xzj4ckQsFyi69PBZGj6m7bBwF7ZCI9JpQQOtCBXji24CGOjP7OOKbSr Ba3OhvBGwOeg3Ua3OVgQxxIcTvIz+6yaz18d+SNJ89SAQ/9l+WKt1J2BO40B75L96kRT NfpjlxcUD6OXwSef5K72Ix6sNOVRnjTitrCrJFiKR+JrlGysKxjkaop5nDkMbW6AUQtW z0EdeqhQr92oTTR2J5AynXonr/LWYpF1dkTJTtjgIogYEEiVkZKvjQRtEcBXl++3iotO NPpt9wO2kUfEylzSXA0Ad+2dQXbCFnGPD4A9KjPgoPGrDf14EPDBye57RYtl9ARLCHww UFxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725264185; x=1725868985; 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=ao860WMWNrVRDzs/GEQFsN8DTsCi/x7LOg2QxgAv34M=; b=QXSP9oK5mjyI3zhZ/TqphjP8+w/Aphu6qkJ5IVy//Gu0bKlCXg67ZPcFWtT6EBmWdX 4IVplR7/RfhVb1oTbwSlFCfH1EgKy0Fa2FBlBginSBurp8C5X8oPt11ipWTKzfijCINX tMIV0PRRZkx/qm/4wFT9KdRQcopZZ1/GzRTuSIqXK4KBAJqZpAPMP8mpPkeyL0tw2Rgb tUpYM8UXH1c8+0ne8YGO6dvhKX8TTbqzrO4VXu5pGHxT3VqBipNiBotubxSFtWuN8OUF ODd4VRmNIRjoDblHLoNL9VmU0Uv7SveikGa99OYtinySFPgfZUuUU2Pj1IPquZlblp2p /4jw== X-Gm-Message-State: AOJu0YxXApWFFLdnsVxQNGvEKWtdWNMn7npOtL17/Ve403YoHmboXR7p 623nqkh4N0BxtzUr6doMJ0zFEuU26DJr4S6jIKK9xU6Aj94xZcxIYshOE9yu X-Google-Smtp-Source: AGHT+IGrt++f3j5Ia5OBtlBMSP1+FozFwD/+zpqLYwLAtuWboPQ+2zKO7do7tlOAvbK4/YTYJhQUXA== X-Received: by 2002:a05:6512:3e26:b0:533:43bf:565d with SMTP id 2adb3069b0e04-53546b45292mr6688625e87.27.1725263817977; Mon, 02 Sep 2024 00:56:57 -0700 (PDT) Received: from localhost.localdomain ([188.68.137.106]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5354084b61fsm1526326e87.239.2024.09.02.00.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 00:56:57 -0700 (PDT) From: Nigko Yerden Date: Mon, 2 Sep 2024 12:53:32 +0500 Message-ID: <2d4b593eaea4fed1fb08031a599aaab032442041.1725263612.git.nigko.yerden@gmail.com> 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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 726AE7372F X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -3.38 X-Spam-Score: -3.38 X-TUID: IDw/rOXruIxt 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 --- Forgot to unwrap #'follow-symlinks? syntax object with 'syntax->datum' when calling 'source-directory' inside 'current-source-directory'. guix/gexp.scm | 2 +- guix/utils.scm | 53 ++++++++++++++++++++++++++++---------------------- tests/gexp.scm | 23 ++++++++++++++++++++++ 3 files changed, 54 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..ea3d80707e 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -1110,41 +1110,48 @@ (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 (syntax->datum #'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