branch: externals-release/org
commit d7b5c19daa4aece68c8ea97aa414fd4d4ec989df
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    DnD: Create directory when `org-yank-image-save-method' is a directory
    
    * lisp/org.el (org--dnd-attach-file): Make sure that target directory
    is created before copying file when `org-yank-image-save-method' is
    set to specific directory (not 'attach).
    
    Reported-by: ISouthRain <isouthr...@qq.com>
    Link: 
https://orgmode.org/list/tencent_aabb2debf7abfbc795348c288e0ebfcfd...@qq.com
---
 lisp/org.el | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1698399c42..795a4d51bb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20941,15 +20941,18 @@ SEPARATOR is the string to insert after each link."
                    ('private (or org-yank-dnd-default-attach-method
                                  org-attach-method)))))
     (if separatep
-        (funcall
-         (pcase method
-           ('cp #'copy-file)
-           ('mv #'rename-file)
-           ('ln #'add-name-to-file)
-           ('lns #'make-symbolic-link))
-         filename
-         (expand-file-name (file-name-nondirectory filename)
-                           org-yank-image-save-method))
+        (progn
+          (unless (file-directory-p org-yank-image-save-method)
+            (make-directory org-yank-image-save-method t))
+          (funcall
+           (pcase method
+             ('cp #'copy-file)
+             ('mv #'rename-file)
+             ('ln #'add-name-to-file)
+             ('lns #'make-symbolic-link))
+           filename
+           (expand-file-name (file-name-nondirectory filename)
+                             org-yank-image-save-method)))
       (org-attach-attach filename nil method))
     (insert
      (org-link-make-string

Reply via email to