emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TRAMP copies binary files incorrectly


From: Stefan Monnier
Subject: Re: TRAMP copies binary files incorrectly
Date: Wed, 10 Jan 2007 22:10:57 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

> tramp.el is careful to bind coding-system-for-write to 'binary when
> writing the region:
>                    (let ((coding-system-for-write 'binary))
>                      (funcall loc-dec (point-min) (point-max))
>                      (write-region (point-min) (point-max) tmpfil))

> but unfortunately that's not enough to stop write-region playing with
> multi-byte characters - and that's probably the real bug.

The problem is not really in write-region but in the code before: there's no
way write-region can correctly write a multibyte char in "binary".
Write-region should probably just burp here rather than write something which
is likely to be incorrect.

> The " *tramp tmp*" buffer has coding-system-for-write set to 'binary,
> but also has enable-multibyte-characters set to t.

That's not a problem per se as long as the region passed to write-region
doesn't contain any multibyte char (i.e. non-ascii and non-eight-bit-*).

> My question is: should having the coding-system-for-write set to
> 'binary be enough to stop any multi-byte processing being done on
> write, regardless of the value of enable-multibyte-characters?  And if
> so, shouldn't we tell e_write() about it?

No.

The problem seems to be that in uudecode.el the call to "insert" ends up
internally converting the unibyte chars into multibyte chars (via
unibyte-char-to-multibyte) when inserting them into the multibyte buffer.

Basically, `insert' uses implicitly string-make-multibyte instead of
string-to-multibyte.

> --- lisp/net/tramp.el 2007-01-11 01:19:46.000000000 +0100
> +++ lisp/net/new/tramp.el     2007-01-11 01:18:59.000000000 +0100
> @@ -3827,6 +3827,7 @@
>                    ;; line from the output here.  Go to point-max,
>                    ;; search backward for tramp_exit_status, delete
>                    ;; between point and point-max if found.
> +                  (set-buffer-multibyte nil)
>                    (let ((coding-system-for-write 'binary))
>                      (funcall loc-dec (point-min) (point-max))
>                      (write-region (point-min) (point-max) tmpfil))

This patch looks correct, although I'd move the line earlier to right after
`erase-buffer' where set-buffer-multibyte will be more efficient.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]