From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 aDN8C0wur2TcVQAASxT56A (envelope-from ) for ; Thu, 13 Jul 2023 00:50:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id SIZ2C0wur2T8RQEAauVa8A (envelope-from ) for ; Thu, 13 Jul 2023 00:50:52 +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 9489238F97 for ; Thu, 13 Jul 2023 00:50:51 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=RuNEsyGw; dmarc=pass (policy=quarantine) header.from=lipklim.org; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1689202252; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ABseU1MVh4RvqqMmK+DZvMTq5y6Fg6FJXKIpnCjbbgs=; b=sEhmMaH2tcLSh3b7KB8/VKOT8YspoSzDdzzrlkfJxHIcAQauNqkeNSkWeL/T7YMeCh0EcN KN8q7eAcdjs0q/ihb3mvemqiTF9WJCuBRihqxC/cksTe7Bnx1SVeNkprlIEDCOSQhJjgL1 NEjoKJ3naR2JF/XRiAHaKgsBDZZ+4xa+LqsFWGnSOScyVCn3kRjpVwHaFZE3/TrlRUVr7e ND4yVl0eS61O8RhD9y1zyUTW+YZQfE2yZnk1duEvaF3vm7VrPLG0Ui/3xeU1PqEusKpTOF RwZso67rJXLBrEwEu1l55yphbA688voLs4cITq5pvhkfScpybm9iMKagd2kPAQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lipklim.org header.s=key1 header.b=RuNEsyGw; dmarc=pass (policy=quarantine) header.from=lipklim.org; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1689202252; a=rsa-sha256; cv=none; b=pP7rTmNXHjhUuup8hcUilwcsdimouMgKH+eT+tbpMn2MWvQ4xz2dK5bp8RWQGBcc+JUVdd OvKn8fR3PNpYLNZ1y3EDyE5Hj5NX3WGYo2tWnjkYsOOxilDiPflKr0jx7PfE7+i6R/ktwH 4pizPyf1w1C2GNjG6K668bbHcGjrwrcmpYiiYN1fLO2c1kkw10LdBxhvSwty8aI/lOvASE kxd0aii8UE1Hfpaq5A3Znh6lp2Qus4mV662pzS0E/hT22fxp8sDd8A/gID5OwWQ7VJ8PpV zT3N8zWO/BhHXDcejpKNqeWpy7pS9vl1uNC8mZ/yqfJ5BPthYYxkkKdUDd3s7A== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJieq-0003dR-Qw; Wed, 12 Jul 2023 18:50:04 -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 1qJiep-0003dJ-OX for emacs-orgmode@gnu.org; Wed, 12 Jul 2023 18:50:03 -0400 Received: from out-27.mta0.migadu.com ([91.218.175.27]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qJiej-0002nl-Pw for emacs-orgmode@gnu.org; Wed, 12 Jul 2023 18:50:03 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lipklim.org; s=key1; t=1689202194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=ABseU1MVh4RvqqMmK+DZvMTq5y6Fg6FJXKIpnCjbbgs=; b=RuNEsyGwIo8//RO1nwMG6HAscAlmujtnXMeCQukuM0cN1Nkw5INIMdgfWd9fKmfaTFCFgv ZaGRRyTT263ylL1UZArirUiLy+8o93W5zMT4QxnCyp/6b+2O/QS4LgvT9XSfJX6Dv/9+6t yG0i2piAEV/kdvRUV5u0QeGQrgoXk8A= From: Evgenii Klimov To: emacs-orgmode Subject: [BUG] ob-tangle.el: Blocks overwrite each other when grouping before tangling Date: Wed, 12 Jul 2023 21:59:01 +0100 Message-ID: <87lefkd9tb.fsf@lipklim.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=91.218.175.27; envelope-from=eugene.dev@lipklim.org; helo=out-27.mta0.migadu.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, 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: 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 9489238F97 X-Migadu-Scanner: mx2.migadu.com X-Migadu-Spam-Score: -9.46 X-Spam-Score: -9.46 X-TUID: TX8469yMcyId --=-=-= Content-Type: text/plain Hi, I noticed that during grouping of blocks to tangle some of them can overwrite each other if they have the same target file, but in different format (relative vs absolute). Consider this example (part of example.org file in the attachment): * 1st explicit :tangle yes #+begin_src emacs-lisp :tangle yes "1st explicit :tangle yes" #+end_src * 1st implicit default #+begin_src emacs-lisp "1st implicit :tangle no" #+end_src If we call `org-babel-tangle-file' with target-file arg equal to "/path/to/example.el" (e.g. `org-babel-load-file' does that), then target file name for the first block will be "example.el" and "/path/to/example.el" for the second block. It appears to be crucial in `org-babel-tangle-collect-blocks' [1]: ;; `org-babel-map-src-blocks' runs this part on each source block (let* ((block (org-babel-tangle-single-block counter)) (src-tfile (cdr (assq :tangle (nth 4 block)))) (file-name (org-babel-effective-tangled-filename (nth 1 block) src-lang src-tfile)) (by-fn (assoc file-name blocks))) (if by-fn (setcdr by-fn (cons (cons src-lang block) (cdr by-fn))) (push (cons file-name (list (cons src-lang block))) blocks))) Current implementation of `org-babel-effective-tangled-filename' returns relative file name if :tangle is "yes" or relative FILENAME. But if :tangle happened to be absolute (as `org-babel-load-file' does), then blocks with the same file name but one name is relative while the other is absolute, will be treated as different and won't be group (see last tree lines of code above). As a result when blocks are returned to `org-babel-tangle' [2] one group will overwrite the previous one, since their absolute file names are equal. I noticed two scenarious where such things happen (e.g. if running `org-babel-tangle-file'): - if target-file arg is equal to one of :tangle FILENAMEs and some blocks don't have :tangle argument, while other have :tangle FILENAME. As a result one of these groups will be lost. - if target-file arg is equal to tangled original Org file and some blocks don't have :tangle argument, while other have :tangle "yes". As a result one of these groups will also be lost. I attach example Org file and scratch code to reproduce both scenarious. [1] [[file:lisp/ob-tangle.el::(file-name (org-babel-effective-tangled-filename][target file-name]] [2] [[file:lisp/ob-tangle.el::org-babel-tangle-collect-blocks lang-re tangle-file))][blocks return]] --=-=-= Content-Type: text/x-org Content-Disposition: attachment; filename=example.org Content-Description: example Org file * 1st explicit :tangle yes #+begin_src emacs-lisp :tangle yes "1st explicit :tangle yes" #+end_src * 1st explicit :tangle filename.el #+begin_src emacs-lisp :tangle filename.el "1st explicit :tangle filename.el" #+end_src * 1st implicit default #+begin_src emacs-lisp "1st implicit :tangle no" #+end_src * 2nd explicit :tangle yes #+begin_src emacs-lisp :tangle yes "2nd explicit :tangle yes" #+end_src * explicit :tangle no #+begin_src emacs-lisp :tangle no "explicit :tangle no" #+end_src * 2nd explicit :tangle filename.el #+begin_src emacs-lisp :tangle filename.el "2nd explicit :tangle filename.el" #+end_src * 2nd implicit default #+begin_src emacs-lisp "2nd implicit :tangle no" #+end_src --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=scratch.el Content-Transfer-Encoding: quoted-printable Content-Description: scratch code to reproduce the bug ;; -*- mode: lisp-interaction; lexical-binding: t -*- ;;; simulate `org-babel-load-file'. ;; change path to your copy of example file (let* ((org-file "/tmp/tangle-bug/example.org") (lang-re (rx string-start (or "emacs-lisp" "elisp") string-end)) (target-non-existent-file "/tmp/tangle-bug/non-existent.el") (target-filename-file "/tmp/tangle-bug/filename.el") (target-org-tangled-file "/tmp/tangle-bug/example.el")) (org-babel-tangle-file org-file ;;target-filename-file ; uncomment and comment ; next target-org-tangled-file lang-re)) --=-=-=--