From 14e445047918321ee19a87283a1c32df5530f4fb Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 12 May 2022 09:03:45 +0200 Subject: [PATCH] Improve Tramp's write-region * lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist): Use `tramp-handle-write-region'. (tramp-sudoedit-handle-write-region): Remove. * lisp/net/tramp.el (tramp-skeleton-write-region): Set extended attributes. --- lisp/net/tramp-sudoedit.el | 34 +--------------------------------- lisp/net/tramp.el | 7 +++++++ 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index fb885ebd054..420a593644f 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -147,7 +147,7 @@ See `tramp-actions-before-shell' for more info.") (unlock-file . tramp-handle-unlock-file) (vc-registered . ignore) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) - (write-region . tramp-sudoedit-handle-write-region)) + (write-region . tramp-handle-write-region)) "Alist of handler functions for Tramp SUDOEDIT method.") ;; It must be a `defsubst' in order to push the whole code into @@ -739,38 +739,6 @@ ID-FORMAT valid values are `string' and `integer'." (or gid (tramp-get-remote-gid v 'integer))) (tramp-unquote-file-local-name filename)))) -(defun tramp-sudoedit-handle-write-region - (start end filename &optional append visit lockname mustbenew) - "Like `write-region' for Tramp files." - (setq filename (expand-file-name filename)) - (with-parsed-tramp-file-name filename nil - (let* ((uid (or (file-attribute-user-id (file-attributes filename 'integer)) - (tramp-get-remote-uid v 'integer))) - (gid (or (file-attribute-group-id (file-attributes filename 'integer)) - (tramp-get-remote-gid v 'integer))) - (flag (and (eq mustbenew 'excl) 'nofollow)) - (modes (tramp-default-file-modes filename flag)) - (attributes (file-extended-attributes filename))) - (prog1 - (tramp-handle-write-region - start end filename append visit lockname mustbenew) - - ;; Set the ownership, modes and extended attributes. This is - ;; not performed in `tramp-handle-write-region'. - (unless (and (= (file-attribute-user-id - (file-attributes filename 'integer)) - uid) - (= (file-attribute-group-id - (file-attributes filename 'integer)) - gid)) - (tramp-set-file-uid-gid filename uid gid)) - (tramp-compat-set-file-modes filename modes flag) - ;; We ignore possible errors, because ACL strings could be - ;; incompatible. - (when attributes - (ignore-errors - (set-file-extended-attributes filename attributes))))))) - ;; Internal functions. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index b26346443da..b06147599c1 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3415,6 +3415,7 @@ BODY is the backend specific code." (gid (or (file-attribute-group-id (file-attributes filename 'integer)) (tramp-get-remote-gid v 'integer))) + (attributes (file-extended-attributes filename)) (curbuf (current-buffer))) ;; Lock file. @@ -3453,6 +3454,12 @@ BODY is the backend specific code." (when need-chown (tramp-set-file-uid-gid filename uid gid))) + ;; Set extended attributes. We ignore possible errors, + ;; because ACL strings could be incompatible. + (when attributes + (ignore-errors + (set-file-extended-attributes filename attributes))) + ;; Unlock file. (when file-locked ;; `unlock-file' exists since Emacs 28.1. -- 2.39.2