unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Bugfix and improved error handling
@ 2006-11-21 19:22 Lars Hansen
  2006-11-23 21:48 ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Hansen @ 2006-11-21 19:22 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

The attached patch has improved error handling for out-of-band copying
and some bug fixes.
The changes are:

1. Give error message "permission denied"/"not a regular file"/"no such
file or directory" rather than the misleading "login failed" when
appropriate.
2. Also kill the copy program buffer when an error occurs (bugfix).
3. Use pscp as default method under windows.

Objections?


[-- Attachment #2: tramp.diff --]
[-- Type: text/x-patch, Size: 7045 bytes --]

*** /home/lh/cvsroot/emacs/lisp/net/tramp.el	2006-11-18 19:48:32.000000000 +0100
--- tramp.el	2006-11-21 20:05:28.000000000 +0100
***************
*** 673,680 ****
  
  (defcustom tramp-default-method
    (if (and (fboundp 'executable-find)
! 	   (executable-find "plink"))
!       "plink"
      "scp")
    "*Default method to use for transferring files.
  See `tramp-methods' for possibilities.
--- 673,680 ----
  
  (defcustom tramp-default-method
    (if (and (fboundp 'executable-find)
! 	   (executable-find "pscp"))
!       "pscp"
      "scp")
    "*Default method to use for transferring files.
  See `tramp-methods' for possibilities.
***************
*** 1327,1351 ****
  Whenever a pattern matches, the corresponding action is performed.
  Each item looks like (PATTERN ACTION).
  
! The PATTERN should be a symbol, a variable.  The value of this
! variable gives the regular expression to search for.  Note that the
! regexp must match at the end of the buffer, \"\\'\" is implicitly
! appended to it.
  
! The ACTION should also be a symbol, but a function.  When the
! corresponding PATTERN matches, the ACTION function is called."
    :group 'tramp
!   :type '(repeat (list variable function)))
  
  (defcustom tramp-actions-copy-out-of-band
    '((tramp-password-prompt-regexp tramp-action-password)
      (tramp-wrong-passwd-regexp tramp-action-permission-denied)
      (tramp-process-alive-regexp tramp-action-out-of-band))
    "List of pattern/action pairs.
  This list is used for copying/renaming with out-of-band methods.
  See `tramp-actions-before-shell' for more info."
    :group 'tramp
!   :type '(repeat (list variable function)))
  
  (defcustom tramp-multi-actions
    '((tramp-password-prompt-regexp tramp-multi-action-password)
--- 1327,1354 ----
  Whenever a pattern matches, the corresponding action is performed.
  Each item looks like (PATTERN ACTION).
  
! The PATTERN should be a form.  This form must evaluate to a
! regular expression to search for.  Note that the regexp must match
! at the end of the buffer except for trailing blanks. When PATTERN
! is evaluated, the symbols `method', `user' and `host' are bound.
  
! The ACTION should be a symbol, a function.  When the corresponding
! PATTERN matches, the ACTION function is called."
    :group 'tramp
!   :type '(repeat (list form function)))
  
  (defcustom tramp-actions-copy-out-of-band
    '((tramp-password-prompt-regexp tramp-action-password)
      (tramp-wrong-passwd-regexp tramp-action-permission-denied)
+     ("\\(.+: Permission denied\\)" tramp-action-copy-failed)
+     ("\\(.+: \\(not a regular file\\|is a directory\\)\\)" tramp-action-copy-failed)
+     ("\\(.+: No such file or directory\\)" tramp-action-copy-failed)
      (tramp-process-alive-regexp tramp-action-out-of-band))
    "List of pattern/action pairs.
  This list is used for copying/renaming with out-of-band methods.
  See `tramp-actions-before-shell' for more info."
    :group 'tramp
!   :type '(repeat (list form function)))
  
  (defcustom tramp-multi-actions
    '((tramp-password-prompt-regexp tramp-multi-action-password)
***************
*** 1358,1364 ****
  This list is used for each hop in multi-hop connections.
  See `tramp-actions-before-shell' for more info."
    :group 'tramp
!   :type '(repeat (list variable function)))
  
  (defcustom tramp-initial-commands
    '("unset HISTORY"
--- 1361,1367 ----
  This list is used for each hop in multi-hop connections.
  See `tramp-actions-before-shell' for more info."
    :group 'tramp
!   :type '(repeat (list form function)))
  
  (defcustom tramp-initial-commands
    '("unset HISTORY"
***************
*** 3174,3185 ****
        (message "Transferring %s to %s..." filename newname)
  
        ;; Use rcp-like program for file transfer.
!       (let ((p (apply 'start-process (buffer-name trampbuf) trampbuf
! 		      copy-program copy-args)))
! 	(tramp-set-process-query-on-exit-flag p nil)
! 	(tramp-process-actions p multi-method method user host
! 			       tramp-actions-copy-out-of-band))
!       (kill-buffer trampbuf)
        (message "Transferring %s to %s...done" filename newname)
  
        ;; Set the mode.
--- 3177,3189 ----
        (message "Transferring %s to %s..." filename newname)
  
        ;; Use rcp-like program for file transfer.
!       (unwind-protect
!           (let ((p (apply 'start-process (buffer-name trampbuf) trampbuf
!                           copy-program copy-args)))
!             (tramp-set-process-query-on-exit-flag p nil)
!             (tramp-process-actions p multi-method method user host
!                                    tramp-actions-copy-out-of-band))
!         (kill-buffer trampbuf))
        (message "Transferring %s to %s...done" filename newname)
  
        ;; Set the mode.
***************
*** 5353,5358 ****
--- 5357,5367 ----
    (kill-process p)
    (throw 'tramp-action 'permission-denied))
  
+ (defun tramp-action-copy-failed (p multi-method method user host)
+   "Signal copy failed."
+   (kill-process p)
+   (error "%s" (match-string 1)))
+ 
  (defun tramp-action-yesno (p multi-method method user host)
    "Ask the user for confirmation using `yes-or-no-p'.
  Send \"yes\" to remote process on confirmation, abort otherwise.
***************
*** 5409,5417 ****
  	       (tramp-message 10 "'set mode' error ignored.")
  	       (tramp-message 9 "Process has finished.")
  	       (throw 'tramp-action 'ok))
- 	   (goto-char (point-min))
- 	   (when (re-search-forward "^.cp.?: \\(.+: Permission denied.?\\)$" nil t)
- 	     (error "Remote host: %s" (match-string 1)))
  	   (tramp-message 9 "Process has died.")
  	   (throw 'tramp-action 'process-died)))
  	(t nil)))
