aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2014-10-14 22:13:44 +0000
committerKatsumi Yamaoka2014-10-14 22:13:44 +0000
commitfcb11aef80477e6218e1de01f71001fdce3f7a9a (patch)
tree2dd9b72e3ef6f11b47571071c46fc47ae27a2517
parent980d78b3587560c13a46aef352ed8d5ed744acf6 (diff)
downloademacs-fcb11aef80477e6218e1de01f71001fdce3f7a9a.tar.gz
emacs-fcb11aef80477e6218e1de01f71001fdce3f7a9a.zip
lisp/gnus/gnus-start.el: Optionally check the newsrc.eld file's timestamp before saving it
-rw-r--r--lisp/gnus/ChangeLog7
-rw-r--r--lisp/gnus/gnus-start.el33
2 files changed, 38 insertions, 2 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 6c59200dfa6..30eda3d2bf0 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,10 @@
12014-10-14 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * gnus-start.el (gnus-save-newsrc-file-check-timestamp): New option to
4 check the newsrc.eld file's timestamp before saving it.
5 (gnus-save-newsrc-file): Use it, with a prompt when the newsrc.eld
6 timestamp has changed to be newer.
7
12014-10-06 Jan Tatarik <jan.tatarik@gmail.com> 82014-10-06 Jan Tatarik <jan.tatarik@gmail.com>
2 9
3 * gnus-icalendar.el (gnus-icalendar-identities): 10 * gnus-icalendar.el (gnus-icalendar-identities):
diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el
index 766e7c26ac4..5b734d0ae77 100644
--- a/lisp/gnus/gnus-start.el
+++ b/lisp/gnus/gnus-start.el
@@ -442,6 +442,14 @@ See also `gnus-before-startup-hook'."
442 :group 'gnus-newsrc 442 :group 'gnus-newsrc
443 :type 'hook) 443 :type 'hook)
444 444
445(defcustom gnus-save-newsrc-file-check-timestamp nil
446 "Check the modification time of the newsrc.eld file before saving it.
447When the newsrc.eld file is updated by multiple machines,
448checking the file's modification time is a good way to avoid
449overwriting updated data."
450 :group 'gnus-newsrc
451 :type 'boolean)
452
445(defcustom gnus-save-newsrc-hook nil 453(defcustom gnus-save-newsrc-hook nil
446 "A hook called before saving any of the newsrc files." 454 "A hook called before saving any of the newsrc files."
447 :group 'gnus-newsrc 455 :group 'gnus-newsrc
@@ -2783,6 +2791,7 @@ If FORCE is non-nil, the .newsrc file is read."
2783 'msdos-long-file-names 2791 'msdos-long-file-names
2784 (lambda () t)))) 2792 (lambda () t))))
2785 2793
2794(defvar gnus-save-newsrc-file-last-timestamp nil)
2786(defun gnus-save-newsrc-file (&optional force) 2795(defun gnus-save-newsrc-file (&optional force)
2787 "Save .newsrc file." 2796 "Save .newsrc file."
2788 ;; Note: We cannot save .newsrc file if all newsgroups are removed 2797 ;; Note: We cannot save .newsrc file if all newsgroups are removed
@@ -2821,12 +2830,30 @@ If FORCE is non-nil, the .newsrc file is read."
2821 (erase-buffer) 2830 (erase-buffer)
2822 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file) 2831 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2823 2832
2833 ;; check timestamp of `gnus-current-startup-file'.eld against
2834 ;; `gnus-save-newsrc-file-last-timestamp'
2835 (when gnus-save-newsrc-file-check-timestamp
2836 (let* ((checkfile (concat gnus-current-startup-file ".eld"))
2837 (mtime (nth 5 (file-attributes checkfile))))
2838 (when (and gnus-save-newsrc-file-last-timestamp
2839 (time-less-p gnus-save-newsrc-file-last-timestamp
2840 mtime))
2841 (unless (y-or-n-p
2842 (format "%s was updated externally after %s, save?"
2843 checkfile
2844 (format-time-string
2845 "%c"
2846 gnus-save-newsrc-file-last-timestamp)))
2847 (error "Couldn't save %s: updated externally" checkfile)))))
2848
2824 (if gnus-save-startup-file-via-temp-buffer 2849 (if gnus-save-startup-file-via-temp-buffer
2825 (let ((coding-system-for-write gnus-ding-file-coding-system) 2850 (let ((coding-system-for-write gnus-ding-file-coding-system)
2826 (standard-output (current-buffer))) 2851 (standard-output (current-buffer)))
2827 (gnus-gnus-to-quick-newsrc-format) 2852 (gnus-gnus-to-quick-newsrc-format)
2828 (gnus-run-hooks 'gnus-save-quick-newsrc-hook) 2853 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2829 (save-buffer)) 2854 (save-buffer)
2855 (setq gnus-save-newsrc-file-last-timestamp
2856 (nth 5 (file-attributes buffer-file-name))))
2830 (let ((coding-system-for-write gnus-ding-file-coding-system) 2857 (let ((coding-system-for-write gnus-ding-file-coding-system)
2831 (version-control gnus-backup-startup-file) 2858 (version-control gnus-backup-startup-file)
2832 (startup-file (concat gnus-current-startup-file ".eld")) 2859 (startup-file (concat gnus-current-startup-file ".eld"))
@@ -2861,7 +2888,9 @@ If FORCE is non-nil, the .newsrc file is read."
2861 2888
2862 ;; Replace the existing startup file with the temp file. 2889 ;; Replace the existing startup file with the temp file.
2863 (rename-file working-file startup-file t) 2890 (rename-file working-file startup-file t)
2864 (gnus-set-file-modes startup-file setmodes))) 2891 (gnus-set-file-modes startup-file setmodes)
2892 (setq gnus-save-newsrc-file-last-timestamp
2893 (nth 5 (file-attributes startup-file)))))
2865 (condition-case nil 2894 (condition-case nil
2866 (delete-file working-file) 2895 (delete-file working-file)
2867 (file-error nil))))) 2896 (file-error nil)))))