emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Max Nikulin <manikulin@gmail.com>
Cc: Cletip Cletip <clement020302@gmail.com>,
	Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: [BUG] Tangle with symbolic links don't work
Date: Tue, 07 Nov 2023 11:30:13 +0000	[thread overview]
Message-ID: <87leb9243e.fsf@localhost> (raw)
In-Reply-To: <e443418b-7c66-413d-86ee-cdaa0bf3042c@gmail.com>

Max Nikulin <manikulin@gmail.com> writes:

>> Max, do you see any pitfalls using `file-truename'?
>
> Sorry, I am not familiar with related code path. That is why I can not 
> reason what way to deal with file name is safer.
>
> If there is a world-writable directory in the file path (usually 
> $TMPDIR) then `file-truename' is less safe, see 
> https://www.kernel.org/doc/html/latest/admin-guide/sysctl/fs.html#protected-symlinks

Thanks!

> In general, I am never sure that Org code follows best practices in 
> respect to security in general and in respect to /tmp in particular. The 
> following citation is unrelated to /tmp, but the same proposed patch has 
> an issue with predictable name in /tmp:

We have to compromise between usability and safety... but probably not
in this case.

> Even when /tmp or similar directories are not involved, a proper 
> strategy to replace file content should be carefully chosen. E.g. cp(1) 
> preserves inode number while install(1) replaces target file atomically 
> (create a temporary one and rename). The latter way is more suitable for 
> shared libraries since it allows running application to continue call 
> function from the deleted file.

What we actually use is Elisp API. For export and tangling, we use
`write-region' - it correctly handles TRAMP files with lower-level
details taken care of.

I can now see that blindly expanding to `file-truename' may not be wise.

Without `file-truename', the difference between ox.el (that works for
Cletip) and ob-tangle.el is that ob-tangle explicitly deletes the tangle
target before tangling:

`org-babel-tangle':

                     ;; erase previous file
                     (when (file-exists-p file-name)
                       (delete-file file-name))
		     (write-region nil nil file-name)
		     (mapc (lambda (mode) (set-file-modes file-name mode)) modes)

Rather than using `file-truename', we may instead remove the
`delete-file' part. This way, we will not risk changing file modes in
the original files and always modify the symlink, if the tangle target
is an existing symlink.

> I know, it is not an answer you expected from me, but giving a better 
> one require to much efforts to read the code and to debug it.

It is exactly an answer I expected, actually :)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2023-11-07 11:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 16:08 [BUG] Tangle with symbolic links don't work Cletip Cletip
2023-11-06 16:17 ` Ihor Radchenko
2023-11-07 10:55   ` Max Nikulin
2023-11-07 11:30     ` Ihor Radchenko [this message]
2023-11-20  9:55       ` Cletip Cletip
2023-12-04 12:58         ` Ihor Radchenko
2023-12-15 11:26           ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87leb9243e.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=clement020302@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).