Subject: Re: bug#35495: 27.0.50; Untarring an archive with a keyring.gpg inside

From: Stefan Monnier <[email-masked]>
Date: Thu, 09 May 2019 20:24:02 -0400

> It looks like `jka-compr-write-region` does not do any compression if
> `file`'s extension does not match any of the extensions defined in
> `jka-compr-compression-info-list`. Writing to a file ending in ".gpg"
> just uses `epa-file-handler`, then.

Yes, of course, but the question is what it does when the tar's content
has a name that ends in `.gz` or something like that.  I now see that it
has a hack in write-region which looks at the contents to detect if it's
already compressed.

[ I guess this can lead to problem in odd cases such as when you
  manipulate a file of type "foo.mypkg" where mypkg is defined as
  a format that is always gz-compressed: if you save it as
  "foo.mypkg.gz" jka-compr won't re-compress it, but then when you open
  it, it will uncompress it before trying to handle it as a ".mypkg" at
  which point the mypkg tool might signal an error because it expected
  the ".mypkg" to be compressed.  If this will ever happen is
  anyone's guess, but it look sufficiently contrived that I'm not
  too worried.  ]

> I found that `tar-copy` has the same problem that `tar-untar-buffer`
> has. However, `tar-copy` has a small check where if the source file is
> compressed and the destination file should be compressed, the jka-compr
> file handler is disabled, as no conversion needs to be done. Maybe
> something similar could be done for .gpg files. If the file inside the
> tarfile is already encrypted and it is being extracted to
> <somewhere>.gpg, then the regular `write-region` should be used
> (i.e. just copy bytes from one place to another).

I think there should be a way to tell `write-region` that the content
should be written as-is into the file (and hence override jka-compr and
epa but not tramp).  I don't think there is such a thing yet, tho, so
we'll have to invent it.

        Stefan