--- 5418,5423 ----
***************
*** 5466,5476 ****
  	(while todo
  	  (goto-char (point-min))
  	  (setq item (pop todo))
! 	  (setq pattern (symbol-value (nth 0 item)))
  	  (setq action (nth 1 item))
  	  (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
  			 pattern)
! 	  (when (re-search-forward (concat pattern "\\'") nil t)
  	    (setq found (funcall action p multi-method method user host)))))
        found)))
  
--- 5472,5482 ----
  	(while todo
  	  (goto-char (point-min))
  	  (setq item (pop todo))
! 	  (setq pattern (eval (nth 0 item)))
  	  (setq action (nth 1 item))
  	  (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
  			 pattern)
! 	  (when (re-search-forward (concat pattern "[ \t\n]*\\'") nil t)
  	    (setq found (funcall action p multi-method method user host)))))
        found)))
  
***************
*** 5503,5509 ****
  	(while todo
  	  (goto-char (point-min))
  	  (setq item (pop todo))
! 	  (setq pattern (symbol-value (nth 0 item)))
  	  (setq action (nth 1 item))
  	  (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
  			 pattern)
--- 5509,5515 ----
  	(while todo
  	  (goto-char (point-min))
  	  (setq item (pop todo))
! 	  (setq pattern (eval (nth 0 item)))
  	  (setq action (nth 1 item))
  	  (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
  			 pattern)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bugfix and improved error handling
  2006-11-21 19:22 Bugfix and improved error handling Lars Hansen
@ 2006-11-23 21:48 ` Michael Albinus
  2006-11-24 16:28   ` Lars Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Albinus @ 2006-11-23 21:48 UTC (permalink / raw)
  Cc: emacs-devel

Lars Hansen <lists@soem.dk> writes:

Hi Lars,

> The attached patch has improved error handling for out-of-band copying
> and some bug fixes.
> The changes are:
>
> 1. Give error message "permission denied"/"not a regular file"/"no such
> file or directory" rather than the misleading "login failed" when
> appropriate.
> 2. Also kill the copy program buffer when an error occurs (bugfix).
> 3. Use pscp as default method under windows.
>
> Objections?

In general the patch looks OK to me.

> --- 1327,1354 ----
>   Whenever a pattern matches, the corresponding action is performed.
>   Each item looks like (PATTERN ACTION).
>   
> ! The PATTERN should be a form.  This form must evaluate to a
> ! regular expression to search for.  Note that the regexp must match
> ! at the end of the buffer except for trailing blanks. When PATTERN
> ! is evaluated, the symbols `method', `user' and `host' are bound.
>   
> ! The ACTION should be a symbol, a function.  When the corresponding
> ! PATTERN matches, the ACTION function is called."
>     :group 'tramp
> !   :type '(repeat (list form function)))
>   
>   (defcustom tramp-actions-copy-out-of-band
>     '((tramp-password-prompt-regexp tramp-action-password)
>       (tramp-wrong-passwd-regexp tramp-action-permission-denied)
> +     ("\\(.+: Permission denied\\)" tramp-action-copy-failed)
> +     ("\\(.+: \\(not a regular file\\|is a directory\\)\\)" tramp-action-copy-failed)
> +     ("\\(.+: No such file or directory\\)" tramp-action-copy-failed)

Why didn't you introduce a new variable tramp-copy-failed-regexp? This
would make the code more readable, and it would avoid several changes.

> --- 5472,5482 ----
>   	(while todo
>   	  (goto-char (point-min))
>   	  (setq item (pop todo))
> ! 	  (setq pattern (eval (nth 0 item)))
>   	  (setq action (nth 1 item))
>   	  (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
>   			 pattern)
> ! 	  (when (re-search-forward (concat pattern "[ \t\n]*\\'") nil t)
>   	    (setq found (funcall action p multi-method method user host)))))
>         found)))

