diff options
Diffstat (limited to 'lisp/net/tramp-crypt.el')
-rw-r--r-- | lisp/net/tramp-crypt.el | 175 |
1 files changed, 77 insertions, 98 deletions
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el index 9588e6a1a8c..27b359d439b 100644 --- a/lisp/net/tramp-crypt.el +++ b/lisp/net/tramp-crypt.el @@ -151,13 +151,14 @@ If NAME doesn't belong to an encrypted remote directory, return nil." (dolist (dir tramp-crypt-directories) (and (string-prefix-p dir (file-name-as-directory (expand-file-name name))) - (throw 'crypt-file-name-p dir)))))) + (throw 'crypt-file-name-p dir)))))) ;; New handlers should be added here. ;;;###tramp-autoload (defconst tramp-crypt-file-name-handler-alist - '((access-file . tramp-crypt-handle-access-file) + '(;; `abbreviate-file-name' performed by default handler. + (access-file . tramp-crypt-handle-access-file) (add-name-to-file . tramp-handle-add-name-to-file) ;; `byte-compiler-base-file-name' performed by default handler. (copy-directory . tramp-handle-copy-directory) @@ -208,6 +209,7 @@ If NAME doesn't belong to an encrypted remote directory, return nil." ;; `get-file-buffer' performed by default handler. (insert-directory . tramp-crypt-handle-insert-directory) (insert-file-contents . tramp-handle-insert-file-contents) + (list-system-processes . ignore) (load . tramp-handle-load) (lock-file . tramp-crypt-handle-lock-file) (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) @@ -217,6 +219,7 @@ If NAME doesn't belong to an encrypted remote directory, return nil." (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) (make-process . ignore) (make-symbolic-link . tramp-handle-make-symbolic-link) + (process-attributes . ignore) (process-file . ignore) (rename-file . tramp-crypt-handle-rename-file) (set-file-acl . ignore) @@ -228,6 +231,7 @@ If NAME doesn't belong to an encrypted remote directory, return nil." (start-file-process . ignore) ;; `substitute-in-file-name' performed by default handler. (temporary-file-directory . tramp-handle-temporary-file-directory) + ;; `tramp-get-home-directory' performed by default-handler. ;; `tramp-get-remote-gid' performed by default handler. ;; `tramp-get-remote-uid' performed by default handler. (tramp-set-file-uid-gid . tramp-crypt-handle-set-file-uid-gid) @@ -294,8 +298,8 @@ arguments to pass to the OPERATION." (defun tramp-crypt-config-file-name (vec) "Return the encfs config file name for VEC." (expand-file-name - (concat "tramp-" (tramp-file-name-host vec) tramp-crypt-encfs-config) - user-emacs-directory)) + (locate-user-emacs-file + (concat "tramp-" (tramp-file-name-host vec) tramp-crypt-encfs-config)))) (defun tramp-crypt-maybe-open-connection (vec) "Maybe open a connection VEC. @@ -322,7 +326,7 @@ connection if a previous connection has died for some reason." tramp-crypt-encfs-config (tramp-crypt-get-remote-dir vec))) (local-config (tramp-crypt-config-file-name vec))) ;; There is no local encfs6 config file. - (when (not (file-exists-p local-config)) + (unless (file-exists-p local-config) (if (and tramp-crypt-save-encfs-config-remote (file-exists-p remote-config)) ;; Copy remote encfs6 config file if possible. @@ -422,7 +426,7 @@ Otherwise, return NAME." (if (directory-name-p name) #'file-name-as-directory #'identity) (concat dir - (unless (string-equal localname "/") + (unless (string-match-p (rx (seq bos (opt "/") eos)) localname) (with-tramp-file-property crypt-vec localname (concat (symbol-name op) "-file-name") (unless (tramp-crypt-send-command @@ -485,6 +489,7 @@ See `tramp-crypt-do-encrypt-or-decrypt-file'." Files in that directory and all subdirectories will be encrypted before copying to, and decrypted after copying from that directory. File names will be also encrypted." + ;; (declare (completion tramp-crypt-command-completion-p)) (interactive "DRemote directory name: ") (unless tramp-crypt-enabled (tramp-user-error nil "Feature is not enabled.")) @@ -595,62 +600,61 @@ absolute file names." (delete-directory filename 'recursive))) (with-parsed-tramp-file-name (if t1 filename newname) nil - (unless (file-exists-p filename) - (tramp-compat-file-missing v filename)) - (when (and (not ok-if-already-exists) (file-exists-p newname)) - (tramp-error v 'file-already-exists newname)) - (when (and (file-directory-p newname) - (not (directory-name-p newname))) - (tramp-error v 'file-error "File is a directory %s" newname)) - - (with-tramp-progress-reporter - v 0 (format "%s %s to %s" msg-operation filename newname) - (if (and t1 t2 (string-equal t1 t2)) - ;; Both files are on the same encrypted remote directory. - (let (tramp-crypt-enabled) - (if (eq op 'copy) - (copy-file - encrypt-filename encrypt-newname ok-if-already-exists - keep-date preserve-uid-gid preserve-extended-attributes) - (rename-file - encrypt-filename encrypt-newname ok-if-already-exists))) - - (let* ((tmpdir (tramp-compat-make-temp-file filename 'dir)) - (tmpfile1 - (expand-file-name - (file-name-nondirectory encrypt-filename) tmpdir)) - (tmpfile2 - (expand-file-name - (file-name-nondirectory encrypt-newname) tmpdir)) - tramp-crypt-enabled) - (cond - ;; Source and target file are on an encrypted remote directory. - ((and t1 t2) - (if (eq op 'copy) - (copy-file - encrypt-filename encrypt-newname ok-if-already-exists - keep-date preserve-uid-gid preserve-extended-attributes) - (rename-file - encrypt-filename encrypt-newname ok-if-already-exists))) - ;; Source file is on an encrypted remote directory. - (t1 - (if (eq op 'copy) - (copy-file - encrypt-filename tmpfile1 t keep-date preserve-uid-gid - preserve-extended-attributes) - (rename-file encrypt-filename tmpfile1 t)) - (tramp-crypt-decrypt-file t1 tmpfile1 tmpfile2) - (rename-file tmpfile2 newname ok-if-already-exists)) - ;; Target file is on an encrypted remote directory. - (t2 - (if (eq op 'copy) - (copy-file - filename tmpfile1 t keep-date preserve-uid-gid - preserve-extended-attributes) - (rename-file filename tmpfile1 t)) - (tramp-crypt-encrypt-file t2 tmpfile1 tmpfile2) - (rename-file tmpfile2 encrypt-newname ok-if-already-exists))) - (delete-directory tmpdir 'recursive)))))) + (tramp-barf-if-file-missing v filename + (when (and (not ok-if-already-exists) (file-exists-p newname)) + (tramp-error v 'file-already-exists newname)) + (when (and (file-directory-p newname) + (not (directory-name-p newname))) + (tramp-error v 'file-error "File is a directory %s" newname)) + + (with-tramp-progress-reporter + v 0 (format "%s %s to %s" msg-operation filename newname) + (if (and t1 t2 (string-equal t1 t2)) + ;; Both files are on the same encrypted remote directory. + (let (tramp-crypt-enabled) + (if (eq op 'copy) + (copy-file + encrypt-filename encrypt-newname ok-if-already-exists + keep-date preserve-uid-gid preserve-extended-attributes) + (rename-file + encrypt-filename encrypt-newname ok-if-already-exists))) + + (let* ((tmpdir (tramp-compat-make-temp-file filename 'dir)) + (tmpfile1 + (expand-file-name + (file-name-nondirectory encrypt-filename) tmpdir)) + (tmpfile2 + (expand-file-name + (file-name-nondirectory encrypt-newname) tmpdir)) + tramp-crypt-enabled) + (cond + ;; Source and target file are on an encrypted remote directory. + ((and t1 t2) + (if (eq op 'copy) + (copy-file + encrypt-filename encrypt-newname ok-if-already-exists + keep-date preserve-uid-gid preserve-extended-attributes) + (rename-file + encrypt-filename encrypt-newname ok-if-already-exists))) + ;; Source file is on an encrypted remote directory. + (t1 + (if (eq op 'copy) + (copy-file + encrypt-filename tmpfile1 t keep-date preserve-uid-gid + preserve-extended-attributes) + (rename-file encrypt-filename tmpfile1 t)) + (tramp-crypt-decrypt-file t1 tmpfile1 tmpfile2) + (rename-file tmpfile2 newname ok-if-already-exists)) + ;; Target file is on an encrypted remote directory. + (t2 + (if (eq op 'copy) + (copy-file + filename tmpfile1 t keep-date preserve-uid-gid + preserve-extended-attributes) + (rename-file filename tmpfile1 t)) + (tramp-crypt-encrypt-file t2 tmpfile1 tmpfile2) + (rename-file tmpfile2 encrypt-newname ok-if-already-exists))) + (delete-directory tmpdir 'recursive))))))) (when (and t1 (eq op 'rename)) (with-parsed-tramp-file-name filename v1 @@ -697,36 +701,14 @@ absolute file names." (defun tramp-crypt-handle-directory-files (directory &optional full match nosort count) "Like `directory-files' for Tramp files." - (unless (file-exists-p directory) - (tramp-compat-file-missing (tramp-dissect-file-name directory) directory)) - (when (file-directory-p directory) - (setq directory (file-name-as-directory (expand-file-name directory))) - (let* (tramp-crypt-enabled - (result - (directory-files (tramp-crypt-encrypt-file-name directory) 'full))) - (setq result - (mapcar (lambda (x) (tramp-crypt-decrypt-file-name x)) result)) - (when match - (setq result - (delq - nil - (mapcar - (lambda (x) - (when (string-match-p match (substring x (length directory))) - x)) - result)))) - (unless full - (setq result - (mapcar - (lambda (x) - (replace-regexp-in-string - (concat "^" (regexp-quote directory)) "" x)) - result))) - (unless nosort - (setq result (sort result #'string<))) - (when (and (natnump count) (> count 0)) - (setq result (nbutlast result (- (length result) count)))) - result))) + (tramp-skeleton-directory-files directory full match nosort count + (let (tramp-crypt-enabled) + (mapcar + (lambda (x) + (replace-regexp-in-string + (concat "^" (regexp-quote directory)) "" + (tramp-crypt-decrypt-file-name x))) + (directory-files (tramp-crypt-encrypt-file-name directory) 'full))))) (defun tramp-crypt-handle-file-attributes (filename &optional id-format) "Like `file-attributes' for Tramp files." @@ -842,24 +824,21 @@ WILDCARD is not supported." (defun tramp-crypt-handle-set-file-modes (filename mode &optional flag) "Like `set-file-modes' for Tramp files." - (with-parsed-tramp-file-name filename nil - (tramp-flush-file-properties v localname) + (tramp-skeleton-set-file-modes-times-uid-gid filename (let (tramp-crypt-enabled) (tramp-compat-set-file-modes (tramp-crypt-encrypt-file-name filename) mode flag)))) (defun tramp-crypt-handle-set-file-times (filename &optional time flag) "Like `set-file-times' for Tramp files." - (with-parsed-tramp-file-name filename nil - (tramp-flush-file-properties v localname) + (tramp-skeleton-set-file-modes-times-uid-gid filename (let (tramp-crypt-enabled) (tramp-compat-set-file-times (tramp-crypt-encrypt-file-name filename) time flag)))) (defun tramp-crypt-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-flush-file-properties v localname) + (tramp-skeleton-set-file-modes-times-uid-gid filename (let (tramp-crypt-enabled) (tramp-set-file-uid-gid (tramp-crypt-encrypt-file-name filename) uid gid)))) |