* lisp/net/tramp.el (tramp-set-syntax): Add missing argument.
(tramp-signal-hook-function): Make it more robust.
(tramp-handle-directory-files):
* lisp/net/tramp-adb.el
(tramp-adb-handle-directory-files-and-attributes)
(tramp-adb-handle-copy-file, tramp-adb-handle-rename-file):
* lisp/net/tramp-gvfs.el (tramp-gvfs-do-copy-or-rename-file):
* lisp/net/tramp-rclone.el (tramp-rclone-do-copy-or-rename-file)
(tramp-rclone-handle-directory-files):
* lisp/net/tramp-sh.el (tramp-sh-handle-directory-files-and-attributes)
(tramp-sh-handle-copy-directory, tramp-do-copy-or-rename-file):
* lisp/net/tramp-smb.el (tramp-smb-handle-copy-directory)
(tramp-smb-handle-copy-file, tramp-smb-handle-directory-files)
(tramp-smb-handle-rename-file):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-do-copy-or-rename-file):
Improve error handling.
* test/lisp/net/tramp-tests.el (tramp-test11-copy-file)
(tramp-test12-rename-file, tramp-test14-delete-directory)
(tramp-test15-copy-directory, tramp-test16-directory-files)
(tramp-test19-directory-files-and-attributes): Extend tests.
(defun tramp-adb-handle-directory-files-and-attributes
(directory &optional full match nosort id-format)
"Like `directory-files-and-attributes' for Tramp files."
+ (unless (file-exists-p directory)
+ (tramp-error
+ (tramp-dissect-file-name directory) tramp-file-missing
+ "No such file or directory" directory))
(when (file-directory-p directory)
(with-parsed-tramp-file-name (expand-file-name directory) nil
(copy-tree
(let ((t1 (tramp-tramp-file-p filename))
(t2 (tramp-tramp-file-p newname)))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "Copying file" "No such file or directory" 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)
(let ((t1 (tramp-tramp-file-p filename))
(t2 (tramp-tramp-file-p newname)))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "Renaming file" "No such file or directory" 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)
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "%s file" msg-operation "No such file or directory" 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)
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "%s file" msg-operation "No such file or directory" 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)
(defun tramp-rclone-handle-directory-files
(directory &optional full match nosort)
"Like `directory-files' for Tramp files."
+ (unless (file-exists-p directory)
+ (tramp-error
+ (tramp-dissect-file-name directory) tramp-file-missing
+ "No such file or directory" directory))
(when (file-directory-p directory)
(setq directory (file-name-as-directory (expand-file-name directory)))
(with-parsed-tramp-file-name directory nil
(directory &optional full match nosort id-format)
"Like `directory-files-and-attributes' for Tramp files."
(unless id-format (setq id-format 'integer))
+ (unless (file-exists-p directory)
+ (tramp-error
+ (tramp-dissect-file-name directory) tramp-file-missing
+ "No such file or directory" directory))
(when (file-directory-p directory)
(setq directory (expand-file-name directory))
(let* ((temp
(let ((t1 (tramp-tramp-file-p dirname))
(t2 (tramp-tramp-file-p newname)))
(with-parsed-tramp-file-name (if t1 dirname newname) nil
+ (unless (file-exists-p dirname)
+ (tramp-error
+ v tramp-file-missing
+ "Copying directory" "No such file or directory" dirname))
(if (and (not copy-contents)
(tramp-get-method-parameter v 'tramp-copy-recursive)
;; When DIRNAME and NEWNAME are remote, they must have
(apply #'file-extended-attributes (list filename)))))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing "No such file or directory" 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)
(with-parsed-tramp-file-name (if t1 dirname newname) nil
(with-tramp-progress-reporter
v 0 (format "Copying %s to %s" dirname newname)
+ (unless (file-exists-p dirname)
+ (tramp-error
+ v tramp-file-missing
+ "Copying directory" "No such file or directory" dirname))
(when (and (file-directory-p newname)
(not (tramp-compat-directory-name-p newname)))
(tramp-error v 'file-already-exists newname))
(if (file-directory-p filename)
(copy-directory filename newname keep-date 'parents 'copy-contents)
+ (unless (file-exists-p filename)
+ (tramp-error
+ (tramp-dissect-file-name
+ (if (tramp-tramp-file-p filename) filename newname))
+ tramp-file-missing
+ "Copying file" "No such file or directory" filename))
+
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
;; Remote filename.
(defun tramp-smb-handle-directory-files
(directory &optional full match nosort)
"Like `directory-files' for Tramp files."
+ (unless (file-exists-p directory)
+ (tramp-error
+ (tramp-dissect-file-name directory) tramp-file-missing
+ "No such file or directory" directory))
(let ((result (mapcar #'directory-file-name
(file-name-all-completions "" directory))))
;; Discriminate with regexp.
(with-parsed-tramp-file-name
(if (tramp-tramp-file-p filename) filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "Renaming file" "No such file or directory" 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)
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
(with-parsed-tramp-file-name (if t1 filename newname) nil
+ (unless (file-exists-p filename)
+ (tramp-error
+ v tramp-file-missing
+ "%s file" msg-operation "No such file or directory" 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)
to be set, depending on VALUE."
;; Check allowed values.
(unless (memq value (tramp-syntax-values))
- (tramp-user-error "Wrong `tramp-syntax' %s" value))
+ (tramp-user-error nil "Wrong `tramp-syntax' %s" value))
;; Cleanup existing buffers.
(unless (eq (symbol-value symbol) value)
(tramp-cleanup-all-buffers))
;; This function provides traces in case of errors not triggered by
;; Tramp functions.
(defun tramp-signal-hook-function (error-symbol data)
- "Funtion to be called via `signal-hook-function'."
- (tramp-error (car tramp-current-connection) error-symbol "%s" data))
+ "Function to be called via `signal-hook-function'."
+ ;; `custom-initialize-*' functions provoke `void-variable' errors.
+ ;; We don't want to see them in the backtrace.
+ (unless (eq error-symbol 'void-variable)
+ (tramp-error
+ (car tramp-current-connection) error-symbol
+ "%s" (mapconcat (lambda (x) (format "%s" x)) data " "))))
(defmacro with-parsed-tramp-file-name (filename var &rest body)
"Parse a Tramp filename and make components available in the body.
(defun tramp-handle-directory-files (directory &optional full match nosort)
"Like `directory-files' for Tramp files."
+ (unless (file-exists-p directory)
+ (tramp-error
+ (tramp-dissect-file-name directory) tramp-file-missing
+ "No such file or directory" directory))
(when (file-directory-p directory)
(setq directory (file-name-as-directory (expand-file-name directory)))
(let ((temp (nreverse (file-name-all-completions "" directory)))
;; Copy simple file.
(unwind-protect
(progn
+ (should-error
+ (copy-file source target)
+ :type tramp-file-missing)
(write-region "foo" nil source)
(should (file-exists-p source))
(copy-file source target)
;; Rename simple file.
(unwind-protect
(progn
+ (should-error
+ (rename-file source target)
+ :type tramp-file-missing)
(write-region "foo" nil source)
(should (file-exists-p source))
(rename-file source target)
(skip-unless (tramp--test-enabled))
(dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
- (let ((tmp-name (tramp--test-make-temp-name nil quoted)))
+ (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted))
+ (tmp-name2 (expand-file-name "foo" tmp-name1)))
;; Delete empty directory.
- (make-directory tmp-name)
- (should (file-directory-p tmp-name))
- (delete-directory tmp-name)
- (should-not (file-directory-p tmp-name))
+ (make-directory tmp-name1)
+ (should (file-directory-p tmp-name1))
+ (delete-directory tmp-name1)
+ (should-not (file-directory-p tmp-name1))
;; Delete non-empty directory.
- (make-directory tmp-name)
- (should (file-directory-p tmp-name))
- (write-region "foo" nil (expand-file-name "bla" tmp-name))
- (should (file-exists-p (expand-file-name "bla" tmp-name)))
- (should-error (delete-directory tmp-name) :type 'file-error)
- (delete-directory tmp-name 'recursive)
- (should-not (file-directory-p tmp-name)))))
+ (make-directory tmp-name1)
+ (should (file-directory-p tmp-name1))
+ (write-region "foo" nil (expand-file-name "bla" tmp-name1))
+ (should (file-exists-p (expand-file-name "bla" tmp-name1)))
+ (make-directory tmp-name2)
+ (should (file-directory-p tmp-name2))
+ (write-region "foo" nil (expand-file-name "bla" tmp-name2))
+ (should (file-exists-p (expand-file-name "bla" tmp-name2)))
+ (should-error (delete-directory tmp-name1) :type 'file-error)
+ (delete-directory tmp-name1 'recursive)
+ (should-not (file-directory-p tmp-name1)))))
(ert-deftest tramp-test15-copy-directory ()
"Check `copy-directory'."
;; Copy complete directory.
(unwind-protect
(progn
+ (should-error
+ (copy-directory tmp-name1 tmp-name2)
+ :type tramp-file-missing)
;; Copy empty directory.
(make-directory tmp-name1)
(write-region "foo" nil tmp-name4)
(tmp-name3 (expand-file-name "foo" tmp-name1)))
(unwind-protect
(progn
+ (should-error
+ (directory-files tmp-name1)
+ :type tramp-file-missing)
(make-directory tmp-name1)
(write-region "foo" nil tmp-name2)
(write-region "bla" nil tmp-name3)
attr)
(unwind-protect
(progn
+ (should-error
+ (directory-files-and-attributes tmp-name1)
+ :type tramp-file-missing)
(make-directory tmp-name1)
(should (file-directory-p tmp-name1))
(setq tramp--test-start-time