Commit 3b30ccda authored by Michael Albinus's avatar Michael Albinus

* net/tramp.el (with-progress-reporter): Create reporter object

only when the message would be displayed.  Handled nested calls.
(tramp-handle-load, tramp-handle-file-local-copy)
(tramp-handle-insert-file-contents, tramp-handle-write-region)
(tramp-maybe-send-script, tramp-find-shell): Use
`with-progress-reporter'.
(tramp-handle-dired-compress-file, tramp-maybe-open-connection):
Fix message text.

* net/tramp-smb.el (tramp-smb-handle-copy-file)
(tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file)
(tramp-smb-handle-write-region, tramp-smb-maybe-open-connection):
Use `with-progress-reporter'.
parent 41d81b80
2010-05-13 Michael Albinus <michael.albinus@gmx.de>
* net/tramp.el (with-progress-reporter): Create reporter object
only when the message would be displayed. Handled nested calls.
(tramp-handle-load, tramp-handle-file-local-copy)
(tramp-handle-insert-file-contents, tramp-handle-write-region)
(tramp-maybe-send-script, tramp-find-shell): Use
`with-progress-reporter'.
(tramp-handle-dired-compress-file, tramp-maybe-open-connection):
Fix message text.
* net/tramp-smb.el (tramp-smb-handle-copy-file)
(tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file)
(tramp-smb-handle-write-region, tramp-smb-maybe-open-connection):
Use `with-progress-reporter'.
2010-05-13 Agustín Martín <agustin.martin@hispalinux.es>
* ispell.el (ispell-init-process): Do not kill ispell process
......
......@@ -334,41 +334,41 @@ KEEP-DATE is not handled in case NEWNAME resides on an SMB server.
PRESERVE-UID-GID is completely ignored."
(setq filename (expand-file-name filename)
newname (expand-file-name newname))
(with-progress-reporter
(tramp-dissect-file-name (if (file-remote-p filename) filename newname))
0 (format "Copying %s to %s" filename newname)
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
;; Remote filename.
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
(tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
(when (file-directory-p newname)
(setq newname
(expand-file-name (file-name-nondirectory filename) newname)))
(with-parsed-tramp-file-name newname nil
(when (and (not ok-if-already-exists)
(file-exists-p newname))
(tramp-error v 'file-already-exists newname))
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
;; Remote filename.
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
(tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
(when (file-directory-p newname)
(setq newname (expand-file-name
(file-name-nondirectory filename) newname)))
(with-parsed-tramp-file-name newname nil
(when (and (not ok-if-already-exists)
(file-exists-p newname))
(tramp-error v 'file-already-exists newname))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)
(unless (tramp-smb-get-share v)
(tramp-error
v 'file-error "Target `%s' must contain a share name" newname))
(tramp-message v 0 "Copying file %s to file %s..." filename newname)
(if (tramp-smb-send-command
v (format "put \"%s\" \"%s\""
filename (tramp-smb-get-localname v)))
(tramp-message
v 0 "Copying file %s to file %s...done" filename newname)
(tramp-error v 'file-error "Cannot copy `%s'" filename)))))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)
(unless (tramp-smb-get-share v)
(tramp-error
v 'file-error "Target `%s' must contain a share name" newname))
(unless (tramp-smb-send-command
v (format "put \"%s\" \"%s\""
filename (tramp-smb-get-localname v)))
(tramp-error v 'file-error "Cannot copy `%s'" filename))))))
;; KEEP-DATE handling.
(when keep-date (set-file-times newname (nth 5 (file-attributes filename)))))
......@@ -605,15 +605,15 @@ PRESERVE-UID-GID is completely ignored."
v 'file-error
"Cannot make local copy of non-existing file `%s'" filename))
(let ((tmpfile (tramp-compat-make-temp-file filename)))
(tramp-message v 4 "Fetching %s to tmp file %s..." filename tmpfile)
(if (tramp-smb-send-command
v (format "get \"%s\" \"%s\"" (tramp-smb-get-localname v) tmpfile))
(tramp-message
v 4 "Fetching %s to tmp file %s...done" filename tmpfile)
;; Oops, an error. We shall cleanup.
(tramp-compat-delete-file tmpfile 'force)
(tramp-error
v 'file-error "Cannot make local copy of file `%s'" filename))
(with-progress-reporter
v 3 (format "Fetching %s to tmp file %s" filename tmpfile)
(unless (tramp-smb-send-command
v (format "get \"%s\" \"%s\""
(tramp-smb-get-localname v) tmpfile))
;; Oops, an error. We shall cleanup.
(tramp-compat-delete-file tmpfile 'force)
(tramp-error
v 'file-error "Cannot make local copy of file `%s'" filename)))
tmpfile)))
;; This function should return "foo/" for directories and "bar" for
......@@ -850,38 +850,39 @@ target of the symlink differ."
"Like `rename-file' for Tramp files."
(setq filename (expand-file-name filename)
newname (expand-file-name newname))
(with-progress-reporter
(tramp-dissect-file-name (if (file-remote-p filename) filename newname))
0 (format "Renaming %s to %s" filename newname)
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
;; Remote filename.
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
(tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
(when (file-directory-p newname)
(setq newname (expand-file-name
(file-name-nondirectory filename) newname)))
(with-parsed-tramp-file-name newname nil
(when (and (not ok-if-already-exists)
(file-exists-p newname))
(tramp-error v 'file-already-exists newname))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)
(unless (tramp-smb-send-command
v (format "put %s \"%s\""
filename (tramp-smb-get-localname v)))
(tramp-error v 'file-error "Cannot rename `%s'" filename)))))
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
;; Remote filename.
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
(tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
(when (file-directory-p newname)
(setq newname (expand-file-name
(file-name-nondirectory filename) newname)))
(with-parsed-tramp-file-name newname nil
(when (and (not ok-if-already-exists)
(file-exists-p newname))
(tramp-error v 'file-already-exists newname))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)
(tramp-message v 0 "Copying file %s to file %s..." filename newname)
(if (tramp-smb-send-command
v (format "put %s \"%s\"" filename (tramp-smb-get-localname v)))
(tramp-message
v 0 "Copying file %s to file %s...done" filename newname)
(tramp-error v 'file-error "Cannot rename `%s'" filename)))))
(tramp-compat-delete-file filename 'force))
(tramp-compat-delete-file filename 'force)))
(defun tramp-smb-handle-set-file-modes (filename mode)
"Like `set-file-modes' for Tramp files."
......@@ -938,14 +939,14 @@ errors for shares like \"C$/\", which are common in Microsoft Windows."
(list start end tmpfile append 'no-message lockname confirm)
(list start end tmpfile append 'no-message lockname)))
(tramp-message v 5 "Writing tmp file %s to file %s..." tmpfile filename)
(unwind-protect
(if (tramp-smb-send-command
v (format "put %s \"%s\"" tmpfile (tramp-smb-get-localname v)))
(tramp-message
v 5 "Writing tmp file %s to file %s...done" tmpfile filename)
(tramp-error v 'file-error "Cannot write `%s'" filename))
(tramp-compat-delete-file tmpfile 'force))
(with-progress-reporter
v 3 (format "Moving tmp file %s to %s" tmpfile filename)
(unwind-protect
(unless (tramp-smb-send-command
v (format "put %s \"%s\""
tmpfile (tramp-smb-get-localname v)))
(tramp-error v 'file-error "Cannot write `%s'" filename))
(tramp-compat-delete-file tmpfile 'force)))
(unless (equal curbuf (current-buffer))
(tramp-error
......@@ -1302,60 +1303,57 @@ connection if a previous connection has died for some reason."
(setq args (append args (list "-s" tramp-smb-conf))))
;; OK, let's go.
(tramp-message
vec 3 "Opening connection for //%s%s/%s..."
(if (not (zerop (length user))) (concat user "@") "")
host (or share ""))
(let* ((coding-system-for-read nil)
(process-connection-type tramp-process-connection-type)
(p (let ((default-directory
(tramp-compat-temporary-file-directory)))
(apply #'start-process
(tramp-buffer-name vec) (tramp-get-buffer vec)
tramp-smb-program args))))
(tramp-message
vec 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-process-query-on-exit-flag p nil)
;; Set variables for computing the prompt for reading password.
(setq tramp-current-method tramp-smb-method
tramp-current-user user
tramp-current-host host)
;; Play login scenario.
(tramp-process-actions
p vec
(if share
tramp-smb-actions-with-share
tramp-smb-actions-without-share))
;; Check server version.
(with-current-buffer (tramp-get-connection-buffer vec)
(goto-char (point-min))
(search-forward-regexp
"Domain=\\[[^]]*\\] OS=\\[[^]]*\\] Server=\\[[^]]*\\]" nil t)
(let ((smbserver-version (match-string 0)))
(unless
(string-equal
smbserver-version
(tramp-get-connection-property
vec "smbserver-version" smbserver-version))
(tramp-flush-directory-property vec "")
(tramp-flush-connection-property vec))
(tramp-set-connection-property
vec "smbserver-version" smbserver-version)))
;; Set chunksize. Otherwise, `tramp-send-string' might
;; try it itself.
(tramp-set-connection-property p "smb-share" share)
(tramp-set-connection-property p "chunksize" tramp-chunksize)
(tramp-message
vec 3 "Opening connection for //%s%s/%s...done"
(if (not (zerop (length user))) (concat user "@") "")
host (or share ""))))))))
(with-progress-reporter
vec 3
(format "Opening connection for //%s%s/%s"
(if (not (zerop (length user))) (concat user "@") "")
host (or share ""))
(let* ((coding-system-for-read nil)
(process-connection-type tramp-process-connection-type)
(p (let ((default-directory
(tramp-compat-temporary-file-directory)))
(apply #'start-process
(tramp-buffer-name vec) (tramp-get-buffer vec)
tramp-smb-program args))))
(tramp-message
vec 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-process-query-on-exit-flag p nil)
;; Set variables for computing the prompt for reading password.
(setq tramp-current-method tramp-smb-method
tramp-current-user user
tramp-current-host host)
;; Play login scenario.
(tramp-process-actions
p vec
(if share
tramp-smb-actions-with-share
tramp-smb-actions-without-share))
;; Check server version.
(with-current-buffer (tramp-get-connection-buffer vec)
(goto-char (point-min))
(search-forward-regexp
"Domain=\\[[^]]*\\] OS=\\[[^]]*\\] Server=\\[[^]]*\\]" nil t)
(let ((smbserver-version (match-string 0)))
(unless
(string-equal
smbserver-version
(tramp-get-connection-property
vec "smbserver-version" smbserver-version))
(tramp-flush-directory-property vec "")
(tramp-flush-connection-property vec))
(tramp-set-connection-property
vec "smbserver-version" smbserver-version)))
;; Set chunksize. Otherwise, `tramp-send-string' might
;; try it itself.
(tramp-set-connection-property p "smb-share" share)
(tramp-set-connection-property
p "chunksize" tramp-chunksize))))))))
;; We don't use timeouts. If needed, the caller shall wrap around.
(defun tramp-smb-wait-for-output (vec)
......
......@@ -2271,14 +2271,18 @@ FILE must be a local file name on a connection identified via VEC."
(tramp-message ,vec ,level "%s..." ,message)
;; We start a pulsing progress reporter after 3 seconds. Feature
;; introduced in Emacs 24.1.
(when (<= ,level tramp-verbose)
(when (and tramp-message-show-message
;; Display only when there is a minimum level.
(<= ,level (min tramp-verbose 3)))
(condition-case nil
(setq pr (tramp-compat-funcall 'make-progress-reporter ,message)
tm (if pr (run-at-time 3 0.1 'progress-reporter-update pr)))
(error nil)))
(unwind-protect
;; Execute the body.
(progn ,@body)
(let ((tramp-message-show-message
(and tramp-message-show-message (not tm))))
,@body)
;; Stop progress reporter.
(if tm (tramp-compat-funcall 'cancel-timer tm))
(tramp-message ,vec ,level "%s...done" ,message))))
......@@ -2558,13 +2562,13 @@ target of the symlink differ."
(tramp-error v 'file-error "Cannot load nonexistent file `%s'" file)))
(if (not (file-exists-p file))
nil
(unless nomessage (tramp-message v 0 "Loading %s..." file))
(let ((local-copy (file-local-copy file)))
;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
(unwind-protect
(load local-copy noerror t t)
(tramp-compat-delete-file local-copy 'force)))
(unless nomessage (tramp-message v 0 "Loading %s...done" file))
(let ((tramp-message-show-message (not nomessage)))
(with-progress-reporter v 0 (format "Loading %s" file)
(let ((local-copy (file-local-copy file)))
;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
(unwind-protect
(load local-copy noerror t t)
(tramp-compat-delete-file local-copy 'force)))))
t)))
;; Localname manipulation functions that grok Tramp localnames...
......@@ -4153,7 +4157,7 @@ This is like `dired-recursive-delete-directory' for Tramp files."
nil)
((and suffix (nth 2 suffix))
;; We found an uncompression rule.
(with-progress-reporter v 0 (format "Uncompressing %s..." file)
(with-progress-reporter v 0 (format "Uncompressing %s" file)
(when (zerop
(tramp-send-command-and-check
v (concat (nth 2 suffix) " "
......@@ -4165,7 +4169,7 @@ This is like `dired-recursive-delete-directory' for Tramp files."
(t
;; We don't recognize the file as compressed, so compress it.
;; Try gzip.
(with-progress-reporter v 0 (format "Compressing %s..." file)
(with-progress-reporter v 0 (format "Compressing %s" file)
(when (zerop
(tramp-send-command-and-check
v (concat "gzip -f "
......@@ -4747,11 +4751,11 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
;; Use inline encoding for file transfer.
(rem-enc
(save-excursion
(tramp-message v 5 "Encoding remote file %s..." filename)
(tramp-barf-unless-okay
v (format rem-enc (tramp-shell-quote-argument localname))
"Encoding remote file failed")
(tramp-message v 5 "Encoding remote file %s...done" filename)
(with-progress-reporter
v 5 (format "Encoding remote file %s" filename)
(tramp-barf-unless-okay
v (format rem-enc (tramp-shell-quote-argument localname))
"Encoding remote file failed"))
(if (functionp loc-dec)
;; If local decoding is a function, we call it. We
......@@ -4761,15 +4765,15 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
(with-temp-buffer
(set-buffer-multibyte nil)
(insert-buffer-substring (tramp-get-buffer v))
(tramp-message
v 5 "Decoding remote file %s with function %s..."
filename loc-dec)
(funcall loc-dec (point-min) (point-max))
;; Unset `file-name-handler-alist'. Otherwise,
;; epa-file gets confused.
(let (file-name-handler-alist
(coding-system-for-write 'binary))
(write-region (point-min) (point-max) tmpfile)))
(with-progress-reporter
v 3 (format "Decoding remote file %s with function %s"
filename loc-dec)
(funcall loc-dec (point-min) (point-max))
;; Unset `file-name-handler-alist'. Otherwise,
;; epa-file gets confused.
(let (file-name-handler-alist
(coding-system-for-write 'binary))
(write-region (point-min) (point-max) tmpfile))))
;; If tramp-decoding-function is not defined for this
;; method, we invoke tramp-decoding-command instead.
......@@ -4779,14 +4783,14 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
(let (file-name-handler-alist
(coding-system-for-write 'binary))
(write-region (point-min) (point-max) tmpfile2))
(tramp-message
v 5 "Decoding remote file %s with command %s..."
filename loc-dec)
(unwind-protect
(tramp-call-local-coding-command loc-dec tmpfile2 tmpfile)
(tramp-compat-delete-file tmpfile2 'force))))
(with-progress-reporter
v 3 (format "Decoding remote file %s with command %s"
filename loc-dec)
(unwind-protect
(tramp-call-local-coding-command
loc-dec tmpfile2 tmpfile)
(tramp-compat-delete-file tmpfile2 'force)))))
(tramp-message v 5 "Decoding remote file %s...done" filename)
;; Set proper permissions.
(set-file-modes tmpfile (tramp-default-file-modes filename))
;; Set local user ownership.
......@@ -4842,7 +4846,7 @@ coding system might not be determined. This function repairs it."
"Like `insert-file-contents' for Tramp files."
(barf-if-buffer-read-only)
(setq filename (expand-file-name filename))
(let (coding-system-used result local-copy remote-copy)
(let (result local-copy remote-copy)
(with-parsed-tramp-file-name filename nil
(unwind-protect
(if (not (file-exists-p filename))
......@@ -4913,27 +4917,16 @@ coding system might not be determined. This function repairs it."
(setq tramp-temp-buffer-file-name local-copy)
(put 'tramp-temp-buffer-file-name 'permanent-local t))
(tramp-message
v 4 "Inserting local temp file `%s'..." local-copy)
;; We must ensure that `file-coding-system-alist'
;; matches `local-copy'.
(let ((file-coding-system-alist
(tramp-find-file-name-coding-system-alist
filename local-copy)))
(setq result
(insert-file-contents
local-copy nil nil nil replace))
;; Now `last-coding-system-used' has right value.
;; Remember it.
(when (boundp 'last-coding-system-used)
(setq coding-system-used
(symbol-value 'last-coding-system-used))))
(tramp-message
v 4 "Inserting local temp file `%s'...done" local-copy)
(when (boundp 'last-coding-system-used)
(set 'last-coding-system-used coding-system-used))))
(with-progress-reporter
v 3 (format "Inserting local temp file `%s'" local-copy)
;; We must ensure that `file-coding-system-alist'
;; matches `local-copy'.
(let ((file-coding-system-alist
(tramp-find-file-name-coding-system-alist
filename local-copy)))
(setq result
(insert-file-contents
local-copy nil nil nil replace))))))
;; Save exit.
(progn
......@@ -5193,15 +5186,14 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
;; Use inline file transfer.
(rem-dec
;; Encode tmpfile.
(tramp-message v 5 "Encoding region...")
(unwind-protect
(with-temp-buffer
(set-buffer-multibyte nil)
;; Use encoding function or command.
(if (functionp loc-enc)
(progn
(tramp-message
v 5 "Encoding region using function `%s'..." loc-enc)
(with-progress-reporter
v 3 (format "Encoding region using function `%s'"
loc-enc)
(let ((coding-system-for-read 'binary))
(insert-file-contents-literally tmpfile))
;; The following `let' is a workaround for the
......@@ -5217,59 +5209,61 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
(tramp-compat-temporary-file-directory)))
(funcall loc-enc (point-min) (point-max))))
(tramp-message
v 5 "Encoding region using command `%s'..." loc-enc)
(unless (zerop (tramp-call-local-coding-command
loc-enc tmpfile t))
(tramp-error
v 'file-error
"Cannot write to `%s', local encoding command `%s' failed"
filename loc-enc)))
(with-progress-reporter
v 3 (format "Encoding region using command `%s'"
loc-enc)
(unless (zerop (tramp-call-local-coding-command
loc-enc tmpfile t))
(tramp-error
v 'file-error
(concat "Cannot write to `%s', "
"local encoding command `%s' failed")
filename loc-enc))))
;; Send buffer into remote decoding command which
;; writes to remote file. Because this happens on
;; the remote host, we cannot use the function.
(goto-char (point-max))
(unless (bolp) (newline))
(tramp-message
v 5 "Decoding region into remote file %s..." filename)
(tramp-send-command
v
(format
(concat rem-dec " <<'EOF'\n%sEOF")
(tramp-shell-quote-argument localname)
(buffer-string)))
(tramp-barf-unless-okay
v nil
"Couldn't write region to `%s', decode using `%s' failed"
filename rem-dec)
;; When `file-precious-flag' is set, the region is
;; written to a temporary file. Check that the
;; checksum is equal to that from the local tmpfile.
(when file-precious-flag
(erase-buffer)
(and
;; cksum runs locally, if possible.
(zerop (tramp-local-call-process "cksum" tmpfile t))
;; cksum runs remotely.
(zerop
(tramp-send-command-and-check
v
(format
"cksum <%s" (tramp-shell-quote-argument localname))))
;; ... they are different.
(not
(string-equal
(buffer-string)
(with-current-buffer (tramp-get-buffer v)
(buffer-string))))
(tramp-error
v 'file-error
(concat "Couldn't write region to `%s',"
" decode using `%s' failed")
filename rem-dec)))
(tramp-message
v 5 "Decoding region into remote file %s...done" filename))
(with-progress-reporter
v 3
(format "Decoding region into remote file %s" filename)
(goto-char (point-max))
(unless (bolp) (newline))
(tramp-send-command
v
(format
(concat rem-dec " <<'EOF'\n%sEOF")
(tramp-shell-quote-argument localname)
(buffer-string)))
(tramp-barf-unless-okay
v nil
"Couldn't write region to `%s', decode using `%s' failed"
filename rem-dec)
;; When `file-precious-flag' is set, the region is
;; written to a temporary file. Check that the
;; checksum is equal to that from the local tmpfile.
(when file-precious-flag
(erase-buffer)
(and
;; cksum runs locally, if possible.
(zerop (tramp-local-call-process "cksum" tmpfile t))
;; cksum runs remotely.
(zerop
(tramp-send-command-and-check
v
(format
"cksum <%s"
(tramp-shell-quote-argument localname))))
;; ... they are different.
(not
(string-equal
(buffer-string)
(with-current-buffer (tramp-get-buffer v)
(buffer-string))))