aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2022-08-18 18:30:35 +0200
committerMichael Albinus2022-08-18 18:30:35 +0200
commitf98276f77b4e2cbf37e4d24387d21b48e9fd6144 (patch)
treea2728b20ee027079c8ef978ead813c19d16c951f
parentca7c278e32d43160c18f2ef8e324bf3b9be5c687 (diff)
downloademacs-f98276f77b4e2cbf37e4d24387d21b48e9fd6144.tar.gz
emacs-f98276f77b4e2cbf37e4d24387d21b48e9fd6144.zip
Fix encoding problem in tramp-sh.el
* lisp/net/tramp-sh.el (tramp-sh-handle-file-local-copy): Compute inline coding only if needed.
-rw-r--r--lisp/net/tramp-sh.el149
1 files changed, 76 insertions, 73 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 4a9cf2e6997..5075394d432 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3269,81 +3269,84 @@ implementation will be used."
3269(defun tramp-sh-handle-file-local-copy (filename) 3269(defun tramp-sh-handle-file-local-copy (filename)
3270 "Like `file-local-copy' for Tramp files." 3270 "Like `file-local-copy' for Tramp files."
3271 (tramp-skeleton-file-local-copy filename 3271 (tramp-skeleton-file-local-copy filename
3272 (if-let ((size (file-attribute-size (file-attributes filename))) 3272 (if-let ((size (file-attribute-size (file-attributes filename))))
3273 (rem-enc (tramp-get-inline-coding v "remote-encoding" size)) 3273 (let (rem-enc loc-dec)
3274 (loc-dec (tramp-get-inline-coding v "local-decoding" size)))
3275 3274
3276 (condition-case err 3275 (condition-case err
3277 (cond 3276 (cond
3278 ;; Empty file. 3277 ;; Empty file. Nothing to copy.
3279 ((zerop size)) 3278 ((zerop size))
3280 3279
3281 ;; `copy-file' handles direct copy and out-of-band methods. 3280 ;; `copy-file' handles direct copy and out-of-band methods.
3282 ((or (tramp-local-host-p v) 3281 ((or (tramp-local-host-p v)
3283 (tramp-method-out-of-band-p v size)) 3282 (tramp-method-out-of-band-p v size))
3284 (copy-file filename tmpfile 'ok-if-already-exists 'keep-time)) 3283 (copy-file filename tmpfile 'ok-if-already-exists 'keep-time))
3285 3284
3286 ;; Use inline encoding for file transfer. 3285 ;; Use inline encoding for file transfer.
3287 (rem-enc 3286 ((and (setq rem-enc
3288 (with-tramp-progress-reporter 3287 (tramp-get-inline-coding v "remote-encoding" size))
3289 v 3 3288 (setq loc-dec
3290 (format-message 3289 (tramp-get-inline-coding v "local-decoding" size)))
3291 "Encoding remote file `%s' with `%s'" filename rem-enc) 3290 (with-tramp-progress-reporter
3292 (tramp-barf-unless-okay 3291 v 3
3293 v (format rem-enc (tramp-shell-quote-argument localname)) 3292 (format-message
3294 "Encoding remote file failed")) 3293 "Encoding remote file `%s' with `%s'" filename rem-enc)
3295 3294 (tramp-barf-unless-okay
3296 ;; Check error. `rem-enc' could be a pipe, which doesn't 3295 v (format rem-enc (tramp-shell-quote-argument localname))
3297 ;; flag the error in the first command. 3296 "Encoding remote file failed"))
3298 (when (zerop (buffer-size (tramp-get-buffer v))) 3297
3299 (tramp-error v 'file-error' "Encoding remote file failed")) 3298 ;; Check error. `rem-enc' could be a pipe, which
3299 ;; doesn't flag the error in the first command.
3300 (when (zerop (buffer-size (tramp-get-buffer v)))
3301 (tramp-error v 'file-error' "Encoding remote file failed"))
3302
3303 (with-tramp-progress-reporter
3304 v 3 (format-message
3305 "Decoding local file `%s' with `%s'" tmpfile loc-dec)
3306 (if (functionp loc-dec)
3307 ;; If local decoding is a function, we call it.
3308 ;; We must disable multibyte, because
3309 ;; `uudecode-decode-region' doesn't handle it
3310 ;; correctly. Unset `file-name-handler-alist'.
3311 ;; Otherwise, epa-file gets confused.
3312 (let (file-name-handler-alist
3313 (coding-system-for-write 'binary)
3314 (default-directory
3315 tramp-compat-temporary-file-directory))
3316 (with-temp-file tmpfile
3317 (set-buffer-multibyte nil)
3318 (insert-buffer-substring (tramp-get-buffer v))
3319 (funcall loc-dec (point-min) (point-max))))
3320
3321 ;; If tramp-decoding-function is not defined for
3322 ;; this method, we invoke tramp-decoding-command
3323 ;; instead.
3324 (let ((tmpfile2 (tramp-compat-make-temp-file filename)))
3325 ;; Unset `file-name-handler-alist'. Otherwise,
3326 ;; epa-file gets confused.
3327 (let (file-name-handler-alist
3328 (coding-system-for-write 'binary))
3329 (with-current-buffer (tramp-get-buffer v)
3330 (write-region
3331 (point-min) (point-max) tmpfile2 nil 'no-message)))
3332 (unwind-protect
3333 (tramp-call-local-coding-command
3334 loc-dec tmpfile2 tmpfile)
3335 (delete-file tmpfile2)))))
3336
3337 ;; Set proper permissions.
3338 (set-file-modes tmpfile (tramp-default-file-modes filename))
3339 ;; Set local user ownership.
3340 (tramp-set-file-uid-gid tmpfile))
3341
3342 ;; Oops, I don't know what to do.
3343 (t (tramp-error
3344 v 'file-error "Wrong method specification for `%s'" method)))
3300 3345
3301 (with-tramp-progress-reporter 3346 ;; Error handling.
3302 v 3 (format-message 3347 ((error quit)
3303 "Decoding local file `%s' with `%s'" tmpfile loc-dec) 3348 (delete-file tmpfile)
3304 (if (functionp loc-dec) 3349 (signal (car err) (cdr err)))))
3305 ;; If local decoding is a function, we call it. We
3306 ;; must disable multibyte, because
3307 ;; `uudecode-decode-region' doesn't handle it
3308 ;; correctly. Unset `file-name-handler-alist'.
3309 ;; Otherwise, epa-file gets confused.
3310 (let (file-name-handler-alist
3311 (coding-system-for-write 'binary)
3312 (default-directory
3313 tramp-compat-temporary-file-directory))
3314 (with-temp-file tmpfile
3315 (set-buffer-multibyte nil)
3316 (insert-buffer-substring (tramp-get-buffer v))
3317 (funcall loc-dec (point-min) (point-max))))
3318
3319 ;; If tramp-decoding-function is not defined for this
3320 ;; method, we invoke tramp-decoding-command instead.
3321 (let ((tmpfile2 (tramp-compat-make-temp-file filename)))
3322 ;; Unset `file-name-handler-alist'. Otherwise,
3323 ;; epa-file gets confused.
3324 (let (file-name-handler-alist
3325 (coding-system-for-write 'binary))
3326 (with-current-buffer (tramp-get-buffer v)
3327 (write-region
3328 (point-min) (point-max) tmpfile2 nil 'no-message)))
3329 (unwind-protect
3330 (tramp-call-local-coding-command
3331 loc-dec tmpfile2 tmpfile)
3332 (delete-file tmpfile2)))))
3333
3334 ;; Set proper permissions.
3335 (set-file-modes tmpfile (tramp-default-file-modes filename))
3336 ;; Set local user ownership.
3337 (tramp-set-file-uid-gid tmpfile))
3338
3339 ;; Oops, I don't know what to do.
3340 (t (tramp-error
3341 v 'file-error "Wrong method specification for `%s'" method)))
3342
3343 ;; Error handling.
3344 ((error quit)
3345 (delete-file tmpfile)
3346 (signal (car err) (cdr err))))
3347 3350
3348 ;; Impossible to copy. Trigger `file-missing' error. 3351 ;; Impossible to copy. Trigger `file-missing' error.
3349 (setq tmpfile nil)))) 3352 (setq tmpfile nil))))