2018-12-16 14:49:07 +00:00
|
|
|
|
;;; tramp-sudoedit.el --- Functions for accessing under root permissions -*- lexical-binding:t -*-
|
|
|
|
|
|
2021-01-01 09:13:56 +00:00
|
|
|
|
;; Copyright (C) 2018-2021 Free Software Foundation, Inc.
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Michael Albinus <michael.albinus@gmx.de>
|
|
|
|
|
;; Keywords: comm, processes
|
|
|
|
|
;; Package: tramp
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; The "sudoedit" Tramp method allows to edit a file as a different
|
|
|
|
|
;; user on the local host. Contrary to the "sudo" method, all magic
|
|
|
|
|
;; file name functions are implemented by single "sudo ..." commands.
|
|
|
|
|
;; The purpose is to make editing such a file as secure as possible;
|
|
|
|
|
;; there must be no session running in the Emacs background which
|
|
|
|
|
;; could be attacked from inside Emacs.
|
|
|
|
|
|
|
|
|
|
;; Consequently, external processes are not implemented.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'tramp)
|
|
|
|
|
|
|
|
|
|
;;;###tramp-autoload
|
|
|
|
|
(defconst tramp-sudoedit-method "sudoedit"
|
|
|
|
|
"When this method name is used, call sudoedit for editing a file.")
|
|
|
|
|
|
|
|
|
|
;;;###tramp-autoload
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(tramp--with-startup
|
|
|
|
|
(add-to-list 'tramp-methods
|
|
|
|
|
`(,tramp-sudoedit-method
|
2019-01-08 14:03:57 +00:00
|
|
|
|
(tramp-sudo-login (("sudo") ("-u" "%u") ("-S") ("-H")
|
|
|
|
|
("-p" "Password:") ("--")))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(add-to-list 'tramp-default-user-alist '("\\`sudoedit\\'" nil "root"))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(tramp-set-completion-function
|
|
|
|
|
tramp-sudoedit-method tramp-completion-function-alist-su))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defconst tramp-sudoedit-sudo-actions
|
|
|
|
|
'((tramp-password-prompt-regexp tramp-action-password)
|
|
|
|
|
(tramp-wrong-passwd-regexp tramp-action-permission-denied)
|
|
|
|
|
(tramp-process-alive-regexp tramp-sudoedit-action-sudo))
|
|
|
|
|
"List of pattern/action pairs.
|
|
|
|
|
This list is used for sudo calls.
|
|
|
|
|
|
|
|
|
|
See `tramp-actions-before-shell' for more info.")
|
|
|
|
|
|
|
|
|
|
;;;###tramp-autoload
|
|
|
|
|
(defconst tramp-sudoedit-file-name-handler-alist
|
2019-02-19 13:00:17 +00:00
|
|
|
|
'((access-file . tramp-handle-access-file)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(add-name-to-file . tramp-sudoedit-handle-add-name-to-file)
|
|
|
|
|
(byte-compiler-base-file-name . ignore)
|
2019-11-05 11:58:47 +00:00
|
|
|
|
(copy-directory . tramp-handle-copy-directory)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(copy-file . tramp-sudoedit-handle-copy-file)
|
|
|
|
|
(delete-directory . tramp-sudoedit-handle-delete-directory)
|
|
|
|
|
(delete-file . tramp-sudoedit-handle-delete-file)
|
|
|
|
|
(diff-latest-backup-file . ignore)
|
|
|
|
|
;; `directory-file-name' performed by default handler.
|
|
|
|
|
(directory-files . tramp-handle-directory-files)
|
|
|
|
|
(directory-files-and-attributes
|
|
|
|
|
. tramp-handle-directory-files-and-attributes)
|
|
|
|
|
(dired-compress-file . ignore)
|
|
|
|
|
(dired-uncache . tramp-handle-dired-uncache)
|
|
|
|
|
(exec-path . ignore)
|
|
|
|
|
(expand-file-name . tramp-sudoedit-handle-expand-file-name)
|
|
|
|
|
(file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
|
|
|
|
|
(file-acl . tramp-sudoedit-handle-file-acl)
|
|
|
|
|
(file-attributes . tramp-sudoedit-handle-file-attributes)
|
|
|
|
|
(file-directory-p . tramp-handle-file-directory-p)
|
|
|
|
|
(file-equal-p . tramp-handle-file-equal-p)
|
|
|
|
|
(file-executable-p . tramp-sudoedit-handle-file-executable-p)
|
|
|
|
|
(file-exists-p . tramp-sudoedit-handle-file-exists-p)
|
|
|
|
|
(file-in-directory-p . tramp-handle-file-in-directory-p)
|
|
|
|
|
(file-local-copy . tramp-handle-file-local-copy)
|
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p,
lock-file and unlock-file.
* etc/NEWS: Tramp supports file locks now.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-adb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file)
(tramp-crypt-handle-unlock-file): New defun.
* lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify.
(tramp-fuse-unmount): New defun.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-rclone-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sh-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-smb-handle-copy-directory): Use `sleep-for'.
(tramp-smb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sshfs-handle-write-region): Handle LOCKNAME.
(tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sudoedit-maybe-open-connection):
Set "lock-pid" connection property.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid)
(tramp-handle-file-locked-p, tramp-handle-lock-file)
(tramp-handle-unlock-file): New defuns.
(tramp-lock-file-contents-regexp): New regexp.
(tramp-handle-write-region): Handle LOCKNAME.
* src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p):
Call handler if exists.
(Flock_file, Funlock_file): New defuns.
(Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols.
(Slock_file, Sunlock_file): Declare subroutines.
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test40-make-nearby-temp-file)
(tramp-archive-test43-file-system-info): Rename.
* test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil.
(tramp--test-fuse-p): New defun.
(tramp-test14-delete-directory): Use it.
(tramp-test39-lock-file): New test.
(tramp-test40-make-nearby-temp-file)
(tramp-test41-special-characters)
(tramp-test41-special-characters-with-stat)
(tramp-test41-special-characters-with-perl)
(tramp-test41-special-characters-with-ls, tramp-test42-utf8)
(tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl)
(tramp-test42-utf8-with-ls, tramp-test43-file-system-info)
(tramp-test44-asynchronous-requests, tramp-test45-auto-load)
(tramp-test45-delay-load, tramp-test45-recursive-load)
(tramp-test45-remote-load-path, tramp-test46-unload): Rename.
(tramp--test-special-characters, tramp--test-utf8)
(tramp--test-asynchronous-requests-timeout): Modify docstring.
2021-07-07 16:36:53 +00:00
|
|
|
|
(file-locked-p . tramp-handle-file-locked-p)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(file-modes . tramp-handle-file-modes)
|
|
|
|
|
(file-name-all-completions
|
|
|
|
|
. tramp-sudoedit-handle-file-name-all-completions)
|
|
|
|
|
(file-name-as-directory . tramp-handle-file-name-as-directory)
|
|
|
|
|
(file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
|
|
|
|
|
(file-name-completion . tramp-handle-file-name-completion)
|
|
|
|
|
(file-name-directory . tramp-handle-file-name-directory)
|
|
|
|
|
(file-name-nondirectory . tramp-handle-file-name-nondirectory)
|
|
|
|
|
;; `file-name-sans-versions' performed by default handler.
|
|
|
|
|
(file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
|
|
|
|
|
(file-notify-add-watch . ignore)
|
|
|
|
|
(file-notify-rm-watch . ignore)
|
|
|
|
|
(file-notify-valid-p . ignore)
|
|
|
|
|
(file-ownership-preserved-p . ignore)
|
|
|
|
|
(file-readable-p . tramp-sudoedit-handle-file-readable-p)
|
|
|
|
|
(file-regular-p . tramp-handle-file-regular-p)
|
|
|
|
|
(file-remote-p . tramp-handle-file-remote-p)
|
|
|
|
|
(file-selinux-context . tramp-sudoedit-handle-file-selinux-context)
|
|
|
|
|
(file-symlink-p . tramp-handle-file-symlink-p)
|
|
|
|
|
(file-system-info . tramp-sudoedit-handle-file-system-info)
|
|
|
|
|
(file-truename . tramp-sudoedit-handle-file-truename)
|
|
|
|
|
(file-writable-p . tramp-sudoedit-handle-file-writable-p)
|
|
|
|
|
(find-backup-file-name . tramp-handle-find-backup-file-name)
|
|
|
|
|
;; `get-file-buffer' performed by default handler.
|
|
|
|
|
(insert-directory . tramp-handle-insert-directory)
|
|
|
|
|
(insert-file-contents . tramp-handle-insert-file-contents)
|
|
|
|
|
(load . tramp-handle-load)
|
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p,
lock-file and unlock-file.
* etc/NEWS: Tramp supports file locks now.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-adb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file)
(tramp-crypt-handle-unlock-file): New defun.
* lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify.
(tramp-fuse-unmount): New defun.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-rclone-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sh-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-smb-handle-copy-directory): Use `sleep-for'.
(tramp-smb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sshfs-handle-write-region): Handle LOCKNAME.
(tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sudoedit-maybe-open-connection):
Set "lock-pid" connection property.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid)
(tramp-handle-file-locked-p, tramp-handle-lock-file)
(tramp-handle-unlock-file): New defuns.
(tramp-lock-file-contents-regexp): New regexp.
(tramp-handle-write-region): Handle LOCKNAME.
* src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p):
Call handler if exists.
(Flock_file, Funlock_file): New defuns.
(Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols.
(Slock_file, Sunlock_file): Declare subroutines.
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test40-make-nearby-temp-file)
(tramp-archive-test43-file-system-info): Rename.
* test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil.
(tramp--test-fuse-p): New defun.
(tramp-test14-delete-directory): Use it.
(tramp-test39-lock-file): New test.
(tramp-test40-make-nearby-temp-file)
(tramp-test41-special-characters)
(tramp-test41-special-characters-with-stat)
(tramp-test41-special-characters-with-perl)
(tramp-test41-special-characters-with-ls, tramp-test42-utf8)
(tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl)
(tramp-test42-utf8-with-ls, tramp-test43-file-system-info)
(tramp-test44-asynchronous-requests, tramp-test45-auto-load)
(tramp-test45-delay-load, tramp-test45-recursive-load)
(tramp-test45-remote-load-path, tramp-test46-unload): Rename.
(tramp--test-special-characters, tramp--test-utf8)
(tramp--test-asynchronous-requests-timeout): Modify docstring.
2021-07-07 16:36:53 +00:00
|
|
|
|
(lock-file . tramp-handle-lock-file)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
|
|
|
|
|
(make-directory . tramp-sudoedit-handle-make-directory)
|
|
|
|
|
(make-directory-internal . ignore)
|
2021-07-13 17:50:05 +00:00
|
|
|
|
(make-lock-file-name . tramp-handle-make-lock-file-name)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
|
2018-12-23 08:48:05 +00:00
|
|
|
|
(make-process . ignore)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link)
|
|
|
|
|
(process-file . ignore)
|
|
|
|
|
(rename-file . tramp-sudoedit-handle-rename-file)
|
|
|
|
|
(set-file-acl . tramp-sudoedit-handle-set-file-acl)
|
|
|
|
|
(set-file-modes . tramp-sudoedit-handle-set-file-modes)
|
|
|
|
|
(set-file-selinux-context . tramp-sudoedit-handle-set-file-selinux-context)
|
|
|
|
|
(set-file-times . tramp-sudoedit-handle-set-file-times)
|
|
|
|
|
(set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
|
|
|
|
|
(shell-command . ignore)
|
|
|
|
|
(start-file-process . ignore)
|
|
|
|
|
(substitute-in-file-name . tramp-handle-substitute-in-file-name)
|
|
|
|
|
(temporary-file-directory . tramp-handle-temporary-file-directory)
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(tramp-get-remote-gid . tramp-sudoedit-handle-get-remote-gid)
|
|
|
|
|
(tramp-get-remote-uid . tramp-sudoedit-handle-get-remote-uid)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(tramp-set-file-uid-gid . tramp-sudoedit-handle-set-file-uid-gid)
|
|
|
|
|
(unhandled-file-name-directory . ignore)
|
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p,
lock-file and unlock-file.
* etc/NEWS: Tramp supports file locks now.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-adb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file)
(tramp-crypt-handle-unlock-file): New defun.
* lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify.
(tramp-fuse-unmount): New defun.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-rclone-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sh-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-smb-handle-copy-directory): Use `sleep-for'.
(tramp-smb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sshfs-handle-write-region): Handle LOCKNAME.
(tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sudoedit-maybe-open-connection):
Set "lock-pid" connection property.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid)
(tramp-handle-file-locked-p, tramp-handle-lock-file)
(tramp-handle-unlock-file): New defuns.
(tramp-lock-file-contents-regexp): New regexp.
(tramp-handle-write-region): Handle LOCKNAME.
* src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p):
Call handler if exists.
(Flock_file, Funlock_file): New defuns.
(Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols.
(Slock_file, Sunlock_file): Declare subroutines.
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test40-make-nearby-temp-file)
(tramp-archive-test43-file-system-info): Rename.
* test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil.
(tramp--test-fuse-p): New defun.
(tramp-test14-delete-directory): Use it.
(tramp-test39-lock-file): New test.
(tramp-test40-make-nearby-temp-file)
(tramp-test41-special-characters)
(tramp-test41-special-characters-with-stat)
(tramp-test41-special-characters-with-perl)
(tramp-test41-special-characters-with-ls, tramp-test42-utf8)
(tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl)
(tramp-test42-utf8-with-ls, tramp-test43-file-system-info)
(tramp-test44-asynchronous-requests, tramp-test45-auto-load)
(tramp-test45-delay-load, tramp-test45-recursive-load)
(tramp-test45-remote-load-path, tramp-test46-unload): Rename.
(tramp--test-special-characters, tramp--test-utf8)
(tramp--test-asynchronous-requests-timeout): Modify docstring.
2021-07-07 16:36:53 +00:00
|
|
|
|
(unlock-file . tramp-handle-unlock-file)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(vc-registered . ignore)
|
|
|
|
|
(verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
|
|
|
|
|
(write-region . tramp-sudoedit-handle-write-region))
|
|
|
|
|
"Alist of handler functions for Tramp SUDOEDIT method.")
|
|
|
|
|
|
|
|
|
|
;; It must be a `defsubst' in order to push the whole code into
|
|
|
|
|
;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
|
|
|
|
|
;;;###tramp-autoload
|
|
|
|
|
(defsubst tramp-sudoedit-file-name-p (filename)
|
Adapt Tramp docstrings according to checkdoc
* lisp/net/tramp.el (tramp-backup-directory-alist)
(tramp-echoed-echo-mark-regexp, tramp-syntax-values)
(tramp-lookup-syntax, tramp-build-prefix-format)
(tramp-build-prefix-regexp, tramp-build-method-regexp)
(tramp-build-postfix-method-format)
(tramp-build-postfix-method-regexp)
(tramp-build-prefix-ipv6-format, tramp-build-prefix-ipv6-regexp)
(tramp-build-postfix-ipv6-format)
(tramp-build-postfix-ipv6-regexp)
(tramp-build-postfix-host-format)
(tramp-build-postfix-host-regexp, tramp-unknown-id-string)
(tramp-unknown-id-integer, tramp-build-file-name-regexp)
(tramp-build-completion-file-name-regexp, tramp-chunksize)
(tramp-find-method, tramp-find-user, tramp-find-host)
(tramp-dissect-file-name, tramp-get-buffer)
(tramp-get-connection-buffer, tramp-debug-message, tramp-error)
(with-tramp-connection-property, tramp-run-real-handler)
(tramp-file-name-for-operation, tramp-file-name-handler)
(tramp-completion-file-name-handler)
(tramp-completion-handle-file-name-completion)
(tramp-completion-dissect-file-name)
(tramp-completion-dissect-file-name1)
(tramp-handle-file-name-as-directory)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-mode-string-to-int)
(tramp-file-mode-from-int):
* lisp/net/tramp-adb.el (tramp-adb-file-name-p):
* lisp/net/tramp-archive.el (tramp-archive-run-real-handler)
(tramp-archive-file-name-handler)
(tramp-archive-dissect-file-name)
(with-parsed-tramp-archive-file-name)
(tramp-archive-gvfs-file-name, tramp-archive-handle-access-file):
* lisp/net/tramp-cmds.el (tramp-list-remote-buffers):
* lisp/net/tramp-compat.el (tramp-unload-file-name-handlers)
(tramp-compat-funcall, tramp-compat-tramp-file-name-slots):
* lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler)
(tramp-ftp-file-name-p):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-p)
(tramp-gvfs-file-name-handler)
(tramp-gvfs-stringify-dbus-message)
(tramp-gvfs-monitor-process-filter)
(tramp-gvfs-handler-mounted-unmounted):
* lisp/net/tramp-integration.el
(tramp-rfn-eshadow-update-overlay-regexp):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-p)
(tramp-rclone-file-name-handler, tramp-rclone-send-command):
* lisp/net/tramp-sh.el (tramp-sh--quoting-style-options)
(tramp-sh-gio-monitor-process-filter)
(tramp-sh-gvfs-monitor-dir-process-filter)
(tramp-sh-inotifywait-process-filter, tramp-find-executable)
(tramp-set-remote-path, tramp-open-shell, tramp-find-shell)
(tramp-send-command-and-check, tramp-shell-case-fold)
(tramp-get-remote-path):
* lisp/net/tramp-smb.el (tramp-smb-file-name-p)
(tramp-smb-file-name-handler)
(tramp-smb-do-file-attributes-with-stat)
(tramp-smb-handle-substitute-in-file-name)
(tramp-smb-get-stat-capability, tramp-smb-shell-quote-argument):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-p)
(tramp-sudoedit-file-name-handler)
(tramp-sudoedit-send-command-string):
* test/lisp/net/tramp-archive-tests.el (tramp-archive-test-all):
* test/lisp/net/tramp-tests.el (tramp--test-gvfs-p)
(tramp--test-with-proper-process-name-and-buffer)
(tramp-test-all): Adapt docstrings according to `checkdoc'.
2019-11-13 12:10:58 +00:00
|
|
|
|
"Check if it's a FILENAME for SUDOEDIT."
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(and (tramp-tramp-file-p filename)
|
|
|
|
|
(string= (tramp-file-name-method (tramp-dissect-file-name filename))
|
|
|
|
|
tramp-sudoedit-method)))
|
|
|
|
|
|
|
|
|
|
;;;###tramp-autoload
|
|
|
|
|
(defun tramp-sudoedit-file-name-handler (operation &rest args)
|
Adapt Tramp docstrings according to checkdoc
* lisp/net/tramp.el (tramp-backup-directory-alist)
(tramp-echoed-echo-mark-regexp, tramp-syntax-values)
(tramp-lookup-syntax, tramp-build-prefix-format)
(tramp-build-prefix-regexp, tramp-build-method-regexp)
(tramp-build-postfix-method-format)
(tramp-build-postfix-method-regexp)
(tramp-build-prefix-ipv6-format, tramp-build-prefix-ipv6-regexp)
(tramp-build-postfix-ipv6-format)
(tramp-build-postfix-ipv6-regexp)
(tramp-build-postfix-host-format)
(tramp-build-postfix-host-regexp, tramp-unknown-id-string)
(tramp-unknown-id-integer, tramp-build-file-name-regexp)
(tramp-build-completion-file-name-regexp, tramp-chunksize)
(tramp-find-method, tramp-find-user, tramp-find-host)
(tramp-dissect-file-name, tramp-get-buffer)
(tramp-get-connection-buffer, tramp-debug-message, tramp-error)
(with-tramp-connection-property, tramp-run-real-handler)
(tramp-file-name-for-operation, tramp-file-name-handler)
(tramp-completion-file-name-handler)
(tramp-completion-handle-file-name-completion)
(tramp-completion-dissect-file-name)
(tramp-completion-dissect-file-name1)
(tramp-handle-file-name-as-directory)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-mode-string-to-int)
(tramp-file-mode-from-int):
* lisp/net/tramp-adb.el (tramp-adb-file-name-p):
* lisp/net/tramp-archive.el (tramp-archive-run-real-handler)
(tramp-archive-file-name-handler)
(tramp-archive-dissect-file-name)
(with-parsed-tramp-archive-file-name)
(tramp-archive-gvfs-file-name, tramp-archive-handle-access-file):
* lisp/net/tramp-cmds.el (tramp-list-remote-buffers):
* lisp/net/tramp-compat.el (tramp-unload-file-name-handlers)
(tramp-compat-funcall, tramp-compat-tramp-file-name-slots):
* lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler)
(tramp-ftp-file-name-p):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-p)
(tramp-gvfs-file-name-handler)
(tramp-gvfs-stringify-dbus-message)
(tramp-gvfs-monitor-process-filter)
(tramp-gvfs-handler-mounted-unmounted):
* lisp/net/tramp-integration.el
(tramp-rfn-eshadow-update-overlay-regexp):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-p)
(tramp-rclone-file-name-handler, tramp-rclone-send-command):
* lisp/net/tramp-sh.el (tramp-sh--quoting-style-options)
(tramp-sh-gio-monitor-process-filter)
(tramp-sh-gvfs-monitor-dir-process-filter)
(tramp-sh-inotifywait-process-filter, tramp-find-executable)
(tramp-set-remote-path, tramp-open-shell, tramp-find-shell)
(tramp-send-command-and-check, tramp-shell-case-fold)
(tramp-get-remote-path):
* lisp/net/tramp-smb.el (tramp-smb-file-name-p)
(tramp-smb-file-name-handler)
(tramp-smb-do-file-attributes-with-stat)
(tramp-smb-handle-substitute-in-file-name)
(tramp-smb-get-stat-capability, tramp-smb-shell-quote-argument):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-p)
(tramp-sudoedit-file-name-handler)
(tramp-sudoedit-send-command-string):
* test/lisp/net/tramp-archive-tests.el (tramp-archive-test-all):
* test/lisp/net/tramp-tests.el (tramp--test-gvfs-p)
(tramp--test-with-proper-process-name-and-buffer)
(tramp-test-all): Adapt docstrings according to `checkdoc'.
2019-11-13 12:10:58 +00:00
|
|
|
|
"Invoke the SUDOEDIT handler for OPERATION and ARGS.
|
2021-02-03 17:48:09 +00:00
|
|
|
|
First arg specifies the OPERATION, second arg is a list of
|
|
|
|
|
arguments to pass to the OPERATION."
|
Sync with Tramp 2.5.0-pre
* doc/misc/tramp.texi: Protext Tramp x.y and Emacs x.y by @w{}.
(GVFS-based methods): Move "GNOME Online Accounts" index.
(Customizing Methods, Android shell setup, File name completion)
(Frequently Asked Questions): Fix typos.
* doc/misc/trampver.texi: Change version to "2.5.0-pre".
* lisp/net/trampver.el: Change version to "2.5.0-pre".
(inhibit-message): Don't declare.
* lisp/net/tramp.el: Bump version to 2.5.0-pre. Require Emacs 25.1.
(tramp-debug-message): Simplify.
(tramp-message): Don't use `tramp-message-show-message'.
(tramp-with-demoted-errors, with-parsed-tramp-file-name)
(with-tramp-file-property, with-tramp-connection-property):
Adapt `declare' form.
(with-tramp-progress-reporter): Suppress progress reporter when
noninteractive.
(tramp-completion-mode, tramp-completion-mode-p): Remove.
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(format-message): Remove compatibility code.
(tramp-compat-directory-name-p)
(tramp-compat-tramp-file-name-slots): Remove.
* lisp/net/tramp.el (tramp-debug-message, tramp-message)
(tramp-backtrace, tramp-error, tramp-error-with-buffer)
(tramp-user-error, tramp-with-demoted-errors)
(tramp-signal-hook-function):
* lisp/net/tramp-compat.el (tramp-compat-funcall)
* lisp/net/tramp-gvfs.el (tramp-dbus-function):
Add `tramp-suppress-trace' property.
* lisp/net/tramp.el (tramp-get-method-parameter)
(tramp-dissect-file-name, tramp-error, tramp-error-with-buffer)
(tramp-user-error, with-parsed-tramp-file-name)
(with-tramp-progress-reporter, tramp-file-name-handler)
(tramp-completion-file-name-handler, tramp-autoload-file-name-handler)
(tramp-register-file-name-handlers, tramp-connectable-p)
(tramp-handle-file-modes, tramp-handle-file-regular-p)
(tramp-handle-file-truename, tramp-handle-insert-directory)
(tramp-handle-load, tramp-set-file-uid-gid):
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler)
(tramp-adb-handle-file-truename, tramp-adb-handle-copy-file)
(tramp-adb-handle-rename-file):
* lisp/net/tramp-archive.el (with-parsed-tramp-archive-file-name):
* lisp/net/tramp-cache.el (tramp-get-file-property, tramp-cache-print):
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(tramp-compat-exec-path):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler)
(tramp-gvfs-dbus-byte-array-to-string)
(tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler)
(tramp-rclone-do-copy-or-rename-file):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-truename)
(tramp-sh-handle-copy-directory, tramp-do-copy-or-rename-file)
(tramp-sh-handle-insert-directory, tramp-sh-file-name-handler)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler)
(tramp-smb-handle-copy-file, tramp-smb-handle-copy-directory)
(tramp-smb-handle-copy-file, tramp-smb-handle-insert-directory)
(tramp-smb-handle-rename-file, tramp-smb-maybe-open-connection):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler)
(tramp-sudoedit-do-copy-or-rename-file)
(tramp-sudoedit-handle-file-truename):
Use `if-let', `when-let', `directory-name-p', `inhibit-message',
`non-essential and `cl-struct-slot-info'. Don't use `seconds-to-time'.
* test/lisp/net/tramp-archive-tests.el (tramp-message-show-message):
Don't set.
* test/lisp/net/tramp-tests.el (inhibit-message): Don't declare.
(tramp-message-show-message): Don't set.
(tramp-test06-directory-file-name): Use `non-essential'.
(tramp-test10-write-region): Use `inhibit-message'.
(tramp-test36-vc-registered): No special handling for old Emacsen.
(tramp--test-emacs25-p): Remove.
(tramp-test45-unload): Special case of `tramp-completion-mode'.
2020-01-19 13:11:07 +00:00
|
|
|
|
(if-let ((fn (assoc operation tramp-sudoedit-file-name-handler-alist)))
|
|
|
|
|
(save-match-data (apply (cdr fn) args))
|
|
|
|
|
(tramp-run-real-handler operation args)))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
;;;###tramp-autoload
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(tramp--with-startup
|
|
|
|
|
(tramp-register-foreign-file-name-handler
|
|
|
|
|
#'tramp-sudoedit-file-name-p #'tramp-sudoedit-file-name-handler))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; File name primitives.
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-add-name-to-file
|
|
|
|
|
(filename newname &optional ok-if-already-exists)
|
|
|
|
|
"Like `add-name-to-file' for Tramp files."
|
|
|
|
|
(unless (tramp-equal-remote filename newname)
|
|
|
|
|
(with-parsed-tramp-file-name
|
|
|
|
|
(if (tramp-tramp-file-p filename) filename newname) nil
|
|
|
|
|
(tramp-error
|
|
|
|
|
v 'file-error
|
|
|
|
|
"add-name-to-file: %s"
|
|
|
|
|
"only implemented for same method, same user, same host")))
|
|
|
|
|
(with-parsed-tramp-file-name filename v1
|
|
|
|
|
(with-parsed-tramp-file-name newname v2
|
|
|
|
|
;; Do the 'confirm if exists' thing.
|
|
|
|
|
(when (file-exists-p newname)
|
|
|
|
|
;; What to do?
|
|
|
|
|
(if (or (null ok-if-already-exists) ; not allowed to exist
|
|
|
|
|
(and (numberp ok-if-already-exists)
|
|
|
|
|
(not (yes-or-no-p
|
|
|
|
|
(format
|
|
|
|
|
"File %s already exists; make it a link anyway? "
|
|
|
|
|
v2-localname)))))
|
|
|
|
|
(tramp-error v2 'file-already-exists newname)
|
|
|
|
|
(delete-file newname)))
|
|
|
|
|
(tramp-flush-file-properties v2 v2-localname)
|
|
|
|
|
(unless
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v1 "ln"
|
|
|
|
|
(tramp-compat-file-name-unquote v1-localname)
|
|
|
|
|
(tramp-compat-file-name-unquote v2-localname))
|
|
|
|
|
(tramp-error
|
|
|
|
|
v1 'file-error
|
|
|
|
|
"error with add-name-to-file, see buffer `%s' for details"
|
|
|
|
|
(buffer-name))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-do-copy-or-rename-file
|
|
|
|
|
(op filename newname &optional ok-if-already-exists keep-date
|
|
|
|
|
preserve-uid-gid preserve-extended-attributes)
|
|
|
|
|
"Copy or rename a remote file.
|
|
|
|
|
OP must be `copy' or `rename' and indicates the operation to perform.
|
|
|
|
|
FILENAME specifies the file to copy or rename, NEWNAME is the name of
|
|
|
|
|
the new file (for copy) or the new name of the file (for rename).
|
|
|
|
|
OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
|
|
|
|
|
KEEP-DATE means to make sure that NEWNAME has the same timestamp
|
|
|
|
|
as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
|
|
|
|
|
the uid and gid if both files are on the same host.
|
|
|
|
|
PRESERVE-EXTENDED-ATTRIBUTES activates selinux and acl commands.
|
|
|
|
|
|
|
|
|
|
This function is invoked by `tramp-sudoedit-handle-copy-file' and
|
|
|
|
|
`tramp-sudoedit-handle-rename-file'. It is an error if OP is
|
|
|
|
|
neither of `copy' and `rename'. FILENAME and NEWNAME must be
|
|
|
|
|
absolute file names."
|
|
|
|
|
(unless (memq op '(copy rename))
|
|
|
|
|
(error "Unknown operation `%s', must be `copy' or `rename'" op))
|
|
|
|
|
|
|
|
|
|
(setq filename (file-truename filename))
|
|
|
|
|
(if (file-directory-p filename)
|
|
|
|
|
(progn
|
|
|
|
|
(copy-directory filename newname keep-date t)
|
|
|
|
|
(when (eq op 'rename) (delete-directory filename 'recursive)))
|
|
|
|
|
|
|
|
|
|
(let ((t1 (tramp-sudoedit-file-name-p filename))
|
|
|
|
|
(t2 (tramp-sudoedit-file-name-p newname))
|
|
|
|
|
(file-times (tramp-compat-file-attribute-modification-time
|
|
|
|
|
(file-attributes filename)))
|
|
|
|
|
(file-modes (tramp-default-file-modes filename))
|
|
|
|
|
(attributes (and preserve-extended-attributes
|
2021-07-25 12:14:49 +00:00
|
|
|
|
(file-extended-attributes filename)))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(sudoedit-operation
|
|
|
|
|
(cond
|
|
|
|
|
((and (eq op 'copy) preserve-uid-gid) '("cp" "-f" "-p"))
|
|
|
|
|
((eq op 'copy) '("cp" "-f"))
|
|
|
|
|
((eq op 'rename) '("mv" "-f"))))
|
|
|
|
|
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
|
|
|
|
|
|
|
|
|
|
(with-parsed-tramp-file-name (if t1 filename newname) nil
|
2019-11-04 16:34:31 +00:00
|
|
|
|
(unless (file-exists-p filename)
|
2021-02-03 17:48:09 +00:00
|
|
|
|
(tramp-compat-file-missing v filename))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(when (and (not ok-if-already-exists) (file-exists-p newname))
|
|
|
|
|
(tramp-error v 'file-already-exists newname))
|
2019-08-08 14:47:29 +00:00
|
|
|
|
(when (and (file-directory-p newname)
|
Sync with Tramp 2.5.0-pre
* doc/misc/tramp.texi: Protext Tramp x.y and Emacs x.y by @w{}.
(GVFS-based methods): Move "GNOME Online Accounts" index.
(Customizing Methods, Android shell setup, File name completion)
(Frequently Asked Questions): Fix typos.
* doc/misc/trampver.texi: Change version to "2.5.0-pre".
* lisp/net/trampver.el: Change version to "2.5.0-pre".
(inhibit-message): Don't declare.
* lisp/net/tramp.el: Bump version to 2.5.0-pre. Require Emacs 25.1.
(tramp-debug-message): Simplify.
(tramp-message): Don't use `tramp-message-show-message'.
(tramp-with-demoted-errors, with-parsed-tramp-file-name)
(with-tramp-file-property, with-tramp-connection-property):
Adapt `declare' form.
(with-tramp-progress-reporter): Suppress progress reporter when
noninteractive.
(tramp-completion-mode, tramp-completion-mode-p): Remove.
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(format-message): Remove compatibility code.
(tramp-compat-directory-name-p)
(tramp-compat-tramp-file-name-slots): Remove.
* lisp/net/tramp.el (tramp-debug-message, tramp-message)
(tramp-backtrace, tramp-error, tramp-error-with-buffer)
(tramp-user-error, tramp-with-demoted-errors)
(tramp-signal-hook-function):
* lisp/net/tramp-compat.el (tramp-compat-funcall)
* lisp/net/tramp-gvfs.el (tramp-dbus-function):
Add `tramp-suppress-trace' property.
* lisp/net/tramp.el (tramp-get-method-parameter)
(tramp-dissect-file-name, tramp-error, tramp-error-with-buffer)
(tramp-user-error, with-parsed-tramp-file-name)
(with-tramp-progress-reporter, tramp-file-name-handler)
(tramp-completion-file-name-handler, tramp-autoload-file-name-handler)
(tramp-register-file-name-handlers, tramp-connectable-p)
(tramp-handle-file-modes, tramp-handle-file-regular-p)
(tramp-handle-file-truename, tramp-handle-insert-directory)
(tramp-handle-load, tramp-set-file-uid-gid):
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler)
(tramp-adb-handle-file-truename, tramp-adb-handle-copy-file)
(tramp-adb-handle-rename-file):
* lisp/net/tramp-archive.el (with-parsed-tramp-archive-file-name):
* lisp/net/tramp-cache.el (tramp-get-file-property, tramp-cache-print):
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(tramp-compat-exec-path):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler)
(tramp-gvfs-dbus-byte-array-to-string)
(tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler)
(tramp-rclone-do-copy-or-rename-file):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-truename)
(tramp-sh-handle-copy-directory, tramp-do-copy-or-rename-file)
(tramp-sh-handle-insert-directory, tramp-sh-file-name-handler)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler)
(tramp-smb-handle-copy-file, tramp-smb-handle-copy-directory)
(tramp-smb-handle-copy-file, tramp-smb-handle-insert-directory)
(tramp-smb-handle-rename-file, tramp-smb-maybe-open-connection):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler)
(tramp-sudoedit-do-copy-or-rename-file)
(tramp-sudoedit-handle-file-truename):
Use `if-let', `when-let', `directory-name-p', `inhibit-message',
`non-essential and `cl-struct-slot-info'. Don't use `seconds-to-time'.
* test/lisp/net/tramp-archive-tests.el (tramp-message-show-message):
Don't set.
* test/lisp/net/tramp-tests.el (inhibit-message): Don't declare.
(tramp-message-show-message): Don't set.
(tramp-test06-directory-file-name): Use `non-essential'.
(tramp-test10-write-region): Use `inhibit-message'.
(tramp-test36-vc-registered): No special handling for old Emacsen.
(tramp--test-emacs25-p): Remove.
(tramp-test45-unload): Special case of `tramp-completion-mode'.
2020-01-19 13:11:07 +00:00
|
|
|
|
(not (directory-name-p newname)))
|
2019-07-12 13:10:57 +00:00
|
|
|
|
(tramp-error v 'file-error "File is a directory %s" newname))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(if (or (and (file-remote-p filename) (not t1))
|
|
|
|
|
(and (file-remote-p newname) (not t2)))
|
|
|
|
|
;; We cannot copy or rename directly.
|
|
|
|
|
(let ((tmpfile (tramp-compat-make-temp-file filename)))
|
|
|
|
|
(if (eq op 'copy)
|
|
|
|
|
(copy-file filename tmpfile t)
|
|
|
|
|
(rename-file filename tmpfile t))
|
|
|
|
|
(rename-file tmpfile newname ok-if-already-exists))
|
|
|
|
|
|
|
|
|
|
;; Direct action.
|
|
|
|
|
(with-tramp-progress-reporter
|
|
|
|
|
v 0 (format "%s %s to %s" msg-operation filename newname)
|
|
|
|
|
(unless (tramp-sudoedit-send-command
|
|
|
|
|
v sudoedit-operation
|
2020-01-06 11:11:53 +00:00
|
|
|
|
(tramp-unquote-file-local-name filename)
|
|
|
|
|
(tramp-unquote-file-local-name newname))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(tramp-error
|
|
|
|
|
v 'file-error
|
|
|
|
|
"Error %s `%s' `%s'" msg-operation filename newname))))
|
|
|
|
|
|
|
|
|
|
;; When `newname' is local, we must change the ownership to
|
|
|
|
|
;; the local user.
|
|
|
|
|
(unless (file-remote-p newname)
|
|
|
|
|
(tramp-set-file-uid-gid
|
|
|
|
|
(concat (file-remote-p filename) newname)
|
|
|
|
|
(tramp-get-local-uid 'integer)
|
|
|
|
|
(tramp-get-local-gid 'integer)))
|
|
|
|
|
|
|
|
|
|
;; Set the time and mode. Mask possible errors.
|
|
|
|
|
(when keep-date
|
|
|
|
|
(ignore-errors
|
2020-03-09 15:05:21 +00:00
|
|
|
|
(tramp-compat-set-file-times
|
|
|
|
|
newname file-times (unless ok-if-already-exists 'nofollow))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(set-file-modes newname file-modes)))
|
|
|
|
|
|
|
|
|
|
;; Handle `preserve-extended-attributes'. We ignore possible
|
|
|
|
|
;; errors, because ACL strings could be incompatible.
|
|
|
|
|
(when attributes
|
|
|
|
|
(ignore-errors
|
2021-07-25 12:14:49 +00:00
|
|
|
|
(set-file-extended-attributes newname attributes)))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(when (and t1 (eq op 'rename))
|
|
|
|
|
(with-parsed-tramp-file-name filename v1
|
|
|
|
|
(tramp-flush-file-properties v1 v1-localname)))
|
|
|
|
|
|
|
|
|
|
(when t2
|
|
|
|
|
(with-parsed-tramp-file-name newname v2
|
2019-01-08 14:03:57 +00:00
|
|
|
|
(tramp-flush-file-properties v2 v2-localname)))))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-copy-file
|
|
|
|
|
(filename newname &optional ok-if-already-exists keep-date
|
|
|
|
|
preserve-uid-gid preserve-extended-attributes)
|
|
|
|
|
"Like `copy-file' for Tramp files."
|
2020-01-24 13:41:44 +00:00
|
|
|
|
(setq filename (expand-file-name filename)
|
|
|
|
|
newname (expand-file-name newname))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; At least one file a Tramp file?
|
|
|
|
|
(if (or (tramp-tramp-file-p filename)
|
|
|
|
|
(tramp-tramp-file-p newname))
|
|
|
|
|
(tramp-sudoedit-do-copy-or-rename-file
|
|
|
|
|
'copy filename newname ok-if-already-exists keep-date
|
|
|
|
|
preserve-uid-gid preserve-extended-attributes)
|
|
|
|
|
(tramp-run-real-handler
|
2019-02-28 09:33:05 +00:00
|
|
|
|
#'copy-file
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(list filename newname ok-if-already-exists keep-date
|
|
|
|
|
preserve-uid-gid preserve-extended-attributes))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-delete-directory
|
|
|
|
|
(directory &optional recursive trash)
|
|
|
|
|
"Like `delete-directory' for Tramp files."
|
2020-11-01 11:42:29 +00:00
|
|
|
|
(tramp-skeleton-delete-directory directory recursive trash
|
|
|
|
|
(unless (tramp-sudoedit-send-command
|
|
|
|
|
v (if recursive '("rm" "-rf") "rmdir")
|
|
|
|
|
(tramp-compat-file-name-unquote localname))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(tramp-error v 'file-error "Couldn't delete %s" directory))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-delete-file (filename &optional trash)
|
|
|
|
|
"Like `delete-file' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(tramp-flush-file-properties v localname)
|
2020-11-01 11:42:29 +00:00
|
|
|
|
(if (and delete-by-moving-to-trash trash)
|
|
|
|
|
(move-file-to-trash filename)
|
|
|
|
|
(unless (tramp-sudoedit-send-command
|
|
|
|
|
v "rm" (tramp-compat-file-name-unquote localname))
|
|
|
|
|
;; Propagate the error.
|
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer v)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(tramp-error-with-buffer
|
|
|
|
|
nil v 'file-error "Couldn't delete %s" filename))))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-expand-file-name (name &optional dir)
|
|
|
|
|
"Like `expand-file-name' for Tramp files.
|
|
|
|
|
If the localname part of the given file name starts with \"/../\" then
|
|
|
|
|
the result will be a local, non-Tramp, file name."
|
|
|
|
|
;; If DIR is not given, use `default-directory' or "/".
|
|
|
|
|
(setq dir (or dir default-directory "/"))
|
2019-03-06 11:06:09 +00:00
|
|
|
|
;; Handle empty NAME.
|
|
|
|
|
(when (zerop (length name)) (setq name "."))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; Unless NAME is absolute, concat DIR and NAME.
|
|
|
|
|
(unless (file-name-absolute-p name)
|
2021-07-25 10:05:01 +00:00
|
|
|
|
(setq name (tramp-compat-file-name-concat dir name)))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(with-parsed-tramp-file-name name nil
|
|
|
|
|
;; Tilde expansion if necessary. We cannot accept "~/", because
|
|
|
|
|
;; under sudo "~/" is expanded to the local user home directory
|
|
|
|
|
;; but to the root home directory.
|
|
|
|
|
(when (zerop (length localname))
|
|
|
|
|
(setq localname "~"))
|
|
|
|
|
(unless (file-name-absolute-p localname)
|
|
|
|
|
(setq localname (format "~%s/%s" user localname)))
|
|
|
|
|
(when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
|
|
|
|
|
(let ((uname (match-string 1 localname))
|
|
|
|
|
(fname (match-string 2 localname)))
|
|
|
|
|
(when (string-equal uname "~")
|
|
|
|
|
(setq uname (concat uname user)))
|
|
|
|
|
(setq localname (concat uname fname))))
|
2021-02-17 17:04:35 +00:00
|
|
|
|
;; Do not keep "/..".
|
|
|
|
|
(when (string-match-p "^/\\.\\.?$" localname)
|
|
|
|
|
(setq localname "/"))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; Do normal `expand-file-name' (this does "~user/", "/./" and "/../").
|
|
|
|
|
(tramp-make-tramp-file-name v (expand-file-name localname))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-remote-acl-p (vec)
|
|
|
|
|
"Check, whether ACL is enabled on the remote host."
|
2020-03-29 10:24:04 +00:00
|
|
|
|
(with-tramp-connection-property (tramp-get-process vec) "acl-p"
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(zerop (tramp-call-process vec "getfacl" nil nil nil "/"))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-acl (filename)
|
|
|
|
|
"Like `file-acl' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-acl"
|
|
|
|
|
(let ((result (and (tramp-sudoedit-remote-acl-p v)
|
|
|
|
|
(tramp-sudoedit-send-command-string
|
|
|
|
|
v "getfacl" "-acp"
|
|
|
|
|
(tramp-compat-file-name-unquote localname)))))
|
|
|
|
|
;; The acl string must have a trailing \n, which is not
|
|
|
|
|
;; provided by `tramp-sudoedit-send-command-string'. Add it.
|
|
|
|
|
(and (stringp result) (concat result "\n"))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-attributes (filename &optional id-format)
|
|
|
|
|
"Like `file-attributes' for Tramp files."
|
|
|
|
|
(unless id-format (setq id-format 'integer))
|
|
|
|
|
(with-parsed-tramp-file-name (expand-file-name filename) nil
|
|
|
|
|
(with-tramp-file-property
|
|
|
|
|
v localname (format "file-attributes-%s" id-format)
|
|
|
|
|
(tramp-message v 5 "file attributes: %s" localname)
|
|
|
|
|
(ignore-errors
|
|
|
|
|
(tramp-convert-file-attributes
|
|
|
|
|
v
|
|
|
|
|
(tramp-sudoedit-send-command-and-read
|
|
|
|
|
v "env" "QUOTING_STYLE=locale" "stat" "-c"
|
|
|
|
|
(format
|
|
|
|
|
;; Apostrophes in the stat output are masked as
|
|
|
|
|
;; `tramp-stat-marker', in order to make a proper shell
|
|
|
|
|
;; escape of them in file names.
|
|
|
|
|
"((%s%%N%s) %%h %s %s %%X %%Y %%Z %%s %s%%A%s t %%i -1)"
|
|
|
|
|
tramp-stat-marker tramp-stat-marker
|
|
|
|
|
(if (eq id-format 'integer)
|
|
|
|
|
"%u"
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(concat tramp-stat-marker "%U" tramp-stat-marker)))
|
|
|
|
|
(if (eq id-format 'integer)
|
|
|
|
|
"%g"
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(concat tramp-stat-marker "%G" tramp-stat-marker)))
|
|
|
|
|
tramp-stat-marker tramp-stat-marker)
|
|
|
|
|
(tramp-compat-file-name-unquote localname)))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-executable-p (filename)
|
|
|
|
|
"Like `file-executable-p' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-executable-p"
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "test" "-x" (tramp-compat-file-name-unquote localname)))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-exists-p (filename)
|
|
|
|
|
"Like `file-exists-p' for Tramp files."
|
2019-09-12 14:38:48 +00:00
|
|
|
|
;; `file-exists-p' is used as predicate in file name completion.
|
|
|
|
|
;; We don't want to run it when `non-essential' is t, or there is
|
|
|
|
|
;; no connection process yet.
|
|
|
|
|
(when (tramp-connectable-p filename)
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-exists-p"
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "test" "-e" (tramp-compat-file-name-unquote localname))))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-name-all-completions (filename directory)
|
|
|
|
|
"Like `file-name-all-completions' for Tramp files."
|
|
|
|
|
(all-completions
|
|
|
|
|
filename
|
|
|
|
|
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
|
|
|
|
(with-tramp-file-property v localname "file-name-all-completions"
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "ls" "-a1" "--quoting-style=literal" "--show-control-chars"
|
|
|
|
|
(if (zerop (length localname))
|
|
|
|
|
"" (tramp-compat-file-name-unquote localname)))
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (f)
|
|
|
|
|
(if (file-directory-p (expand-file-name f directory))
|
|
|
|
|
(file-name-as-directory f)
|
|
|
|
|
f))
|
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer v)
|
|
|
|
|
(delq
|
|
|
|
|
nil
|
|
|
|
|
(mapcar
|
2019-01-08 14:03:57 +00:00
|
|
|
|
(lambda (l) (and (not (string-match-p "^[[:space:]]*$" l)) l))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(split-string (buffer-string) "\n" 'omit)))))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-readable-p (filename)
|
|
|
|
|
"Like `file-readable-p' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-readable-p"
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "test" "-r" (tramp-compat-file-name-unquote localname)))))
|
|
|
|
|
|
Add 'nofollow' flag to set-file-modes etc.
This avoids some race conditions (Bug#39683). E.g., if some other
program changes a file to a symlink between the time Emacs creates
the file and the time it changes the file’s permissions, using the
new flag prevents Emacs from inadvertently changing the
permissions of a victim in some completely unrelated directory.
* admin/merge-gnulib (GNULIB_MODULES): Add fchmodat.
* doc/lispref/files.texi (Testing Accessibility, Changing Files):
* doc/lispref/os.texi (File Notifications):
* etc/NEWS:
Adjust documentation accordingly.
* lib/chmodat.c, lib/fchmodat.c, lib/lchmod.c, m4/fchmodat.m4:
* m4/lchmod.m4: New files, copied from Gnulib.
* lib/gnulib.mk.in: Regenerate.
* lisp/dired-aux.el (dired-do-chmod):
* lisp/doc-view.el (doc-view-make-safe-dir):
* lisp/emacs-lisp/autoload.el (autoload--save-buffer):
* lisp/emacs-lisp/bytecomp.el (byte-compile-file):
* lisp/eshell/em-pred.el (eshell-pred-file-mode):
* lisp/files.el (backup-buffer-copy, copy-directory):
* lisp/gnus/mail-source.el (mail-source-movemail):
* lisp/gnus/mm-decode.el (mm-display-external):
* lisp/gnus/nnmail.el (nnmail-write-region):
* lisp/net/tramp-adb.el (tramp-adb-handle-file-local-copy)
(tramp-adb-handle-write-region):
* lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-directly):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-write-region):
* lisp/net/tramp.el (tramp-handle-write-region)
(tramp-make-tramp-temp-file):
* lisp/server.el (server-ensure-safe-dir):
* lisp/url/url-util.el (url-make-private-file):
When getting or setting file modes, avoid following symbolic links
when the file is not supposed to be a symbolic link.
* lisp/doc-view.el (doc-view-make-safe-dir):
Omit no-longer-needed separate symlink test.
* lisp/gnus/gnus-util.el (gnus-set-file-modes):
* lisp/net/tramp.el (tramp-handle-file-modes):
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-set-file-modes):
* src/fileio.c (symlink_nofollow_flag): New function.
(Ffile_modes, Fset_file_modes):
Support an optional FLAG arg. All C callers changed.
* lisp/net/ange-ftp.el (ange-ftp-set-file-modes):
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-modes):
* lisp/net/tramp-sh.el (tramp-sh-handle-set-file-modes):
* lisp/net/tramp-smb.el (tramp-smb-handle-set-file-modes):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-set-file-modes):
Accept an optional FLAG arg that is currently ignored,
and add a FIXME comment for it.
* m4/gnulib-comp.m4: Regenerate.
2020-02-24 00:19:42 +00:00
|
|
|
|
(defun tramp-sudoedit-handle-set-file-modes (filename mode &optional flag)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
"Like `set-file-modes' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
2020-02-26 17:43:11 +00:00
|
|
|
|
;; It is unlikely that "chmod -h" works.
|
|
|
|
|
(unless (and (eq flag 'nofollow) (file-symlink-p filename))
|
|
|
|
|
(tramp-flush-file-properties v localname)
|
|
|
|
|
(unless (tramp-sudoedit-send-command
|
|
|
|
|
v "chmod" (format "%o" mode)
|
|
|
|
|
(tramp-compat-file-name-unquote localname))
|
|
|
|
|
(tramp-error
|
|
|
|
|
v 'file-error "Error while changing file's mode %s" filename)))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-remote-selinux-p (vec)
|
|
|
|
|
"Check, whether SELINUX is enabled on the remote host."
|
2020-03-29 10:24:04 +00:00
|
|
|
|
(with-tramp-connection-property (tramp-get-process vec) "selinux-p"
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(zerop (tramp-call-process vec "selinuxenabled"))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-selinux-context (filename)
|
|
|
|
|
"Like `file-selinux-context' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-selinux-context"
|
|
|
|
|
(let ((context '(nil nil nil nil))
|
2020-07-12 13:02:56 +00:00
|
|
|
|
(regexp (concat "\\([[:alnum:]_]+\\):" "\\([[:alnum:]_]+\\):"
|
|
|
|
|
"\\([[:alnum:]_]+\\):" "\\([[:alnum:]_]+\\)")))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(when (and (tramp-sudoedit-remote-selinux-p v)
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "ls" "-d" "-Z"
|
|
|
|
|
(tramp-compat-file-name-unquote localname)))
|
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer v)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (re-search-forward regexp (point-at-eol) t)
|
|
|
|
|
(setq context (list (match-string 1) (match-string 2)
|
|
|
|
|
(match-string 3) (match-string 4))))))
|
|
|
|
|
;; Return the context.
|
|
|
|
|
context))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-system-info (filename)
|
|
|
|
|
"Like `file-system-info' for Tramp files."
|
|
|
|
|
(ignore-errors
|
|
|
|
|
(with-parsed-tramp-file-name (expand-file-name filename) nil
|
|
|
|
|
(tramp-message v 5 "file system info: %s" localname)
|
|
|
|
|
(when (tramp-sudoedit-send-command
|
|
|
|
|
v "df" "--block-size=1" "--output=size,used,avail"
|
2020-01-04 13:00:39 +00:00
|
|
|
|
(tramp-compat-file-name-unquote localname))
|
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer v)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line)
|
|
|
|
|
(when (looking-at
|
2020-07-12 13:02:56 +00:00
|
|
|
|
(concat "[[:space:]]*\\([[:digit:]]+\\)"
|
|
|
|
|
"[[:space:]]+\\([[:digit:]]+\\)"
|
|
|
|
|
"[[:space:]]+\\([[:digit:]]+\\)"))
|
2020-01-04 13:00:39 +00:00
|
|
|
|
(list (string-to-number (match-string 1))
|
|
|
|
|
;; The second value is the used size. We need the
|
|
|
|
|
;; free size.
|
|
|
|
|
(- (string-to-number (match-string 1))
|
|
|
|
|
(string-to-number (match-string 2)))
|
|
|
|
|
(string-to-number (match-string 3)))))))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
Add ‘nofollow’ flag to set-file-times
This is a companion to the recent set-file-modes patch.
It adds support for a ‘nofollow’ flag to set-file-times (Bug#39773).
Like the set-file-modes patch, it needs work in the w32 port.
* admin/merge-gnulib (GNULIB_MODULES): Add futimens, utimensat.
Remove utimens.
* doc/lispref/files.texi (Changing Files):
* etc/NEWS: Mention the change.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lisp/files.el (copy-directory):
* lisp/gnus/gnus-cloud.el (gnus-cloud-replace-file):
* lisp/net/tramp-adb.el (tramp-adb-handle-copy-file):
* lisp/net/tramp-smb.el (tramp-smb-handle-copy-file):
* lisp/tar-mode.el (tar-copy):
* test/lisp/filenotify-tests.el (file-notify-test03-events):
* test/lisp/files-tests.el:
(files-tests-file-name-non-special-set-file-times):
* test/lisp/net/tramp-tests.el (tramp-test22-file-times):
When setting file times, avoid following symbolic links
when the file is not supposed to be a symbolic link.
* lib/futimens.c, lib/utimensat.c, m4/futimens.m4, m4/utimensat.m4:
New files, copied from Gnulib.
* lisp/gnus/gnus-cloud.el (gnus-cloud-replace-file):
When creating a file that is not supposed to exist already,
use the excl flag to check this.
* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times):
* lisp/net/tramp-sh.el (tramp-sh-handle-set-file-times):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-set-file-times):
Accept an optional FLAG arg that is currently ignored,
and add a FIXME comment for it.
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-set-file-times):
* src/fileio.c (Fset_file_times):
Support an optional FLAG arg.
* src/fileio.c (Fcopy_file): Use futimens instead of set_file_times,
as it’s simpler and is a POSIX API.
* src/sysdep.c (set_file_times): Move from here ...
* src/w32.c (set_file_times): ... to here, and make it static,
since it is now used only in w32.c. Presumably w32.c should also
add support for futimens and utimensat (the POSIX APIs, which
Emacs now uses) and it can remove fdutimens (the Gnulib API,
which Emacs no longer uses).
2020-03-07 20:04:05 +00:00
|
|
|
|
(defun tramp-sudoedit-handle-set-file-times (filename &optional time flag)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
"Like `set-file-times' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(tramp-flush-file-properties v localname)
|
|
|
|
|
(let ((time
|
|
|
|
|
(if (or (null time)
|
|
|
|
|
(tramp-compat-time-equal-p time tramp-time-doesnt-exist)
|
|
|
|
|
(tramp-compat-time-equal-p time tramp-time-dont-know))
|
|
|
|
|
(current-time)
|
|
|
|
|
time)))
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "env" "TZ=UTC" "touch" "-t"
|
|
|
|
|
(format-time-string "%Y%m%d%H%M.%S" time t)
|
2020-03-09 15:05:21 +00:00
|
|
|
|
(if (eq flag 'nofollow) "-h" "")
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(tramp-compat-file-name-unquote localname)))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-truename (filename)
|
|
|
|
|
"Like `file-truename' for Tramp files."
|
2019-08-12 14:18:59 +00:00
|
|
|
|
;; Preserve trailing "/".
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(funcall
|
Sync with Tramp 2.5.0-pre
* doc/misc/tramp.texi: Protext Tramp x.y and Emacs x.y by @w{}.
(GVFS-based methods): Move "GNOME Online Accounts" index.
(Customizing Methods, Android shell setup, File name completion)
(Frequently Asked Questions): Fix typos.
* doc/misc/trampver.texi: Change version to "2.5.0-pre".
* lisp/net/trampver.el: Change version to "2.5.0-pre".
(inhibit-message): Don't declare.
* lisp/net/tramp.el: Bump version to 2.5.0-pre. Require Emacs 25.1.
(tramp-debug-message): Simplify.
(tramp-message): Don't use `tramp-message-show-message'.
(tramp-with-demoted-errors, with-parsed-tramp-file-name)
(with-tramp-file-property, with-tramp-connection-property):
Adapt `declare' form.
(with-tramp-progress-reporter): Suppress progress reporter when
noninteractive.
(tramp-completion-mode, tramp-completion-mode-p): Remove.
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(format-message): Remove compatibility code.
(tramp-compat-directory-name-p)
(tramp-compat-tramp-file-name-slots): Remove.
* lisp/net/tramp.el (tramp-debug-message, tramp-message)
(tramp-backtrace, tramp-error, tramp-error-with-buffer)
(tramp-user-error, tramp-with-demoted-errors)
(tramp-signal-hook-function):
* lisp/net/tramp-compat.el (tramp-compat-funcall)
* lisp/net/tramp-gvfs.el (tramp-dbus-function):
Add `tramp-suppress-trace' property.
* lisp/net/tramp.el (tramp-get-method-parameter)
(tramp-dissect-file-name, tramp-error, tramp-error-with-buffer)
(tramp-user-error, with-parsed-tramp-file-name)
(with-tramp-progress-reporter, tramp-file-name-handler)
(tramp-completion-file-name-handler, tramp-autoload-file-name-handler)
(tramp-register-file-name-handlers, tramp-connectable-p)
(tramp-handle-file-modes, tramp-handle-file-regular-p)
(tramp-handle-file-truename, tramp-handle-insert-directory)
(tramp-handle-load, tramp-set-file-uid-gid):
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler)
(tramp-adb-handle-file-truename, tramp-adb-handle-copy-file)
(tramp-adb-handle-rename-file):
* lisp/net/tramp-archive.el (with-parsed-tramp-archive-file-name):
* lisp/net/tramp-cache.el (tramp-get-file-property, tramp-cache-print):
* lisp/net/tramp-compat.el (tramp-compat-process-running-p)
(tramp-compat-exec-path):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler)
(tramp-gvfs-dbus-byte-array-to-string)
(tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler)
(tramp-rclone-do-copy-or-rename-file):
* lisp/net/tramp-sh.el (tramp-sh-handle-file-truename)
(tramp-sh-handle-copy-directory, tramp-do-copy-or-rename-file)
(tramp-sh-handle-insert-directory, tramp-sh-file-name-handler)
(tramp-maybe-open-connection):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler)
(tramp-smb-handle-copy-file, tramp-smb-handle-copy-directory)
(tramp-smb-handle-copy-file, tramp-smb-handle-insert-directory)
(tramp-smb-handle-rename-file, tramp-smb-maybe-open-connection):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler)
(tramp-sudoedit-do-copy-or-rename-file)
(tramp-sudoedit-handle-file-truename):
Use `if-let', `when-let', `directory-name-p', `inhibit-message',
`non-essential and `cl-struct-slot-info'. Don't use `seconds-to-time'.
* test/lisp/net/tramp-archive-tests.el (tramp-message-show-message):
Don't set.
* test/lisp/net/tramp-tests.el (inhibit-message): Don't declare.
(tramp-message-show-message): Don't set.
(tramp-test06-directory-file-name): Use `non-essential'.
(tramp-test10-write-region): Use `inhibit-message'.
(tramp-test36-vc-registered): No special handling for old Emacsen.
(tramp--test-emacs25-p): Remove.
(tramp-test45-unload): Special case of `tramp-completion-mode'.
2020-01-19 13:11:07 +00:00
|
|
|
|
(if (directory-name-p filename) #'file-name-as-directory #'identity)
|
2019-08-12 14:18:59 +00:00
|
|
|
|
;; Quote properly.
|
|
|
|
|
(funcall
|
|
|
|
|
(if (tramp-compat-file-name-quoted-p filename)
|
|
|
|
|
#'tramp-compat-file-name-quote #'identity)
|
|
|
|
|
(with-parsed-tramp-file-name
|
|
|
|
|
(tramp-compat-file-name-unquote (expand-file-name filename)) nil
|
|
|
|
|
(tramp-make-tramp-file-name
|
|
|
|
|
v
|
|
|
|
|
(with-tramp-file-property v localname "file-truename"
|
|
|
|
|
(let (result)
|
|
|
|
|
(tramp-message v 4 "Finding true name for `%s'" filename)
|
|
|
|
|
(setq result (tramp-sudoedit-send-command-string
|
|
|
|
|
v "readlink" "--canonicalize-missing" localname))
|
|
|
|
|
;; Detect cycle.
|
|
|
|
|
(when (and (file-symlink-p filename)
|
|
|
|
|
(string-equal result localname))
|
|
|
|
|
(tramp-error
|
|
|
|
|
v 'file-error
|
|
|
|
|
"Apparent cycle of symbolic links for %s" filename))
|
|
|
|
|
;; If the resulting localname looks remote, we must quote it
|
|
|
|
|
;; for security reasons.
|
|
|
|
|
(when (file-remote-p result)
|
|
|
|
|
(setq result (tramp-compat-file-name-quote result 'top)))
|
|
|
|
|
(tramp-message v 4 "True name of `%s' is `%s'" localname result)
|
|
|
|
|
result))
|
|
|
|
|
'nohop)))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-file-writable-p (filename)
|
|
|
|
|
"Like `file-writable-p' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(with-tramp-file-property v localname "file-writable-p"
|
|
|
|
|
(if (file-exists-p filename)
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "test" "-w" (tramp-compat-file-name-unquote localname))
|
|
|
|
|
(let ((dir (file-name-directory filename)))
|
|
|
|
|
(and (file-exists-p dir)
|
|
|
|
|
(file-writable-p dir)))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-make-directory (dir &optional parents)
|
|
|
|
|
"Like `make-directory' for Tramp files."
|
|
|
|
|
(setq dir (expand-file-name dir))
|
|
|
|
|
(with-parsed-tramp-file-name dir nil
|
2019-11-06 15:49:35 +00:00
|
|
|
|
(when (and (null parents) (file-exists-p dir))
|
|
|
|
|
(tramp-error v 'file-already-exists "Directory already exists %s" dir))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; When PARENTS is non-nil, DIR could be a chain of non-existent
|
|
|
|
|
;; directories a/b/c/... Instead of checking, we simply flush the
|
|
|
|
|
;; whole cache.
|
|
|
|
|
(tramp-flush-directory-properties
|
|
|
|
|
v (if parents "/" (file-name-directory localname)))
|
|
|
|
|
(unless (tramp-sudoedit-send-command
|
|
|
|
|
v (if parents '("mkdir" "-p") "mkdir")
|
|
|
|
|
(tramp-compat-file-name-unquote localname))
|
|
|
|
|
(tramp-error v 'file-error "Couldn't make directory %s" dir))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-make-symbolic-link
|
|
|
|
|
(target linkname &optional ok-if-already-exists)
|
|
|
|
|
"Like `make-symbolic-link' for Tramp files.
|
|
|
|
|
If TARGET is a non-Tramp file, it is used verbatim as the target
|
|
|
|
|
of the symlink. If TARGET is a Tramp file, only the localname
|
|
|
|
|
component is used as the target of the symlink."
|
|
|
|
|
(if (not (tramp-tramp-file-p (expand-file-name linkname)))
|
|
|
|
|
(tramp-run-real-handler
|
2019-02-28 09:33:05 +00:00
|
|
|
|
#'make-symbolic-link (list target linkname ok-if-already-exists))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(with-parsed-tramp-file-name linkname nil
|
|
|
|
|
;; If TARGET is a Tramp name, use just the localname component.
|
2019-06-04 10:51:45 +00:00
|
|
|
|
;; Don't check for a proper method.
|
|
|
|
|
(let ((non-essential t))
|
|
|
|
|
(when (and (tramp-tramp-file-p target)
|
|
|
|
|
(tramp-file-name-equal-p v (tramp-dissect-file-name target)))
|
2020-01-06 11:11:53 +00:00
|
|
|
|
(setq target (tramp-file-local-name (expand-file-name target)))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
;; If TARGET is still remote, quote it.
|
|
|
|
|
(if (tramp-tramp-file-p target)
|
2019-08-12 14:18:59 +00:00
|
|
|
|
(make-symbolic-link (tramp-compat-file-name-quote target 'top)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
linkname ok-if-already-exists)
|
|
|
|
|
|
|
|
|
|
;; Do the 'confirm if exists' thing.
|
|
|
|
|
(when (file-exists-p linkname)
|
|
|
|
|
;; What to do?
|
|
|
|
|
(if (or (null ok-if-already-exists) ; not allowed to exist
|
|
|
|
|
(and (numberp ok-if-already-exists)
|
|
|
|
|
(not
|
|
|
|
|
(yes-or-no-p
|
|
|
|
|
(format
|
|
|
|
|
"File %s already exists; make it a link anyway? "
|
|
|
|
|
localname)))))
|
|
|
|
|
(tramp-error v 'file-already-exists localname)
|
|
|
|
|
(delete-file linkname)))
|
|
|
|
|
|
|
|
|
|
(tramp-flush-file-properties v localname)
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "ln" "-sf"
|
|
|
|
|
(tramp-compat-file-name-unquote target)
|
|
|
|
|
(tramp-compat-file-name-unquote localname))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-rename-file
|
|
|
|
|
(filename newname &optional ok-if-already-exists)
|
|
|
|
|
"Like `rename-file' for Tramp files."
|
2020-01-24 13:41:44 +00:00
|
|
|
|
(setq filename (expand-file-name filename)
|
|
|
|
|
newname (expand-file-name newname))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; At least one file a Tramp file?
|
|
|
|
|
(if (or (tramp-tramp-file-p filename)
|
|
|
|
|
(tramp-tramp-file-p newname))
|
|
|
|
|
(tramp-sudoedit-do-copy-or-rename-file
|
|
|
|
|
'rename filename newname ok-if-already-exists
|
|
|
|
|
'keep-date 'preserve-uid-gid)
|
|
|
|
|
(tramp-run-real-handler
|
2021-05-22 15:51:07 +00:00
|
|
|
|
#'rename-file (list filename newname ok-if-already-exists))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-set-file-acl (filename acl-string)
|
|
|
|
|
"Like `set-file-acl' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name (expand-file-name filename) nil
|
|
|
|
|
(when (and (stringp acl-string) (tramp-sudoedit-remote-acl-p v))
|
|
|
|
|
;; Massage `acl-string'.
|
2019-06-28 14:32:12 +00:00
|
|
|
|
(setq acl-string (string-join (split-string acl-string "\n" 'omit) ","))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(prog1
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "setfacl" "-m"
|
|
|
|
|
acl-string (tramp-compat-file-name-unquote localname))
|
|
|
|
|
(tramp-flush-file-property v localname "file-acl")))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-set-file-selinux-context (filename context)
|
|
|
|
|
"Like `set-file-selinux-context' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(when (and (consp context)
|
|
|
|
|
(tramp-sudoedit-remote-selinux-p v))
|
|
|
|
|
(let ((user (and (stringp (nth 0 context)) (nth 0 context)))
|
|
|
|
|
(role (and (stringp (nth 1 context)) (nth 1 context)))
|
|
|
|
|
(type (and (stringp (nth 2 context)) (nth 2 context)))
|
|
|
|
|
(range (and (stringp (nth 3 context)) (nth 3 context))))
|
|
|
|
|
(when (tramp-sudoedit-send-command
|
2019-01-08 14:03:57 +00:00
|
|
|
|
v "chcon"
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(when user (format "--user=%s" user))
|
|
|
|
|
(when role (format "--role=%s" role))
|
|
|
|
|
(when type (format "--type=%s" type))
|
|
|
|
|
(when range (format "--range=%s" range))
|
|
|
|
|
(tramp-compat-file-name-unquote localname))
|
|
|
|
|
(if (and user role type range)
|
|
|
|
|
(tramp-set-file-property
|
|
|
|
|
v localname "file-selinux-context" context)
|
|
|
|
|
(tramp-flush-file-property v localname "file-selinux-context"))
|
|
|
|
|
t)))))
|
|
|
|
|
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(defun tramp-sudoedit-handle-get-remote-uid (vec id-format)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
"The uid of the remote connection VEC, in ID-FORMAT.
|
|
|
|
|
ID-FORMAT valid values are `string' and `integer'."
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(if (equal id-format 'integer)
|
|
|
|
|
(tramp-sudoedit-send-command-and-read vec "id" "-u")
|
|
|
|
|
(tramp-sudoedit-send-command-string vec "id" "-un")))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(defun tramp-sudoedit-handle-get-remote-gid (vec id-format)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
"The gid of the remote connection VEC, in ID-FORMAT.
|
|
|
|
|
ID-FORMAT valid values are `string' and `integer'."
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(if (equal id-format 'integer)
|
|
|
|
|
(tramp-sudoedit-send-command-and-read vec "id" "-g")
|
|
|
|
|
(tramp-sudoedit-send-command-string vec "id" "-gn")))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-set-file-uid-gid (filename &optional uid gid)
|
|
|
|
|
"Like `tramp-set-file-uid-gid' for Tramp files."
|
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
|
|
|
|
(tramp-sudoedit-send-command
|
|
|
|
|
v "chown"
|
|
|
|
|
(format "%d:%d"
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(or uid (tramp-get-remote-uid v 'integer))
|
|
|
|
|
(or gid (tramp-get-remote-gid v 'integer)))
|
2020-01-06 11:11:53 +00:00
|
|
|
|
(tramp-unquote-file-local-name filename))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-handle-write-region
|
|
|
|
|
(start end filename &optional append visit lockname mustbenew)
|
|
|
|
|
"Like `write-region' for Tramp files."
|
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p,
lock-file and unlock-file.
* etc/NEWS: Tramp supports file locks now.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-adb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file)
(tramp-crypt-handle-unlock-file): New defun.
* lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify.
(tramp-fuse-unmount): New defun.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-rclone-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sh-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-smb-handle-copy-directory): Use `sleep-for'.
(tramp-smb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sshfs-handle-write-region): Handle LOCKNAME.
(tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sudoedit-maybe-open-connection):
Set "lock-pid" connection property.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid)
(tramp-handle-file-locked-p, tramp-handle-lock-file)
(tramp-handle-unlock-file): New defuns.
(tramp-lock-file-contents-regexp): New regexp.
(tramp-handle-write-region): Handle LOCKNAME.
* src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p):
Call handler if exists.
(Flock_file, Funlock_file): New defuns.
(Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols.
(Slock_file, Sunlock_file): Declare subroutines.
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test40-make-nearby-temp-file)
(tramp-archive-test43-file-system-info): Rename.
* test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil.
(tramp--test-fuse-p): New defun.
(tramp-test14-delete-directory): Use it.
(tramp-test39-lock-file): New test.
(tramp-test40-make-nearby-temp-file)
(tramp-test41-special-characters)
(tramp-test41-special-characters-with-stat)
(tramp-test41-special-characters-with-perl)
(tramp-test41-special-characters-with-ls, tramp-test42-utf8)
(tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl)
(tramp-test42-utf8-with-ls, tramp-test43-file-system-info)
(tramp-test44-asynchronous-requests, tramp-test45-auto-load)
(tramp-test45-delay-load, tramp-test45-recursive-load)
(tramp-test45-remote-load-path, tramp-test46-unload): Rename.
(tramp--test-special-characters, tramp--test-utf8)
(tramp--test-asynchronous-requests-timeout): Modify docstring.
2021-07-07 16:36:53 +00:00
|
|
|
|
(setq filename (expand-file-name filename))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(with-parsed-tramp-file-name filename nil
|
2020-02-25 12:25:57 +00:00
|
|
|
|
(let* ((uid (or (tramp-compat-file-attribute-user-id
|
|
|
|
|
(file-attributes filename 'integer))
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(tramp-get-remote-uid v 'integer)))
|
2020-02-25 12:25:57 +00:00
|
|
|
|
(gid (or (tramp-compat-file-attribute-group-id
|
|
|
|
|
(file-attributes filename 'integer))
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(tramp-get-remote-gid v 'integer)))
|
2020-02-25 12:25:57 +00:00
|
|
|
|
(flag (and (eq mustbenew 'excl) 'nofollow))
|
2021-07-25 12:14:49 +00:00
|
|
|
|
(modes (tramp-default-file-modes filename flag))
|
|
|
|
|
(attributes (file-extended-attributes filename)))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(prog1
|
|
|
|
|
(tramp-handle-write-region
|
|
|
|
|
start end filename append visit lockname mustbenew)
|
|
|
|
|
|
2021-07-25 12:14:49 +00:00
|
|
|
|
;; Set the ownership, modes and extended attributes. This is
|
|
|
|
|
;; not performed in `tramp-handle-write-region'.
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(unless (and (= (tramp-compat-file-attribute-user-id
|
|
|
|
|
(file-attributes filename 'integer))
|
|
|
|
|
uid)
|
|
|
|
|
(= (tramp-compat-file-attribute-group-id
|
|
|
|
|
(file-attributes filename 'integer))
|
|
|
|
|
gid))
|
|
|
|
|
(tramp-set-file-uid-gid filename uid gid))
|
2021-07-25 12:14:49 +00:00
|
|
|
|
(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)))))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Internal functions.
|
|
|
|
|
|
|
|
|
|
;; Used in `tramp-sudoedit-sudo-actions'.
|
|
|
|
|
(defun tramp-sudoedit-action-sudo (proc vec)
|
Adapt Tramp docstrings according to checkdoc
* lisp/net/tramp.el (tramp-backup-directory-alist)
(tramp-echoed-echo-mark-regexp, tramp-syntax-values)
(tramp-lookup-syntax, tramp-build-prefix-format)
(tramp-build-prefix-regexp, tramp-build-method-regexp)
(tramp-build-postfix-method-format)
(tramp-build-postfix-method-regexp)
(tramp-build-prefix-ipv6-format, tramp-build-prefix-ipv6-regexp)
(tramp-build-postfix-ipv6-format)
(tramp-build-postfix-ipv6-regexp)
(tramp-build-postfix-host-format)
(tramp-build-postfix-host-regexp, tramp-unknown-id-string)
(tramp-unknown-id-integer, tramp-build-file-name-regexp)
(tramp-build-completion-file-name-regexp, tramp-chunksize)
(tramp-find-method, tramp-find-user, tramp-find-host)
(tramp-dissect-file-name, tramp-get-buffer)
(tramp-get-connection-buffer, tramp-debug-message, tramp-error)
(with-tramp-connection-property, tramp-run-real-handler)
(tramp-file-name-for-operation, tramp-file-name-handler)
(tramp-completion-file-name-handler)
(tramp-completion-handle-file-name-completion)
(tramp-completion-dissect-file-name)
(tramp-completion-dissect-file-name1)
(tramp-handle-file-name-as-directory)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-mode-string-to-int)
(tramp-file-mode-from-int):
* lisp/net/tramp-adb.el (tramp-adb-file-name-p):
* lisp/net/tramp-archive.el (tramp-archive-run-real-handler)
(tramp-archive-file-name-handler)
(tramp-archive-dissect-file-name)
(with-parsed-tramp-archive-file-name)
(tramp-archive-gvfs-file-name, tramp-archive-handle-access-file):
* lisp/net/tramp-cmds.el (tramp-list-remote-buffers):
* lisp/net/tramp-compat.el (tramp-unload-file-name-handlers)
(tramp-compat-funcall, tramp-compat-tramp-file-name-slots):
* lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler)
(tramp-ftp-file-name-p):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-p)
(tramp-gvfs-file-name-handler)
(tramp-gvfs-stringify-dbus-message)
(tramp-gvfs-monitor-process-filter)
(tramp-gvfs-handler-mounted-unmounted):
* lisp/net/tramp-integration.el
(tramp-rfn-eshadow-update-overlay-regexp):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-p)
(tramp-rclone-file-name-handler, tramp-rclone-send-command):
* lisp/net/tramp-sh.el (tramp-sh--quoting-style-options)
(tramp-sh-gio-monitor-process-filter)
(tramp-sh-gvfs-monitor-dir-process-filter)
(tramp-sh-inotifywait-process-filter, tramp-find-executable)
(tramp-set-remote-path, tramp-open-shell, tramp-find-shell)
(tramp-send-command-and-check, tramp-shell-case-fold)
(tramp-get-remote-path):
* lisp/net/tramp-smb.el (tramp-smb-file-name-p)
(tramp-smb-file-name-handler)
(tramp-smb-do-file-attributes-with-stat)
(tramp-smb-handle-substitute-in-file-name)
(tramp-smb-get-stat-capability, tramp-smb-shell-quote-argument):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-p)
(tramp-sudoedit-file-name-handler)
(tramp-sudoedit-send-command-string):
* test/lisp/net/tramp-archive-tests.el (tramp-archive-test-all):
* test/lisp/net/tramp-tests.el (tramp--test-gvfs-p)
(tramp--test-with-proper-process-name-and-buffer)
(tramp-test-all): Adapt docstrings according to `checkdoc'.
2019-11-13 12:10:58 +00:00
|
|
|
|
"Check, whether a sudo process has finished. Remove unneeded output."
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; There might be pending output for the exit status.
|
2019-01-29 16:25:36 +00:00
|
|
|
|
(unless (process-live-p proc)
|
2019-01-28 15:33:27 +00:00
|
|
|
|
(while (tramp-accept-process-output proc 0))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; Delete narrowed region, it would be in the way reading a Lisp form.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(widen)
|
|
|
|
|
(delete-region (point-min) (point))
|
|
|
|
|
;; Delete empty lines.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (and (not (eobp)) (= (point) (point-at-eol)))
|
|
|
|
|
(forward-line))
|
|
|
|
|
(delete-region (point-min) (point))
|
|
|
|
|
(tramp-message vec 3 "Process has finished.")
|
|
|
|
|
(throw 'tramp-action 'ok)))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-maybe-open-connection (vec)
|
|
|
|
|
"Maybe open a connection VEC.
|
|
|
|
|
Does not do anything if a connection is already open, but re-opens the
|
|
|
|
|
connection if a previous connection has died for some reason."
|
2019-09-12 14:38:48 +00:00
|
|
|
|
;; During completion, don't reopen a new connection.
|
|
|
|
|
(unless (tramp-connectable-p vec)
|
|
|
|
|
(throw 'non-essential 'non-essential))
|
|
|
|
|
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; We need a process bound to the connection buffer. Therefore, we
|
|
|
|
|
;; create a dummy process. Maybe there is a better solution?
|
|
|
|
|
(unless (tramp-get-connection-process vec)
|
|
|
|
|
(let ((p (make-network-process
|
2019-06-04 10:51:45 +00:00
|
|
|
|
:name (tramp-get-connection-name vec)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
:buffer (tramp-get-connection-buffer vec)
|
|
|
|
|
:server t :host 'local :service t :noquery t)))
|
|
|
|
|
(process-put p 'vector vec)
|
|
|
|
|
(set-process-query-on-exit-flag p nil)
|
|
|
|
|
|
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p,
lock-file and unlock-file.
* etc/NEWS: Tramp supports file locks now.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-adb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file)
(tramp-crypt-handle-unlock-file): New defun.
* lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify.
(tramp-fuse-unmount): New defun.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-rclone-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sh-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-smb-handle-copy-directory): Use `sleep-for'.
(tramp-smb-handle-write-region): Handle LOCKNAME.
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sshfs-handle-write-region): Handle LOCKNAME.
(tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property.
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-sudoedit-maybe-open-connection):
Set "lock-pid" connection property.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-locked-p', `lock-file' and `unlock-file'.
(tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid)
(tramp-handle-file-locked-p, tramp-handle-lock-file)
(tramp-handle-unlock-file): New defuns.
(tramp-lock-file-contents-regexp): New regexp.
(tramp-handle-write-region): Handle LOCKNAME.
* src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p):
Call handler if exists.
(Flock_file, Funlock_file): New defuns.
(Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols.
(Slock_file, Sunlock_file): Declare subroutines.
* test/lisp/net/tramp-archive-tests.el
(tramp-archive-test40-make-nearby-temp-file)
(tramp-archive-test43-file-system-info): Rename.
* test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil.
(tramp--test-fuse-p): New defun.
(tramp-test14-delete-directory): Use it.
(tramp-test39-lock-file): New test.
(tramp-test40-make-nearby-temp-file)
(tramp-test41-special-characters)
(tramp-test41-special-characters-with-stat)
(tramp-test41-special-characters-with-perl)
(tramp-test41-special-characters-with-ls, tramp-test42-utf8)
(tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl)
(tramp-test42-utf8-with-ls, tramp-test43-file-system-info)
(tramp-test44-asynchronous-requests, tramp-test45-auto-load)
(tramp-test45-delay-load, tramp-test45-recursive-load)
(tramp-test45-remote-load-path, tramp-test46-unload): Rename.
(tramp--test-special-characters, tramp--test-utf8)
(tramp--test-asynchronous-requests-timeout): Modify docstring.
2021-07-07 16:36:53 +00:00
|
|
|
|
;; Mark process for filelock.
|
|
|
|
|
(tramp-set-connection-property p "lock-pid" (truncate (time-to-seconds)))
|
|
|
|
|
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; Set connection-local variables.
|
2019-02-06 08:07:39 +00:00
|
|
|
|
(tramp-set-connection-local-variables vec)
|
|
|
|
|
|
|
|
|
|
;; Mark it as connected.
|
2020-06-14 13:31:17 +00:00
|
|
|
|
(tramp-set-connection-property p "connected" t))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-send-command (vec &rest args)
|
|
|
|
|
"Send commands ARGS to connection VEC.
|
|
|
|
|
If an element of ARGS is a list, it will be flattened. If an
|
|
|
|
|
element of ARGS is nil, it will be deleted.
|
|
|
|
|
Erases temporary buffer before sending the command. Returns nil
|
|
|
|
|
in case of error, t otherwise."
|
|
|
|
|
(tramp-sudoedit-maybe-open-connection vec)
|
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer vec)
|
|
|
|
|
(erase-buffer)
|
Add remote processes to Tramp sshfs method
* doc/misc/tramp.texi (FUSE setup): Method sshfs supports also
remote processes.
* lisp/net/tramp-cache.el (tramp-get-file-property)
(tramp-set-file-property): Move setting of
`tramp-cache-unload-hook' out of function.
* lisp/net/tramp.el (tramp-expand-args): New defun.
(tramp-handle-make-process):
* lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band)
(tramp-maybe-open-connection):
* lisp/net/tramp-sshfs.el (tramp-sshfs-maybe-open-connection):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-send-command): Use it.
* lisp/net/tramp-sshfs.el (tramp-methods) <sshfs>:
Adapt `tramp-mount-args'. Add `tramp-login-args',
`tramp-direct-async', `tramp-remote-shell',
`tramp-remote-shell-login' and `tramp-remote-shell-args'.
(tramp-connection-properties): Set "direct-async-process" fir sshfs.
(tramp-sshfs-file-name-handler-alist): Add `exec-path',
`make-process', `process-file', `set-file-modes', `shell-command',
`start-file-process', `tramp-get-remote-gid',
`tramp-get-remote-uid' and `tramp-set-file-uid-gid'.
(tramp-sshfs-handle-exec-path, tramp-sshfs-handle-process-file)
(tramp-sshfs-handle-set-file-modes): New defuns.
* test/lisp/net/tramp-tests.el (tramp-test20-file-modes)
(tramp-test28-process-file, tramp-test29-start-file-process)
(tramp-test30-make-process, tramp-test32-shell-command)
(tramp-test32-shell-command-dont-erase-buffer)
(tramp-test34-explicit-shell-file-name, tramp-test35-exec-path)
(tramp-test43-asynchronous-requests): Run also for tramp-sshfs.
(tramp--test-shell-file-name): New defun.
(tramp-test28-process-file)
(tramp-test34-explicit-shell-file-name)
(tramp-test43-asynchronous-requests): Use it.
(tramp-test40-special-characters-with-stat)
(tramp-test40-special-characters-with-perl)
(tramp-test40-special-characters-with-ls)
(tramp-test41-utf8-with-stat, tramp-test41-utf8-with-perl)
(tramp-test41-utf8-with-ls): Remove superfluous skip.
2021-03-11 16:16:50 +00:00
|
|
|
|
(let* ((delete-exited-processes t)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(process-connection-type tramp-process-connection-type)
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(p (apply #'start-process
|
Add remote processes to Tramp sshfs method
* doc/misc/tramp.texi (FUSE setup): Method sshfs supports also
remote processes.
* lisp/net/tramp-cache.el (tramp-get-file-property)
(tramp-set-file-property): Move setting of
`tramp-cache-unload-hook' out of function.
* lisp/net/tramp.el (tramp-expand-args): New defun.
(tramp-handle-make-process):
* lisp/net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band)
(tramp-maybe-open-connection):
* lisp/net/tramp-sshfs.el (tramp-sshfs-maybe-open-connection):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-send-command): Use it.
* lisp/net/tramp-sshfs.el (tramp-methods) <sshfs>:
Adapt `tramp-mount-args'. Add `tramp-login-args',
`tramp-direct-async', `tramp-remote-shell',
`tramp-remote-shell-login' and `tramp-remote-shell-args'.
(tramp-connection-properties): Set "direct-async-process" fir sshfs.
(tramp-sshfs-file-name-handler-alist): Add `exec-path',
`make-process', `process-file', `set-file-modes', `shell-command',
`start-file-process', `tramp-get-remote-gid',
`tramp-get-remote-uid' and `tramp-set-file-uid-gid'.
(tramp-sshfs-handle-exec-path, tramp-sshfs-handle-process-file)
(tramp-sshfs-handle-set-file-modes): New defuns.
* test/lisp/net/tramp-tests.el (tramp-test20-file-modes)
(tramp-test28-process-file, tramp-test29-start-file-process)
(tramp-test30-make-process, tramp-test32-shell-command)
(tramp-test32-shell-command-dont-erase-buffer)
(tramp-test34-explicit-shell-file-name, tramp-test35-exec-path)
(tramp-test43-asynchronous-requests): Run also for tramp-sshfs.
(tramp--test-shell-file-name): New defun.
(tramp-test28-process-file)
(tramp-test34-explicit-shell-file-name)
(tramp-test43-asynchronous-requests): Use it.
(tramp-test40-special-characters-with-stat)
(tramp-test40-special-characters-with-perl)
(tramp-test40-special-characters-with-ls)
(tramp-test41-utf8-with-stat, tramp-test41-utf8-with-perl)
(tramp-test41-utf8-with-ls): Remove superfluous skip.
2021-03-11 16:16:50 +00:00
|
|
|
|
(tramp-get-connection-name vec) (current-buffer)
|
|
|
|
|
(append
|
|
|
|
|
(tramp-expand-args
|
|
|
|
|
vec 'tramp-sudo-login
|
|
|
|
|
?h (or (tramp-file-name-host vec) "")
|
|
|
|
|
?u (or (tramp-file-name-user vec) ""))
|
|
|
|
|
(tramp-compat-flatten-tree args))))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; We suppress the messages `Waiting for prompts from remote shell'.
|
|
|
|
|
(tramp-verbose (if (= tramp-verbose 3) 2 tramp-verbose))
|
2021-07-26 07:55:30 +00:00
|
|
|
|
;; The password shall be cached also in case of "emacs -Q".
|
|
|
|
|
;; See `tramp-process-actions'.
|
|
|
|
|
(tramp-cache-read-persistent-data t)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; We do not want to save the password.
|
|
|
|
|
auth-source-save-behavior)
|
2019-06-28 14:32:12 +00:00
|
|
|
|
(tramp-message vec 6 "%s" (string-join (process-command p) " "))
|
2018-12-16 14:49:07 +00:00
|
|
|
|
;; Avoid process status message in output buffer.
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(set-process-sentinel p #'ignore)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(process-put p 'vector vec)
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(process-put p 'adjust-window-size-function #'ignore)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(set-process-query-on-exit-flag p nil)
|
|
|
|
|
(tramp-process-actions p vec nil tramp-sudoedit-sudo-actions)
|
|
|
|
|
(tramp-message vec 6 "%s\n%s" (process-exit-status p) (buffer-string))
|
|
|
|
|
(prog1
|
|
|
|
|
(zerop (process-exit-status p))
|
|
|
|
|
(delete-process p)))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-send-command-and-read (vec &rest args)
|
|
|
|
|
"Run command ARGS and return the output, which must be a Lisp expression.
|
|
|
|
|
In case there is no valid Lisp expression, it raises an error."
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(when (apply #'tramp-sudoedit-send-command vec args)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer vec)
|
|
|
|
|
;; Replace stat marker.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (search-forward tramp-stat-marker nil t)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward "\"" nil t)
|
|
|
|
|
(replace-match "\\\"" nil 'literal))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward tramp-stat-marker nil t)
|
|
|
|
|
(replace-match "\"")))
|
|
|
|
|
;; Read the expression.
|
|
|
|
|
(tramp-message vec 6 "\n%s" (buffer-string))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(prog1 (read (current-buffer))
|
|
|
|
|
;; Error handling.
|
|
|
|
|
(when (re-search-forward "\\S-" (point-at-eol) t)
|
|
|
|
|
(error nil)))
|
|
|
|
|
(error (tramp-error
|
|
|
|
|
vec 'file-error
|
|
|
|
|
"`%s' does not return a valid Lisp expression: `%s'"
|
|
|
|
|
(car args) (buffer-string)))))))
|
|
|
|
|
|
|
|
|
|
(defun tramp-sudoedit-send-command-string (vec &rest args)
|
Adapt Tramp docstrings according to checkdoc
* lisp/net/tramp.el (tramp-backup-directory-alist)
(tramp-echoed-echo-mark-regexp, tramp-syntax-values)
(tramp-lookup-syntax, tramp-build-prefix-format)
(tramp-build-prefix-regexp, tramp-build-method-regexp)
(tramp-build-postfix-method-format)
(tramp-build-postfix-method-regexp)
(tramp-build-prefix-ipv6-format, tramp-build-prefix-ipv6-regexp)
(tramp-build-postfix-ipv6-format)
(tramp-build-postfix-ipv6-regexp)
(tramp-build-postfix-host-format)
(tramp-build-postfix-host-regexp, tramp-unknown-id-string)
(tramp-unknown-id-integer, tramp-build-file-name-regexp)
(tramp-build-completion-file-name-regexp, tramp-chunksize)
(tramp-find-method, tramp-find-user, tramp-find-host)
(tramp-dissect-file-name, tramp-get-buffer)
(tramp-get-connection-buffer, tramp-debug-message, tramp-error)
(with-tramp-connection-property, tramp-run-real-handler)
(tramp-file-name-for-operation, tramp-file-name-handler)
(tramp-completion-file-name-handler)
(tramp-completion-handle-file-name-completion)
(tramp-completion-dissect-file-name)
(tramp-completion-dissect-file-name1)
(tramp-handle-file-name-as-directory)
(tramp-handle-file-name-directory)
(tramp-handle-file-name-nondirectory, tramp-mode-string-to-int)
(tramp-file-mode-from-int):
* lisp/net/tramp-adb.el (tramp-adb-file-name-p):
* lisp/net/tramp-archive.el (tramp-archive-run-real-handler)
(tramp-archive-file-name-handler)
(tramp-archive-dissect-file-name)
(with-parsed-tramp-archive-file-name)
(tramp-archive-gvfs-file-name, tramp-archive-handle-access-file):
* lisp/net/tramp-cmds.el (tramp-list-remote-buffers):
* lisp/net/tramp-compat.el (tramp-unload-file-name-handlers)
(tramp-compat-funcall, tramp-compat-tramp-file-name-slots):
* lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler)
(tramp-ftp-file-name-p):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-p)
(tramp-gvfs-file-name-handler)
(tramp-gvfs-stringify-dbus-message)
(tramp-gvfs-monitor-process-filter)
(tramp-gvfs-handler-mounted-unmounted):
* lisp/net/tramp-integration.el
(tramp-rfn-eshadow-update-overlay-regexp):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-p)
(tramp-rclone-file-name-handler, tramp-rclone-send-command):
* lisp/net/tramp-sh.el (tramp-sh--quoting-style-options)
(tramp-sh-gio-monitor-process-filter)
(tramp-sh-gvfs-monitor-dir-process-filter)
(tramp-sh-inotifywait-process-filter, tramp-find-executable)
(tramp-set-remote-path, tramp-open-shell, tramp-find-shell)
(tramp-send-command-and-check, tramp-shell-case-fold)
(tramp-get-remote-path):
* lisp/net/tramp-smb.el (tramp-smb-file-name-p)
(tramp-smb-file-name-handler)
(tramp-smb-do-file-attributes-with-stat)
(tramp-smb-handle-substitute-in-file-name)
(tramp-smb-get-stat-capability, tramp-smb-shell-quote-argument):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-p)
(tramp-sudoedit-file-name-handler)
(tramp-sudoedit-send-command-string):
* test/lisp/net/tramp-archive-tests.el (tramp-archive-test-all):
* test/lisp/net/tramp-tests.el (tramp--test-gvfs-p)
(tramp--test-with-proper-process-name-and-buffer)
(tramp-test-all): Adapt docstrings according to `checkdoc'.
2019-11-13 12:10:58 +00:00
|
|
|
|
"Run command ARGS and return the output as a string."
|
* lisp/net/tramp: Rework mutual dependencies
Functionally split tramp-loaddefs.el into two parts: one part run
while loading it at the very beginning of loading tramp.el (holding plain
autoloads and declarations), and another run at the very end of loading
tramp.el (holding setup code).
This should reduce infinite-recursion problems while loading.
* lisp/net/tramp.el: Require tramp-loaddefs at beginning.
Run (new and internal) tramp--startup-hook at the end.
Remove all tramp-autoloads. Prefer tramp--with-startup over
eval-after-load.
(tramp--with-startup): New macro.
(tramp-set-syntax): Show the new value rather than the old value in the
error message.
(tramp-syntax-values): Explicitly return 'values'.
(tramp-prefix-format, tramp-prefix-regexp, tramp-method-regexp)
(tramp-postfix-method-format, tramp-postfix-method-regexp)
(tramp-prefix-ipv6-format, tramp-prefix-ipv6-regexp)
(tramp-postfix-ipv6-format, tramp-postfix-ipv6-regexp)
(tramp-postfix-host-format, tramp-postfix-host-regexp)
(tramp-remote-file-name-spec-regexp, tramp-file-name-structure)
(tramp-completion-file-name-regexp): Don't initialize in the declaration,
since it's recomputed at the end anyway.
(tramp-time-dont-know, tramp-time-doesnt-exist): Move before first use.
* lisp/net/tramp-compat.el: Don't require tramp-loaddefs any more.
(tramp-compat-tramp-syntax): Declare tramp-syntax.
* lisp/net/tramp-smb.el:
* lisp/net/tramp-rclone.el:
* lisp/net/tramp-gvfs.el:
* lisp/net/tramp-ftp.el:
* lisp/net/tramp-adb.el: Wrap all autoloaded setup operations within
tramp--with-startup.
* lisp/net/tramp-sh.el: Wrap all autoloaded setup operations within
tramp--with-startup.
(tramp-display-escape-sequence-regexp)
(tramp-device-escape-sequence-regexp): Don't tramp-autoload any more.
(tramp-stat-marker): Use eval-and-compile rather than tramp-autoload.
* lisp/net/tramp-sudoedit.el: Wrap all autoloaded setup operations within
tramp--with-startup.
Require tramp-sh at compile-time to precompute some regexps based on
tramp-stat-marker.
2018-12-16 15:32:53 +00:00
|
|
|
|
(when (apply #'tramp-sudoedit-send-command vec args)
|
2018-12-16 14:49:07 +00:00
|
|
|
|
(with-current-buffer (tramp-get-connection-buffer vec)
|
|
|
|
|
(tramp-message vec 6 "\n%s" (buffer-string))
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
;(delete-blank-lines)
|
|
|
|
|
(while (looking-back "[ \t\n]+" nil 'greedy)
|
|
|
|
|
(delete-region (match-beginning 0) (point)))
|
|
|
|
|
(when (> (point-max) (point-min))
|
|
|
|
|
(substring-no-properties (buffer-string))))))
|
|
|
|
|
|
|
|
|
|
(add-hook 'tramp-unload-hook
|
|
|
|
|
(lambda ()
|
|
|
|
|
(unload-feature 'tramp-sudoedit 'force)))
|
|
|
|
|
|
|
|
|
|
(provide 'tramp-sudoedit)
|
|
|
|
|
|
|
|
|
|
;;; TODO:
|
|
|
|
|
|
|
|
|
|
;; * Fix *-selinux functions. Likely, this is due to wrong file
|
|
|
|
|
;; ownership after `write-region' and/or `copy-file'.
|
|
|
|
|
|
|
|
|
|
;;; tramp-sudoedit.el ends here
|