When publishing using org-babel-tangle-publish to the same directory
that contains the org files, copy-file will signal an error, since the
source and destination files refer to the same file. So use rename-file
instead.

When publishing to a different directory, this change also cleans up the
old files, which matches the behavior of the other publishing functions
like org-html-publish-to-html.

>From c122cef65da00275e2f1a76cf74bbcb3838abea9 Mon Sep 17 00:00:00 2001
From: Antero Mejr <ant...@mailbox.org>
Date: Fri, 17 Nov 2023 16:06:53 +0000
Subject: [PATCH] Move files when using org-babel-tangle-publish

Fixes copy-file error when publishing to the current directory.
Don't leave behind the old tangled files when publishing.

* lisp/org/ob-tangle.el (org-babel-tangle-publish): Use rename-file
instead of copy-file on tangled files.
---
 lisp/org/ob-tangle.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org/ob-tangle.el b/lisp/org/ob-tangle.el
index a833037ca2b..9c8de839308 100644
--- a/lisp/org/ob-tangle.el
+++ b/lisp/org/ob-tangle.el
@@ -219,7 +219,8 @@ Return list of the tangled file names."
   (unless (file-exists-p pub-dir)
     (make-directory pub-dir t))
   (setq pub-dir (file-name-as-directory pub-dir))
-  (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
+  (mapc (lambda (el) (rename-file el pub-dir t))
+        (org-babel-tangle-file filename)))
 
 ;;;###autoload
 (defun org-babel-tangle (&optional arg target-file lang-re)
-- 
2.41.0

Reply via email to