I don't know whether it is possible to cut trailing newlines in
general. Some existing regexps claim "The regexp should match at end
of buffer." Likely you are right in your change, but then you could
remove trailing "\\s-*" from several regexps. It would be more
consistent.

Best regards, Michael.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bugfix and improved error handling
  2006-11-23 21:48 ` Michael Albinus
@ 2006-11-24 16:28   ` Lars Hansen
  2006-11-24 17:35     ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Hansen @ 2006-11-24 16:28 UTC (permalink / raw)
  Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]


>Why didn't you introduce a new variable tramp-copy-failed-regexp? This
>would make the code more readable, and it would avoid several changes.
>  
>
I didn't want to clobber the name space, but I agree that adding a
variable makes my change more consistent with the rest of tramp.

>I don't know whether it is possible to cut trailing newlines in
>general. Some existing regexps claim "The regexp should match at end
>of buffer."
>
Then we better not change it.

My patch, whit your change suggestions is attached.


[-- Attachment #2: tramp.diff --]
[-- Type: text/x-patch, Size: 3740 bytes --]

*** /home/lh/cvsroot/emacs/lisp/net/tramp.el	2006-11-18 19:39:04.000000000 +0100
--- tramp.el	2006-11-24 16:58:24.000000000 +0100
***************
*** 673,680 ****
  
  (defcustom tramp-default-method
    (if (and (fboundp 'executable-find)
! 	   (executable-find "plink"))
!       "plink"
      "scp")
    "*Default method to use for transferring files.
  See `tramp-methods' for possibilities.
--- 673,680 ----
  
  (defcustom tramp-default-method
    (if (and (fboundp 'executable-find)
! 	   (executable-find "pscp"))
!       "pscp"
      "scp")
    "*Default method to use for transferring files.
  See `tramp-methods' for possibilities.
***************
*** 943,948 ****
--- 943,959 ----
    :group 'tramp
    :type 'regexp)
  
+ (defcustom tramp-copy-failed-regexp
+   (concat "\\(.+: "
+           (regexp-opt '("Permission denied"
+                         "not a regular file"
+                         "is a directory"
+                         "No such file or directory") t)
+           "\\)\\s-*")
+   "Regular expression matching copy problems in (s)cp operations."
+   :group 'tramp
+   :type 'regexp)
+ 
  (defcustom tramp-process-alive-regexp
    ""
    "Regular expression indicating a process has finished.
***************
*** 1340,1345 ****
--- 1351,1357 ----
  (defcustom tramp-actions-copy-out-of-band
    '((tramp-password-prompt-regexp tramp-action-password)
      (tramp-wrong-passwd-regexp tramp-action-permission-denied)
+     (tramp-copy-failed-regexp tramp-action-copy-failed)
      (tramp-process-alive-regexp tramp-action-out-of-band))
    "List of pattern/action pairs.
  This list is used for copying/renaming with out-of-band methods.
***************
*** 3174,3185 ****
        (message "Transferring %s to %s..." filename newname)
  
        ;; Use rcp-like program for file transfer.
!       (let ((p (apply 'start-process (buffer-name trampbuf) trampbuf
! 		      copy-program copy-args)))
! 	(tramp-set-process-query-on-exit-flag p nil)
! 	(tramp-process-actions p multi-method method user host
! 			       tramp-actions-copy-out-of-band))
!       (kill-buffer trampbuf)
        (message "Transferring %s to %s...done" filename newname)
  
        ;; Set the mode.
--- 3186,3198 ----
        (message "Transferring %s to %s..." filename newname)
  
        ;; Use rcp-like program for file transfer.
!       (unwind-protect
!           (let ((p (apply 'start-process (buffer-name trampbuf) trampbuf
!                           copy-program copy-args)))
!             (tramp-set-process-query-on-exit-flag p nil)
!             (tramp-process-actions p multi-method method user host
!                                    tramp-actions-copy-out-of-band))
!         (kill-buffer trampbuf))
        (message "Transferring %s to %s...done" filename newname)
  
        ;; Set the mode.
***************
*** 5353,5358 ****
--- 5366,5376 ----
    (kill-process p)
    (throw 'tramp-action 'permission-denied))
  
+ (defun tramp-action-copy-failed (p multi-method method user host)
+   "Signal copy failed."
+   (kill-process p)
+   (error "%s" (match-string 1)))
+ 
  (defun tramp-action-yesno (p multi-method method user host)
    "Ask the user for confirmation using `yes-or-no-p'.
  Send \"yes\" to remote process on confirmation, abort otherwise.
***************
*** 5409,5417 ****
  	       (tramp-message 10 "'set mode' error ignored.")
  	       (tramp-message 9 "Process has finished.")
  	       (throw 'tramp-action 'ok))
- 	   (goto-char (point-min))
- 	   (when (re-search-forward "^.cp.?: \\(.+: Permission denied.?\\)$" nil t)
- 	     (error "Remote host: %s" (match-string 1)))
  	   (tramp-message 9 "Process has died.")
  	   (throw 'tramp-action 'process-died)))
  	(t nil)))
--- 5427,5432 ----

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bugfix and improved error handling
  2006-11-24 16:28   ` Lars Hansen
@ 2006-11-24 17:35     ` Michael Albinus
  2006-11-24 19:17       ` Lars Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Albinus @ 2006-11-24 17:35 UTC (permalink / raw)
  Cc: emacs-devel

Lars Hansen <lists@soem.dk> writes:

Hi Lars,

> My patch, whit your change suggestions is attached.

Looks OK to me. You might commit it to CVS; I'll sync later with Tramp CVS.

Thanks, and best regards, Michael.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bugfix and improved error handling
  2006-11-24 17:35     ` Michael Albinus
@ 2006-11-24 19:17       ` Lars Hansen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Hansen @ 2006-11-24 19:17 UTC (permalink / raw)
  Cc: emacs-devel


>Looks OK to me. You might commit it to CVS; I'll sync later with Tramp CVS.
>  
>
Done. Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-11-24 19:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-21 19:22 Bugfix and improved error handling Lars Hansen
2006-11-23 21:48 ` Michael Albinus
2006-11-24 16:28   ` Lars Hansen
2006-11-24 17:35     ` Michael Albinus
2006-11-24 19:17       ` Lars Hansen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).