emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-attach-attach: fix symlinks
@ 2021-11-15 13:22 Matt Price
  2022-04-30  3:32 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Price @ 2021-11-15 13:22 UTC (permalink / raw)
  To: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 596 bytes --]

I'm having trouble with org-attach-attach if my current buffer is visiting
a filepath starting with "~/". This trivial patch fixes the problem for me
by running (expand-file-name) on the file before attaching. I always use
the 'lns method, so I don't know whether it might be better to
expand-file-name before running any of the methods.

Alternatively, it might actually be better to use a *relative* file path
where possible (e.g. to ensure that project directories are fully
portable), but I'm  not sure how best to do that.

This should be a tinychange, but also I have signed FSF paperwork.

[-- Attachment #1.2: Type: text/html, Size: 716 bytes --]

[-- Attachment #2: 0001-org-attach-attach-expand-file-names-before-linking.patch --]
[-- Type: text/x-patch, Size: 1115 bytes --]

From f618fb512e62ccb2e700242a7678dacbc2b025e2 Mon Sep 17 00:00:00 2001
From: Matt Price <matt.price@utoronto.ca>
Date: Mon, 15 Nov 2021 08:14:37 -0500
Subject: [PATCH] org-attach-attach: expand file names before linking

when using symbolic links for attachments, ensure links are fully
expanded to avoid filesystem errors.
---
 lisp/org-attach.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 75db69c9c..abdce3e7a 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -523,7 +523,7 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
        ((eq method 'mv) (rename-file file attach-file))
        ((eq method 'cp) (copy-file file attach-file))
        ((eq method 'ln) (add-name-to-file file attach-file))
-       ((eq method 'lns) (make-symbolic-link file attach-file))
+       ((eq method 'lns) (make-symbolic-link (expand-file-name file) attach-file))
        ((eq method 'url) (url-copy-file file attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
-- 
2.33.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] org-attach-attach: fix symlinks
  2021-11-15 13:22 [PATCH] org-attach-attach: fix symlinks Matt Price
@ 2022-04-30  3:32 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2022-04-30  3:32 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

Matt Price <moptop99@gmail.com> writes:

> I'm having trouble with org-attach-attach if my current buffer is visiting
> a filepath starting with "~/". This trivial patch fixes the problem for me
> by running (expand-file-name) on the file before attaching. I always use
> the 'lns method, so I don't know whether it might be better to
> expand-file-name before running any of the methods.
>
> Alternatively, it might actually be better to use a *relative* file path
> where possible (e.g. to ensure that project directories are fully
> portable), but I'm  not sure how best to do that.

I do not like explicit expansion of the FILE path. It may break relative
vs. absolute path handling.

Attaching an alternative patch. It makes use of make-symbolic-link
arguments.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-attach-attach-Avoid-linking-to-path-starting-wit.patch --]
[-- Type: text/x-patch, Size: 1369 bytes --]

From ff9ccae51ce1b02fc5d95cbc60de7a44c42f28a1 Mon Sep 17 00:00:00 2001
Message-Id: <ff9ccae51ce1b02fc5d95cbc60de7a44c42f28a1.1651289455.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 30 Apr 2022 11:27:30 +0800
Subject: [PATCH] org-attach-attach: Avoid linking to path starting with ~

* lisp/org-attach.el (org-attach-attach): Auto-expand ~ in the file
patch when using symlink (`lns') attach method.

Fixes https://orgmode.org/list/CAN_Dec_LyTKgSN_kiftee9GULM7FPER5frQFant3n_2C3cwM-g@mail.gmail.com
---
 lisp/org-attach.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5ee2b84b2..760592507 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -524,7 +524,8 @@ (defun org-attach-attach (file &optional visit-dir method)
        ((eq method 'mv) (rename-file file attach-file))
        ((eq method 'cp) (copy-file file attach-file))
        ((eq method 'ln) (add-name-to-file file attach-file))
-       ((eq method 'lns) (make-symbolic-link file attach-file))
+       ;; We pass integer third argument to auto-expand "~" in FILE.
+       ((eq method 'lns) (make-symbolic-link file attach-file 1))
        ((eq method 'url) (url-copy-file file attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-30  3:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 13:22 [PATCH] org-attach-attach: fix symlinks Matt Price
2022-04-30  3:32 ` Ihor Radchenko

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).