[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 1ce4381 10/39: Allow reproducing "cp --backup=numbered fro

From: Thierry Volpiatto
Subject: [elpa] master 1ce4381 10/39: Allow reproducing "cp --backup=numbered from to".
Date: Wed, 18 May 2016 18:02:51 +0000 (UTC)

branch: master
commit 1ce438174ab0dd1f101709b76a9febe80fdcfaa8
Author: Thierry Volpiatto <address@hidden>
Commit: Thierry Volpiatto <address@hidden>

    Allow reproducing "cp --backup=numbered from to".
    * dired-async.el (dired-async-create-files):
    When using a file-creator named 'backup-file, files are
    copied to destination without overwriting existing files,
    making a versionned copy of original files.
 dired-async.el |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/dired-async.el b/dired-async.el
index ecab9cb..461e1dd 100644
--- a/dired-async.el
+++ b/dired-async.el
@@ -166,7 +166,8 @@ See `dired-create-files' for the behavior of arguments."
                          (downcase operation) from)))
         (if (not to)
             (setq skipped (cons (dired-make-relative from) skipped))
-            (let* ((overwrite (file-exists-p to))
+            (let* ((overwrite (and (null (eq file-creator 'backup-file))
+                                   (file-exists-p to)))
                    (dired-overwrite-confirmed ; for dired-handle-overwrite
                     (and overwrite
                          (let ((help-form '(format "\
@@ -255,8 +256,21 @@ ESC or `q' to not overwrite any of the remaining files,
                       (condition-case err
                           (let ((dired-recursive-copies (quote always)))
-                            (cl-loop for (f . d) in (quote ,async-fn-list)
-                                     do (funcall (quote ,file-creator) f d t)))
+                            (defalias 'backup-file
+                                ;; Same feature as "cp --backup=numbered from 
+                                (lambda (from to ok)
+                                  (when (null (nth 0 (file-attributes from)))
+                                    (let ((count 0))
+                                      (while (let ((attrs (file-attributes 
+                                               (and attrs
+                                                    (null (nth 0 
(file-attributes to)))))
+                                        (cl-incf count)
+                                        (setq to (concat 
(file-name-sans-versions to)
+                                                         (format ".~%s~" 
+                                    (copy-file from to ok 
+                            (cl-loop with fn = (quote ,file-creator)
+                                     for (from . dest) in (quote 
+                                     do (funcall fn from dest t)))
                          (with-temp-file ,dired-async-log-file
                            (insert (format "%S" err)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]