diff options
| author | Michael Albinus | 2009-11-07 23:51:17 +0000 |
|---|---|---|
| committer | Michael Albinus | 2009-11-07 23:51:17 +0000 |
| commit | c2770957182dce2b6f365829f5f4563aa1dbc3a3 (patch) | |
| tree | 7b516afd3429d3749b6f5768efe5cd1a484a9ee8 | |
| parent | a20903d09e11de170b39fafbc3d6e8e9417fae67 (diff) | |
| download | emacs-c2770957182dce2b6f365829f5f4563aa1dbc3a3.tar.gz emacs-c2770957182dce2b6f365829f5f4563aa1dbc3a3.zip | |
* net/tramp-compat.el (tramp-compat-copy-directory)
(tramp-compat-delete-directory): New defuns.
| -rw-r--r-- | lisp/net/tramp-compat.el | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 57f23df94f3..266a3de0c70 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el | |||
| @@ -251,6 +251,48 @@ Add the extension of FILENAME, if existing." | |||
| 251 | filename newname ok-if-already-exists keep-date preserve-uid-gid) | 251 | filename newname ok-if-already-exists keep-date preserve-uid-gid) |
| 252 | (copy-file filename newname ok-if-already-exists keep-date))) | 252 | (copy-file filename newname ok-if-already-exists keep-date))) |
| 253 | 253 | ||
| 254 | ;; `copy-directory' is a new function in Emacs 23.2. Implementation | ||
| 255 | ;; is taken from there. | ||
| 256 | (defun tramp-compat-copy-directory | ||
| 257 | (directory newname &optional keep-time parents) | ||
| 258 | "Make a copy of DIRECTORY (compat function)." | ||
| 259 | (if (fboundp 'copy-directory) | ||
| 260 | (funcall | ||
| 261 | (symbol-function 'copy-directory) directory newname keep-time parents) | ||
| 262 | |||
| 263 | ;; If default-directory is a remote directory, make sure we find | ||
| 264 | ;; its copy-directory handler. | ||
| 265 | (let ((handler (or (find-file-name-handler directory 'copy-directory) | ||
| 266 | (find-file-name-handler newname 'copy-directory)))) | ||
| 267 | (if handler | ||
| 268 | (funcall handler 'copy-directory directory newname keep-time parents) | ||
| 269 | |||
| 270 | ;; Compute target name. | ||
| 271 | (setq directory (directory-file-name (expand-file-name directory)) | ||
| 272 | newname (directory-file-name (expand-file-name newname))) | ||
| 273 | (if (and (file-directory-p newname) | ||
| 274 | (not (string-equal (file-name-nondirectory directory) | ||
| 275 | (file-name-nondirectory newname)))) | ||
| 276 | (setq newname | ||
| 277 | (expand-file-name | ||
| 278 | (file-name-nondirectory directory) newname))) | ||
| 279 | (if (not (file-directory-p newname)) (make-directory newname parents)) | ||
| 280 | |||
| 281 | ;; Copy recursively. | ||
| 282 | (mapc | ||
| 283 | (lambda (file) | ||
| 284 | (if (file-directory-p file) | ||
| 285 | (tramp-compat-copy-directory file newname keep-time parents) | ||
| 286 | (copy-file file newname t keep-time))) | ||
| 287 | ;; We do not want to delete "." and "..". | ||
| 288 | (directory-files | ||
| 289 | directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")) | ||
| 290 | |||
| 291 | ;; Set directory attributes. | ||
| 292 | (set-file-modes newname (file-modes directory)) | ||
| 293 | (if keep-time | ||
| 294 | (set-file-times newname (nth 5 (file-attributes directory)))))))) | ||
| 295 | |||
| 254 | ;; `copy-tree' is a built-in function in XEmacs. In Emacs 21, it is | 296 | ;; `copy-tree' is a built-in function in XEmacs. In Emacs 21, it is |
| 255 | ;; an autoloaded function in cl-extra.el. Since Emacs 22, it is part | 297 | ;; an autoloaded function in cl-extra.el. Since Emacs 22, it is part |
| 256 | ;; of subr.el. There are problems when autoloading, therefore we test | 298 | ;; of subr.el. There are problems when autoloading, therefore we test |
| @@ -268,6 +310,13 @@ Add the extension of FILENAME, if existing." | |||
| 268 | (setq tree (cdr tree))) | 310 | (setq tree (cdr tree))) |
| 269 | (nconc (nreverse result) tree)))) | 311 | (nconc (nreverse result) tree)))) |
| 270 | 312 | ||
| 313 | ;; RECURSIVE has been introduced with Emacs 23.2. | ||
| 314 | (defun tramp-compat-delete-directory (directory &optional recursive) | ||
| 315 | "Like `delete-directory' for Tramp files (compat function)." | ||
| 316 | (if recursive | ||
| 317 | (funcall (symbol-function 'delete-directory) directory recursive) | ||
| 318 | (delete-directory directory))) | ||
| 319 | |||
| 271 | ;; `number-sequence' has been introduced in Emacs 22. Implementation | 320 | ;; `number-sequence' has been introduced in Emacs 22. Implementation |
| 272 | ;; is taken from Emacs 23. | 321 | ;; is taken from Emacs 23. |
| 273 | (defun tramp-compat-number-sequence (from &optional to inc) | 322 | (defun tramp-compat-number-sequence (from &optional to inc) |