emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r118111: lisp/gnus/gnus-start.el: Optionally check t


From: Katsumi Yamaoka
Subject: [Emacs-diffs] trunk r118111: lisp/gnus/gnus-start.el: Optionally check the newsrc.eld file's timestamp before saving it
Date: Tue, 14 Oct 2014 22:13:52 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 118111
revision-id: address@hidden
parent: address@hidden
author: Ted Zlatanov <address@hidden>
committer: Katsumi Yamaoka <address@hidden>
branch nick: trunk
timestamp: Tue 2014-10-14 22:13:44 +0000
message:
  lisp/gnus/gnus-start.el: Optionally check the newsrc.eld file's timestamp 
before saving it
modified:
  lisp/gnus/ChangeLog            changelog-20091113204419-o5vbwnq5f7feedwu-1433
  lisp/gnus/gnus-start.el        
gnusstart.el-20091113204419-o5vbwnq5f7feedwu-1136
=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2014-10-06 22:11:44 +0000
+++ b/lisp/gnus/ChangeLog       2014-10-14 22:13:44 +0000
@@ -1,3 +1,10 @@
+2014-10-14  Teodor Zlatanov  <address@hidden>
+
+       * gnus-start.el (gnus-save-newsrc-file-check-timestamp): New option to
+       check the newsrc.eld file's timestamp before saving it.
+       (gnus-save-newsrc-file): Use it, with a prompt when the newsrc.eld
+       timestamp has changed to be newer.
+
 2014-10-06  Jan Tatarik  <address@hidden>
 
        * gnus-icalendar.el (gnus-icalendar-identities):

=== modified file 'lisp/gnus/gnus-start.el'
--- a/lisp/gnus/gnus-start.el   2014-07-07 05:47:59 +0000
+++ b/lisp/gnus/gnus-start.el   2014-10-14 22:13:44 +0000
@@ -442,6 +442,14 @@
   :group 'gnus-newsrc
   :type 'hook)
 
+(defcustom gnus-save-newsrc-file-check-timestamp nil
+  "Check the modification time of the newsrc.eld file before saving it.
+When the newsrc.eld file is updated by multiple machines,
+checking the file's modification time is a good way to avoid
+overwriting updated data."
+  :group 'gnus-newsrc
+  :type 'boolean)
+
 (defcustom gnus-save-newsrc-hook nil
   "A hook called before saving any of the newsrc files."
   :group 'gnus-newsrc
@@ -2783,6 +2791,7 @@
       'msdos-long-file-names
       (lambda () t))))
 
+(defvar gnus-save-newsrc-file-last-timestamp nil)
 (defun gnus-save-newsrc-file (&optional force)
   "Save .newsrc file."
   ;; Note: We cannot save .newsrc file if all newsgroups are removed
@@ -2821,12 +2830,30 @@
          (erase-buffer)
           (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
 
+          ;; check timestamp of `gnus-current-startup-file'.eld against
+          ;; `gnus-save-newsrc-file-last-timestamp'
+          (when gnus-save-newsrc-file-check-timestamp
+            (let* ((checkfile (concat gnus-current-startup-file ".eld"))
+                   (mtime (nth 5 (file-attributes checkfile))))
+              (when (and gnus-save-newsrc-file-last-timestamp
+                         (time-less-p gnus-save-newsrc-file-last-timestamp
+                                      mtime))
+                (unless (y-or-n-p
+                         (format "%s was updated externally after %s, save?"
+                                 checkfile
+                                 (format-time-string
+                                  "%c"
+                                  gnus-save-newsrc-file-last-timestamp)))
+                (error "Couldn't save %s: updated externally" checkfile)))))
+
           (if gnus-save-startup-file-via-temp-buffer
               (let ((coding-system-for-write gnus-ding-file-coding-system)
                     (standard-output (current-buffer)))
                 (gnus-gnus-to-quick-newsrc-format)
                 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
-                (save-buffer))
+                (save-buffer)
+                (setq gnus-save-newsrc-file-last-timestamp
+                            (nth 5 (file-attributes buffer-file-name))))
             (let ((coding-system-for-write gnus-ding-file-coding-system)
                   (version-control gnus-backup-startup-file)
                   (startup-file (concat gnus-current-startup-file ".eld"))
@@ -2861,7 +2888,9 @@
 
                       ;; Replace the existing startup file with the temp file.
                       (rename-file working-file startup-file t)
-                      (gnus-set-file-modes startup-file setmodes)))
+                      (gnus-set-file-modes startup-file setmodes)
+                      (setq gnus-save-newsrc-file-last-timestamp
+                            (nth 5 (file-attributes startup-file)))))
                 (condition-case nil
                     (delete-file working-file)
                   (file-error nil)))))


reply via email to

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