From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/85088 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: check mtime of newsrc.eld before saving it Date: Mon, 06 Oct 2014 23:11:40 -0400 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: Reply-To: ding@gnus.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1412651590 8383 80.91.229.3 (7 Oct 2014 03:13:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Oct 2014 03:13:10 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M33332@lists.math.uh.edu Tue Oct 07 05:13:00 2014 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XbLCu-00070f-Ac for ding-account@gmane.org; Tue, 07 Oct 2014 05:13:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1XbLBw-0004Ii-LM; Mon, 06 Oct 2014 22:12:00 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1XbLBt-0004II-7m for ding@lists.math.uh.edu; Mon, 06 Oct 2014 22:11:57 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) (envelope-from ) id 1XbLBr-00028d-3H for ding@lists.math.uh.edu; Mon, 06 Oct 2014 22:11:56 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]) by quimby.gnus.org with esmtp (Exim 4.80) (envelope-from ) id 1XbLBp-0007bd-4s for ding@gnus.org; Tue, 07 Oct 2014 05:11:53 +0200 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XbLBn-0006eM-Sx for ding@gnus.org; Tue, 07 Oct 2014 05:11:52 +0200 Original-Received: from 166.170.35.2 ([166.170.35.2]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Oct 2014 05:11:51 +0200 Original-Received: from tzz by 166.170.35.2 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 07 Oct 2014 05:11:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: ding@gnus.org Original-Lines: 92 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 166.170.35.2 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (darwin) Cancel-Lock: sha1:sfKeYIlitEdAwrR+15e8ExijSbI= X-Spam-Score: -1.7 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:85088 Archived-At: --=-=-= Content-Type: text/plain I sometimes update my newsrc.eld in a directory shared between multiple machines. I wanted a way to stop Gnus from overwriting the updated file. I came up with the following untested patch, which adds a customizable option to do that check and saves the last modification time. But I didn't finish testing or commit it because I had two questions: 1) is there a more elegant way to do this with file reverting? It seems like Emacs can usually tell if the file needs to be reverted. 2) should I make and use a new newsrc pre-save hook? Let me know what you think... Thanks Ted --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=save-newsrc-check.patch diff --git a/lisp/gnus-start.el b/lisp/gnus-start.el index 766e7c2..53e88a9 100644 --- a/lisp/gnus-start.el +++ b/lisp/gnus-start.el @@ -442,6 +442,14 @@ See also `gnus-before-startup-hook'." :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 @@ If FORCE is non-nil, the .newsrc file is read." '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,24 @@ If FORCE is non-nil, the .newsrc file is read." (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)) + (error "Couldn't save %s because it was updated" 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 +2882,9 @@ If FORCE is non-nil, the .newsrc file is read." ;; 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))))) --=-=-=--