+2010-05-05 Michael Albinus <michael.albinus@gmx.de>
+
+ Add FORCE argument to `delete-file'.
+
+ * net/ange-ftp.el (ange-ftp-del-tmp-name): Make it a defun,
+ forcing to delete the temporary file.
+ (ange-ftp-delete-file): Add FORCE arg.
+ (ange-ftp-rename-remote-to-remote)
+ (ange-ftp-rename-local-to-remote, ange-ftp-rename-remote-to-local)
+ (ange-ftp-load, ange-ftp-compress, ange-ftp-uncompress): Force
+ file deletion.
+
+ * net/tramp-compat.el (tramp-compat-delete-file): New defun.
+
+ * net/tramp.el (tramp-handle-delete-file): Add FORCE arg.
+ (tramp-handle-make-symbolic-link, tramp-handle-load)
+ (tramp-do-copy-or-rename-file-via-buffer)
+ (tramp-do-copy-or-rename-file-directly)
+ (tramp-do-copy-or-rename-file-out-of-band)
+ (tramp-handle-process-file, tramp-handle-call-process-region)
+ (tramp-handle-shell-command, tramp-handle-file-local-copy)
+ (tramp-handle-insert-file-contents, tramp-handle-write-region)
+ (tramp-delete-temp-file-function): Use `tramp-compat-delete-file'.
+
+ * net/tramp-fish.el (tramp-fish-handle-delete-file): Add FORCE arg.
+ (tramp-fish-handle-make-symbolic-link)
+ (tramp-fish-handle-process-file): Use `tramp-compat-delete-file'.
+
+ * net/tramp-ftp.el (tramp-ftp-file-name-handler): Use
+ `tramp-compat-delete-file'.
+
+ * net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Add FORCE arg.
+ (tramp-gvfs-handle-write-region): Use `tramp-compat-delete-file'.
+
+ * net/tramp-imap.el (tramp-imap-handle-delete-file): Add FORCE arg.
+ (tramp-imap-do-copy-or-rename-file): Use `tramp-compat-delete-file'.
+
+ * net/tramp-smb.el (tramp-smb-handle-delete-file): Add FORCE arg.
+ (tramp-smb-handle-copy-file, tramp-smb-handle-file-local-copy)
+ (tramp-smb-handle-rename-file, tramp-smb-handle-write-region): Use
+ `tramp-compat-delete-file'.
+
2010-05-05 Stefan Monnier <monnier@iro.umontreal.ca>
Minor cleanups.
ange-ftp-gateway-tmp-name-template
ange-ftp-tmp-name-template)))
-(defalias 'ange-ftp-del-tmp-name 'delete-file)
+(defun ange-ftp-del-tmp-name (filename)
+ "Force to delete temporary file."
+ (delete-file filename 'force))
+
\f
;;;; ------------------------------------------------------------
;;;; Interactive gateway program support.
(file-exists-p file)
(ange-ftp-real-file-executable-p file))))
-(defun ange-ftp-delete-file (file)
+(defun ange-ftp-delete-file (file &optional force)
(interactive "fDelete file: ")
(setq file (expand-file-name file))
(let ((parsed (ange-ftp-ftp-name file)))
(format "FTP Error: \"%s\"" (cdr result))
file)))
(ange-ftp-delete-file-entry file))
- (ange-ftp-real-delete-file file))))
+ (ange-ftp-real-delete-file file force))))
(defun ange-ftp-file-modtime (file)
"Return the modification time of remote file FILE.
(ange-ftp-add-file-entry newname)
(ange-ftp-delete-file-entry filename))
(ange-ftp-copy-file-internal filename newname t nil)
- (delete-file filename))))
+ (delete-file filename 'force))))
(defun ange-ftp-rename-local-to-remote (filename newname)
"Rename local file FILENAME to remote file NEWNAME."
(msg (format "Renaming %s to %s" fabbr nabbr)))
(ange-ftp-copy-file-internal filename newname t nil msg)
(let (ange-ftp-process-verbose)
- (delete-file filename))))
+ (delete-file filename 'force))))
(defun ange-ftp-rename-remote-to-local (filename newname)
"Rename remote file FILENAME to local file NEWNAME."
(msg (format "Renaming %s to %s" fabbr nabbr)))
(ange-ftp-copy-file-internal filename newname t nil msg)
(let (ange-ftp-process-verbose)
- (delete-file filename))))
+ (delete-file filename 'force))))
(defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists)
(interactive "fRename file: \nFRename %s to file: \np")
(if copy
(unwind-protect
(funcall 'load copy noerror nomessage nosuffix)
- (delete-file copy))
+ (delete-file copy 'force))
(or noerror
(signal 'file-error (list "Cannot open load file" file)))
nil))
(if (zerop (buffer-size))
(progn
(let (ange-ftp-process-verbose)
- (delete-file file))
+ (delete-file file 'force))
(ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
(ange-ftp-del-tmp-name tmp1)
(ange-ftp-del-tmp-name tmp2))))
(if (zerop (buffer-size))
(progn
(let (ange-ftp-process-verbose)
- (delete-file file))
+ (delete-file file 'force))
(ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
(ange-ftp-del-tmp-name tmp1)
(ange-ftp-del-tmp-name tmp2))))
(if keep-time
(set-file-times newname (nth 5 (file-attributes directory))))))))
+;; FORCE has been introduced with Emacs 24.1.
+(defun tramp-compat-delete-file (filename &optional force)
+ "Like `delete-file' for Tramp files (compat function)."
+ (condition-case nil
+ (funcall (symbol-function 'delete-file) filename force)
+ ;; This Emacs version does not support the FORCE flag. Setting
+ ;; `delete-by-moving-to-trash' shall give us the same effect.
+ (error
+ (let ((delete-by-moving-to-trash (null force)))
+ (delete-file filename)))))
+
;; RECURSIVE has been introduced with Emacs 23.2.
(defun tramp-compat-delete-directory (directory &optional recursive)
"Like `delete-directory' for Tramp files (compat function)."
(tramp-flush-directory-property v localname)
(tramp-fish-send-command-and-check v (format "#RMD %s" localname)))))
-(defun tramp-fish-handle-delete-file (filename)
+(defun tramp-fish-handle-delete-file (filename &optional force)
"Like `delete-file' for Tramp files."
(when (file-exists-p filename)
(with-parsed-tramp-file-name (expand-file-name filename) nil
localname)))))
(tramp-error
v 'file-already-exists "File %s already exists" localname)
- (delete-file linkname)))
+ (tramp-compat-delete-file linkname 'force)))
;; If FILENAME is a Tramp name, use just the localname component.
(when (tramp-tramp-file-p filename)
;; Provide error file.
(when tmpstderr (rename-file tmpstderr (cadr destination) t))
;; Cleanup.
- (when tmpinput (delete-file tmpinput))
- (when tmpoutput (delete-file tmpoutput))
+ (when tmpinput (tramp-compat-delete-file tmpinput 'force))
+ (when tmpoutput (tramp-compat-delete-file tmpoutput 'force))
;; Return exit status.
ret)))
;;; tramp-ftp.el --- Tramp convenience functions for Ange-FTP
-;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007,
-;; 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;; 2009, 2010 Free Software Foundation, Inc.
;; Author: Michael Albinus <michael.albinus@gmx.de>
;; Keywords: comm, processes
(unwind-protect
(rename-file tmpfile newname (car args))
;; Cleanup.
- (ignore-errors (delete-file tmpfile)))))
+ (ignore-errors (tramp-compat-delete-file tmpfile 'force)))))
;; Normally, the handlers must be discarded.
;; `inhibit-file-name-handlers' isn't sufficient, because the
(tramp-compat-delete-directory
(tramp-gvfs-fuse-file-name directory) recursive))
-(defun tramp-gvfs-handle-delete-file (filename)
+(defun tramp-gvfs-handle-delete-file (filename &optional force)
"Like `delete-file' for Tramp files."
- (delete-file (tramp-gvfs-fuse-file-name filename)))
+ (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename) force))
(defun tramp-gvfs-handle-directory-files
(directory &optional full match nosort)
"gvfs-save" tmpfile (tramp-get-buffer v) nil
(tramp-gvfs-url-file-name filename)))
(signal (car err) (cdr err)))
- (delete-file tmpfile)))))
+ (tramp-compat-delete-file tmpfile 'force)))))
;; Set file modification time.
(when (or (eq visit t) (stringp visit))
(tramp-message v 0 "Transferring %s to %s...done" filename newname))
(when (eq op 'rename)
- (delete-file filename))))
+ (tramp-compat-delete-file filename 'force))))
;; TODO: revise this much
(defun tramp-imap-handle-expand-file-name (name &optional dir)
;; (file-exists-p (file-name-directory filename)))
(file-directory-p (file-name-directory filename)))
-(defun tramp-imap-handle-delete-file (filename)
+(defun tramp-imap-handle-delete-file (filename &optional force)
"Like `delete-file' for Tramp files."
(cond
((not (file-exists-p filename)) nil)
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
(tramp-error
v 'file-error "%s `%s'" (match-string 0) directory))))))
-(defun tramp-smb-handle-delete-file (filename)
+(defun tramp-smb-handle-delete-file (filename &optional force)
"Like `delete-file' for Tramp files."
(setq filename (expand-file-name filename))
(when (file-exists-p filename)
(tramp-message
v 4 "Fetching %s to tmp file %s...done" filename tmpfile)
;; Oops, an error. We shall cleanup.
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(tramp-error
v 'file-error "Cannot make local copy of file `%s'" filename))
tmpfile)))
(condition-case err
(rename-file tmpfile newname ok-if-already-exists)
((error quit)
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Remote newname.
v 0 "Copying file %s to file %s...done" filename newname)
(tramp-error v 'file-error "Cannot rename `%s'" filename)))))
- (delete-file filename))
+ (tramp-compat-delete-file filename 'force))
(defun tramp-smb-handle-set-file-modes (filename mode)
"Like `set-file-modes' for Tramp files."
(tramp-message
v 5 "Writing tmp file %s to file %s...done" tmpfile filename)
(tramp-error v 'file-error "Cannot write `%s'" filename))
- (delete-file tmpfile))
+ (tramp-compat-delete-file tmpfile 'force))
(unless (equal curbuf (current-buffer))
(tramp-error
l-localname)))))
(tramp-error
l 'file-already-exists "File %s already exists" l-localname)
- (delete-file linkname)))
+ (tramp-compat-delete-file linkname 'force)))
;; If FILENAME is a Tramp name, use just the localname component.
(when (tramp-tramp-file-p filename)
;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
(unwind-protect
(load local-copy noerror t t)
- (delete-file local-copy)))
+ (tramp-compat-delete-file local-copy 'force)))
(unless nomessage (tramp-message v 0 "Loading %s...done" file))
t)))
;; Set the mode.
(set-file-modes newname (tramp-default-file-modes filename))
;; If the operation was `rename', delete the original file.
- (unless (eq op 'copy) (delete-file filename)))
+ (unless (eq op 'copy) (tramp-compat-delete-file filename 'force)))
(defun tramp-do-copy-or-rename-file-directly
(op filename newname ok-if-already-exists keep-date preserve-uid-gid)
;; Save exit.
(condition-case nil
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(error)))))))))
;; Set the time and mode. Mask possible errors.
(if dir-flag
(tramp-compat-delete-directory
(expand-file-name ".." tmpfile) 'recursive)
- (delete-file tmpfile))
+ (tramp-compat-delete-file tmpfile 'force))
(error))))
;; Expand hops. Might be necessary for gateway methods.
;; If the operation was `rename', delete the original file.
(unless (eq op 'copy)
(if (file-regular-p filename)
- (delete-file filename)
+ (tramp-compat-delete-file filename 'force)
(tramp-compat-delete-directory filename 'recursive))))))
(defun tramp-handle-make-directory (dir &optional parents)
(tramp-shell-quote-argument localname))))
(tramp-error v 'file-error "Couldn't delete %s" directory))))
-(defun tramp-handle-delete-file (filename)
+(defun tramp-handle-delete-file (filename &optional force)
"Like `delete-file' for Tramp files."
(setq filename (expand-file-name filename))
(with-parsed-tramp-file-name filename nil
;; Cleanup. We remove all file cache values for the connection,
;; because the remote process could have changed them.
- (when tmpinput (delete-file tmpinput))
+ (when tmpinput (tramp-compat-delete-file tmpinput 'force))
;; `process-file-side-effects' has been introduced with GNU
;; Emacs 23.2. If set to `nil', no remote file will be changed
(when delete (delete-region start end))
(unwind-protect
(apply 'call-process program tmpfile buffer display args)
- (delete-file tmpfile))))
+ (tramp-compat-delete-file tmpfile 'force))))
(defun tramp-handle-shell-command
(command &optional output-buffer error-buffer)
(when (listp buffer)
(with-current-buffer error-buffer
(insert-file-contents (cadr buffer)))
- (delete-file (cadr buffer)))
+ (tramp-compat-delete-file (cadr buffer) 'force))
(if current-buffer-p
;; This is like exchange-point-and-mark, but doesn't
;; activate the mark. It is cleaner to avoid activation,
filename loc-dec)
(unwind-protect
(tramp-call-local-coding-command loc-dec tmpfile2 tmpfile)
- (delete-file tmpfile2))))
+ (tramp-compat-delete-file tmpfile2 'force))))
(tramp-message v 5 "Decoding remote file %s...done" filename)
;; Set proper permissions.
;; Error handling.
((error quit)
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
(run-hooks 'tramp-handle-file-local-copy-hook)
(set-buffer-modified-p nil))
(when (and (stringp local-copy)
(or remote-copy (null tramp-temp-buffer-file-name)))
- (delete-file local-copy))
+ (tramp-compat-delete-file local-copy 'force))
(when (stringp remote-copy)
- (delete-file
- (tramp-make-tramp-file-name method user host remote-copy))))))
+ (tramp-compat-delete-file
+ (tramp-make-tramp-file-name method user host remote-copy)
+ 'force)))))
;; Result.
(list (expand-file-name filename)
(list start end tmpfile append 'no-message lockname confirm))
((error quit)
(setq tramp-temp-buffer-file-name nil)
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err))))
;; Now, `last-coding-system-used' has the right value. Remember it.
(copy-file tmpfile filename t)
((error quit)
(setq tramp-temp-buffer-file-name nil)
- (delete-file tmpfile)
+ (tramp-compat-delete-file tmpfile 'force)
(signal (car err) (cdr err)))))
(setq tramp-temp-buffer-file-name nil)
;; Don't rename, in order to keep context in SELinux.
(unwind-protect
(copy-file tmpfile filename t)
- (delete-file tmpfile))))
+ (tramp-compat-delete-file tmpfile 'force))))
;; Use inline file transfer.
(rem-dec
v 5 "Decoding region into remote file %s...done" filename))
;; Save exit.
- (delete-file tmpfile)))
+ (tramp-compat-delete-file tmpfile 'force)))
;; That's not expected.
(t
"Remove temporary files related to current buffer."
(when (stringp tramp-temp-buffer-file-name)
(condition-case nil
- (delete-file tramp-temp-buffer-file-name)
+ (tramp-compat-delete-file tramp-temp-buffer-file-name 'force)
(error nil))))
(add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function)