From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id EL6KCxrczWQeTwEASxT56A (envelope-from ) for ; Sat, 05 Aug 2023 07:20:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id oLC4ChrczWSCAAAAG6o9tA (envelope-from ) for ; Sat, 05 Aug 2023 07:20:26 +0200 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 B623340903 for ; Sat, 5 Aug 2023 07:20:25 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=R57gP9Wi; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1691212826; a=rsa-sha256; cv=none; b=V7QOmYHshXFCRkD6i9Mcoq2VHMpWDBf+KuAwJOj40xRMil59+03+8Hbk7fQENetjEsX3Of DxeAjTQUKlf2E9y817u0kzUvX+/t9nGXJZgp7hVk7UTXKrpMj7dd3pXagdKF2EYSUjG5fv jy6QRH97v1cElAGY5WnbVqpuWsqRaeTA0RizOkf8qh3RBLDkFDrZ55+XNV+Wo+VSNBS3Cr n0lKFzTC+wQ/oALSjsJXm70Qvi/ghyscqWvK1Kj5p1iJ8/shvD4oK4GaXvz5BXYR/vG7Cp 7OVl/o6kOhzW1jyNCPXweqNwsm8VzacB1/AEgqU9TPxmGkgYEojUiNjysvq2pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1691212826; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=OzkGdXZSrajcMpGqByjQ2jL/XxSnB1UgNcmyd6HVgsw=; b=cOoicpTFsysEfDZThrwdXD7YwKEHyO79kBeAuM3iKA1jZNenPRxzDe7hGplzAjKl1/azK6 PvFMZOKsw9qlObvrfYPs6lPZlQoSg2UKawyKOuMRqnI45HhC3zG1+Og4I1jGQH+9qGeNas ZzMiC4PODPDUIgDbrmGmRGuQ8dpImWqT99vSCrWsmZBno8Pta/amXhAnVHfPTr3h/pqsRD MLYMMZPCQ5tcOg10/UExMBGcyEmax0ONtoMLTAnzaCTylc/0CixwQqYlvkYX8MC8pPuLnQ SZOGcdWmfgsBtFJf+gul+LewKrxX0Q7asqNEoWSojn+GOznhU5Z3AicjJ+xM+w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=R57gP9Wi; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qS9h3-00051M-FQ; Sat, 05 Aug 2023 01:19: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 1qS9h2-000517-1n for emacs-orgmode@gnu.org; Sat, 05 Aug 2023 01:19:12 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qS9h0-0001K1-68 for emacs-orgmode@gnu.org; Sat, 05 Aug 2023 01:19:11 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a412653335so2103624b6e.1 for ; Fri, 04 Aug 2023 22:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691212748; x=1691817548; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OzkGdXZSrajcMpGqByjQ2jL/XxSnB1UgNcmyd6HVgsw=; b=R57gP9Wi7FsiHFEJC2Mn/0GIS/Mf1MtJguI7XflxQCJtEW+WR1nDu18N87++FUo0ir Tr1Mt3Qh0XPCFtwMJjrwEoAHacHCscXeixF34MVjSxCWwUvmjQ0LxmDXKN9j5ymi/S/r ezAusWCddeVb7TIovLHqUKZc68KbWNQxpbEpymCgc/QJPoSfDIEJh99xgKbAnJdVbqkR p4vNZB+L81xkCsviBpz7Z34YoDeNk/fi1/b/Dqipndd8TO0v3lLbvmtBKPyW4rWlhkSI jAHkeRDcpyx55B7rwKGcm4+Go21BY660rBjJhHX7uI9jdQoxBlUnUM+bfcYhiJzGrun8 84gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691212748; x=1691817548; 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=OzkGdXZSrajcMpGqByjQ2jL/XxSnB1UgNcmyd6HVgsw=; b=Cd05SjGzqqAyC4sZ2Tu/RZTjN8itCyUNFKPDzPvxhjvet6nRLXCKUnDyS0Y6YGbRNL l0Qojao6O1r/rfLuSB1nAOhLAZcGJBH2qLcGXIUKP+Z549As5lGq9Y8J8bgPwcKJYUw1 1+QKe7sBFSS07aekkYIJ5174uzDcFTT5apHoxn1sFUet4oPnMtlYP1nlwPaqEZEz20SQ ixtS2Q1ielYu2krClbcD2SA9KPl7+fvqLJJKxHIALQANbjvvQgYdCzjxMuwUhpDeNk4Q rALIWE1/TpWwLZAtvqtkShRRWNUohuaaXWZ+XBr13C6ztHfqPFbhMBgO3jNqaKPTHQtz ZLGg== X-Gm-Message-State: AOJu0YxwEBeor1GVcDpyLUAYoWwQOQm26i1B9WMyo+N+8DNslyP58JM/ bAEWFcPZwPdgGzPvgAeizjXuRsovwN/dHA== X-Google-Smtp-Source: AGHT+IE7iByZU0F6JrCS+hSyRSMMsx+9vQx+eg3SOgzPBk9rplNzfjpZr6+0JwvJEUFRLiYsrcOzdA== X-Received: by 2002:a05:6808:2223:b0:3a7:44f2:4570 with SMTP id bd35-20020a056808222300b003a744f24570mr5742476oib.42.1691212748026; Fri, 04 Aug 2023 22:19:08 -0700 (PDT) Received: from localhost (S01069050ca65e863.ed.shawcable.net. [174.3.244.184]) by smtp.gmail.com with ESMTPSA id g26-20020aa7875a000000b00682a9325ffcsm2351211pfo.5.2023.08.04.22.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 22:19:07 -0700 (PDT) From: Roshan Shariff To: emacs-orgmode@gnu.org Cc: Roshan Shariff Subject: [PATCH] org-macs: Fix incorrect use of relative paths in org-compile-file Date: Fri, 4 Aug 2023 23:18:25 -0600 Message-ID: <20230805051842.142048-1-roshan.shariff@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=roshan.shariff@gmail.com; helo=mail-oi1-x22d.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.02 X-Migadu-Scanner: mx2.migadu.com X-Migadu-Queue-Id: B623340903 X-Spam-Score: -9.02 X-TUID: rpB+N7vaNeTg * org-macs.el (org-compile-file, org-compile-file-commands): Avoid converting the source path to be relative to the default-directory, which breaks for absolute source paths when the current directory is a symlink. Commit 5a8a1d4ff [1] changed org-compile-file to use `file-relative-name` for the source argument. This was intended to fix bug [2] by expanding ~ directories in the source path, like a shell. Unfortunately, this forced use of relative paths breaks when default-directory is a symlink, and the source to be compiled has an absolute path. For example, on macOS Ventura, ~/Dropbox is a symlink to ~/Library/CloudStorage/Dropbox. Suppose `default-directory` is /Users/username/Dropbox and you try to compile /var/tmp/test.org. Its relative path is ../../../var/tmp/test.org. But the working directory of a compilation process is actually ~/Library/CloudStorage/Dropbox, relative to which the source path resolves to "/Users/username/var/tmp/test.org". The process thus cannot find the source file. This commit changes `org-compile-file` and its helper function `org-compile-file-commands` to avoid the use of relative paths. Instead, to address bug [2], `expand-file-name` is used (only on absolute paths) for ~ expansion. Otherwise, the source path is passed unchanged to the compilation command. The `file-truename` of the source directory is used to construct absolute source and output paths if needed by the command. [1] https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=5a8a1d4ff [2] https://orgmode.org/list/25528.42190.53674.62381@gargle.gargle.HOWL --- lisp/org-macs.el | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index e102f01c3..5d8f65193 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -1606,16 +1606,20 @@ filename. Otherwise, it raises an error. When PROCESS is a list of commands, optional argument LOG-BUF can be set to a buffer or a buffer name. `shell-command' then uses it for output." + (when (file-name-absolute-p source) + ;; Expand "~" and "~user" . Shell expansion will be disabled + ;; in the shell command call. + (setq source (expand-file-name source))) (let* ((commands (org-compile-file-commands source process ext spec err-msg)) - (output (expand-file-name (concat (file-name-base source) "." ext) - (file-name-directory source))) + (output (file-name-concat (file-name-directory source) + (concat (file-name-base source) "." ext))) (log-buf (and log-buf (get-buffer-create log-buf))) (time (file-attribute-modification-time (file-attributes output)))) (save-window-excursion (dolist (command commands) (cond ((functionp command) - (funcall command (shell-quote-argument (file-relative-name source)))) + (funcall command (shell-quote-argument source))) ((stringp command) (shell-command command log-buf))))) ;; Check for process failure. Output file is expected to be ;; located in the same directory as SOURCE. @@ -1658,22 +1662,33 @@ argument SPEC, as an alist following the pattern Throw an error if PROCESS does not satisfy the described patterns. The error string will be appended with ERR-MSG, when it is a string." + (when (file-name-absolute-p source) + ;; Expand "~" and "~user" . Shell expansion will be disabled + ;; in the shell command call. + (setq source (expand-file-name source))) (let* ((base-name (file-name-base source)) - (full-name (file-truename source)) - (relative-name (file-relative-name source)) - (out-dir (if (file-name-directory source) - ;; Expand "~". Shell expansion will be disabled - ;; in the shell command call. - (file-name-directory full-name) - "./")) - (output (expand-file-name (concat (file-name-base source) "." ext) out-dir)) + (out-dir (file-name-directory source)) + ;; Don't use (expand-file-name SOURCE) for the absolute path, + ;; in case SOURCE starts with ../ and default-directory is a + ;; symlink. Instead, resolve symlinks in the directory + ;; component of SOURCE... + (true-out-dir (file-truename out-dir)) + ;; but use the original file name component of SOURCE in case + ;; it is a symlink; we want %f and %F to have the same file + ;; name component: + (full-name (file-name-concat true-out-dir + (file-name-nondirectory source))) + ;; The absolute path OUTPUT is the same as FULL-NAME, except + ;; with extension EXT: + (output (file-name-concat true-out-dir + (concat base-name "." ext))) (err-msg (if (stringp err-msg) (concat ". " err-msg) ""))) (pcase process ((pred functionp) (list process)) ((pred consp) (let ((spec (append spec `((?b . ,(shell-quote-argument base-name)) - (?f . ,(shell-quote-argument relative-name)) + (?f . ,(shell-quote-argument source)) (?F . ,(shell-quote-argument full-name)) (?o . ,(shell-quote-argument out-dir)) (?O . ,(shell-quote-argument output)))))) base-commit: 73cb528c24322fef2d05142d36bc48bb9dac962e -- 2.41.0