From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@yandex.ru>
To: Bart Schaefer <schaefer@brasslantern.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: Feature request: set extension for =( ) created file
Date: Sun, 25 Sep 2016 19:58:07 +0300 [thread overview]
Message-ID: <1769091474822687@web1j.yandex.ru> (raw)
In-Reply-To: <160924221731.ZM30342@torch.brasslantern.com>
25.09.2016, 08:19, "Bart Schaefer" <schaefer@brasslantern.com>:
> On Sep 25, 3:05am, Nikolay Aleksandrovich Pavlov (ZyX) wrote:
> }
> } I would consider another thing: while extensions are significant part
> } of the file names, sometimes complete last path component or the whole
> } path matters. I would suggest that if syntax is extended to allow
> } controlling some properties of a temporary file name it should allow
> } to control everything:
>
> One thing that has to be considered is the security aspects of temporary
> file creation. Files created with =(...) have unpredictable names for
> a reason: A malicious actor should not be able to create such a file in
> advance, because if that's possible then the shell can be caused to read
> and/or write anywhere that the malicious actor desires.
>
> We even swept through the completion shell-functions not long ago and
> revised them all to create their temporary files using =(...) and then
> hardlink them with the actual desired file names. The linked files
> are then removed before functions exit, via an "always" block.
If user explicitly requested temporary file at `/home/foo/bar` then he is not satisfied with usual `=()` location and thus simply will use other options in place of `=()`. Providing extension to a `=()` syntax which allows specifying whole name should not open any security holes because it is not the default and it is a replacement for less convenient alternatives (i.e. `always` block). Specifying part of the name (extension or trailing path component) as I suggested is not different from the current situation: in both cases it simply adds a known suffix to a random name.
>
> } 1. Provide just an extension: use names like `/tmp/zshUkxFmK.ext`.
> } 2. Optionally provide full file name: use names like
> } `/tmp/zshUkxFmK/name.ext`, in this case temporary directory is generated and
> } then recursively deleted.
> } 3. Provide full path: allow generating automatically removed temporary files
> } at any selected location.
> } 4. Optionally make this feature generate temporary directories and not files,
> } if code for 2. is written this should be easy.
>
> The "mktemp" utility is designed to cover nearly all of these cases,
> and I don't know of any likely situation in which use of an "always"
> block (see next example) would leave something behind that the use
> of =(...) wouild not also leave behind.
>
> () {
> {
> local tempdir=$(mktemp -d)
> # ... do stuff in $tempdir ...
> } always {
> [[ -n $tempdir ]] && /bin/rm -r $tempdir
> }
> }
This is an argument against `=()` as a whole, not against my proposal. I can use `mktemp`+`always` block everywhere I use `=()`, but yet `=()` exists.
>
> } The key point is that I sometimes need temporary file in a specific
> } location, but I almost never needed temporary file with a specific
> } extension.
> [...]
> } As an implementation detail I would expect zsh to run parameter
> } expansion, filename expansion and filename generation and match the
> } result according to the above patterns.
>
> You can combine mktemp and zsh temp files, too:
>
> local tempdir=$(mktemp -d -p /*/${specific}/location)
> local TMPPREFIX=$tempdir/zsh
> ln =(<<<'this is a silly example') $tempdir/sillyexample.txt
> ls -l $tempdir
>
> In short it's pretty unlikely that we're going to re-implement mktemp
> by inventing convoluted variations of =(...) syntax.
>
> Futhermore, the definition of =(...) is that the contents of the
> resulting file are the standard output of the command inside the
> parens. What would that mean in the case of a directory?
This is why I suggested to allow only empty command if one needs a directory.
>
> What might be more reasonable is to add $TMPSUFFIX, which unlike
> $TMPPREFIX would not have a value by default, and when it is set,
> append that to the temporary name.
>
> However, neither that nor any of your suggestions would accomplish
> altering the filename based on the file content. The file has to be
> created in the parent shell before the command is even run, so that
> it can be opened as the command's output; and I would not advocate
> having the shell peering at the content without being explicitly
> scripted to do so.
This feature is not what OP requested.
next prev parent reply other threads:[~2016-09-25 17:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-24 17:51 Sebastian Gniazdowski
2016-09-24 17:55 ` Vadim Zeitlin
2016-09-24 18:43 ` Lawrence Velázquez
2016-09-24 19:30 ` Sebastian Gniazdowski
2016-09-24 19:55 ` Lawrence Velázquez
2016-09-24 20:14 ` Sebastian Gniazdowski
2016-09-24 20:36 ` Lawrence Velázquez
2016-09-24 20:44 ` Sebastian Gniazdowski
2016-09-24 21:06 ` Lawrence Velázquez
2016-09-24 21:24 ` Bart Schaefer
2016-09-24 21:58 ` Lawrence Velázquez
2016-09-25 0:05 ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-09-25 5:17 ` Bart Schaefer
2016-09-25 6:17 ` Sebastian Gniazdowski
2016-09-25 15:21 ` Lawrence Velázquez
2016-09-26 18:03 ` Bart Schaefer
2016-09-25 16:58 ` Nikolay Aleksandrovich Pavlov (ZyX) [this message]
2016-09-25 22:37 ` Bart Schaefer
2016-09-24 21:06 ` Bart Schaefer
2016-09-24 18:56 ` Sebastian Gniazdowski
2016-09-24 18:22 ` Bart Schaefer
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1769091474822687@web1j.yandex.ru \
--to=kp-pav@yandex.ru \
--cc=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/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.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).