all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH 2/2] nnmaildir: Use a 'num' file, instead of a directory
@ 2010-05-27 21:09 John Wiegley
  2010-06-24 17:52 ` Ted Zlatanov
  2010-06-26 17:33 ` Paul Jarc
  0 siblings, 2 replies; 4+ messages in thread
From: John Wiegley @ 2010-05-27 21:09 UTC (permalink / raw)
  To: emacs-devel@gnu.org devel

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

This patch causes nnmaildir to use a "num" file to track the next available article number, rather than creating N empty files.  However, this only works for new groups.  Existing groups, which use the directory, will continue to.  If you want to switch to using file-based numbering, you must convert your Maildir using the attached script (it's also copied to the commit description in the patch).

John


[-- Attachment #2: 0002-nnmaildir-Use-a-num-file-instead-of-a-directory.patch --]
[-- Type: application/octet-stream, Size: 3449 bytes --]

From d80163c6686b7b8a9a24ff94d61baddbcdd0364c Mon Sep 17 00:00:00 2001
From: John Wiegley <johnw@newartisans.com>
Date: Thu, 27 May 2010 15:03:10 -0600
Subject: [PATCH 2/2] nnmaildir: Use a 'num' file, instead of a directory

---
 nnmaildir.el |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/nnmaildir.el b/nnmaildir.el
index fde1fc8..1991321 100644
--- a/nnmaildir.el
+++ b/nnmaildir.el
@@ -236,6 +236,9 @@ by nnmaildir-request-article.")
 (defmacro nnmaildir--marks-dir (dir) `(nnmaildir--subdir ,dir "marks"))
 (defmacro nnmaildir--num-dir   (dir) `(nnmaildir--subdir ,dir "num"))
 
+(defun nnmaildir--num-file  (dir)
+  (expand-file-name "num" dir))
+
 (defmacro nnmaildir--unlink (file-arg)
   `(let ((file ,file-arg))
      (if (file-attributes file) (delete-file file))))
@@ -249,7 +252,7 @@ by nnmaildir-request-article.")
     (mapc 'delete-file (funcall ls dir 'full "\\`[^.]" 'nosort))
     (delete-directory dir)))
 
-(defun nnmaildir--group-maxnum (server group)
+(defun nnmaildir--group-maxnum-from-dir (server group)
   (catch 'return
     (if (zerop (nnmaildir--grp-count group)) (throw 'return 0))
     (let ((dir (nnmaildir--srvgrp-dir (nnmaildir--srv-dir server)
@@ -273,6 +276,21 @@ by nnmaildir-request-article.")
 	(unless (equal ino-opened (nth 10 attr))
 	  (setq number-opened number-linked))))))
 
+(defun nnmaildir--group-maxnum (server group)
+  (if (zerop (nnmaildir--grp-count group))
+      0
+    (let ((file (nnmaildir--num-file
+		 (nnmaildir--nndir
+		  (nnmaildir--srvgrp-dir (nnmaildir--srv-dir server)
+					 (nnmaildir--grp-name group))))))
+      (if (file-directory-p file)
+	  (nnmaildir--group-maxnum-from-dir server group)
+	(if (file-exists-p file)
+	    (with-temp-buffer
+	      (insert-file-contents file)
+	      (read (current-buffer)))
+	  0)))))
+
 ;; Make the given server, if non-nil, be the current server.  Then make the
 ;; given group, if non-nil, be the current group of the current server.  Then
 ;; return the group object for the current group.
@@ -324,8 +342,7 @@ by nnmaildir-request-article.")
 (defun nnmaildir--eexist-p (err)
   (eq (car err) 'file-already-exists))
 
-(defun nnmaildir--new-number (nndir)
-  "Allocate a new article number by atomically creating a file under NNDIR."
+(defun nnmaildir--new-number-from-dir (nndir)
   (let ((numdir (nnmaildir--num-dir nndir))
 	(make-new-file t)
 	(number-open 1)
@@ -366,6 +383,23 @@ by nnmaildir-request-article.")
 		      number-link 0))))
 	   (t (signal (car err) (cdr err)))))))))
 
+(defun nnmaildir--new-number (nndir)
+  "Allocate a new article number by atomically creating a file under NNDIR."
+  (let ((numfile (nnmaildir--num-file nndir))
+	(number 0))
+    (if (file-directory-p numfile)
+	(nnmaildir--new-number-from-dir nndir)
+      (with-current-buffer (find-file-noselect numfile t t)
+	(goto-char (point-min))
+	(unless (eobp)
+	  (setq number (1+ (read (current-buffer))))
+	  (delete-region (point-min) (point-max)))
+	(insert (number-to-string number))
+	(write-region (point-min) (point-max) numfile nil 'no-message)
+	(set-buffer-modified-p nil)
+	(kill-buffer (current-buffer)))
+      number)))
+
 (defun nnmaildir--update-nov (server group article)
   (let ((nnheader-file-coding-system 'binary)
 	(srv-dir (nnmaildir--srv-dir server))
-- 
1.7.1


[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



[-- Attachment #4: gnus-renumber --]
[-- Type: application/octet-stream, Size: 422 bytes --]

#!/bin/sh

dryrun=false
if [ "$1" = "-n" ]; then
    dryrun=true
    shift 1
fi

find $1 -name .nnmaildir -type d | \
while read nndir; do
    if [ -d "$nndir"/num ]; then
	last=$(find "$nndir"/num -type f | sed -e 's/.*\///' | sort -n | tail -1)
	if [ $dryrun = true ]; then
	    echo rm -fr "$nndir"/num
	    echo echo $last '>' "$nndir"/num
	else
	    rm -fr "$nndir"/num
	    echo $last > "$nndir"/num
	fi
    fi
done

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-13  0:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-27 21:09 [PATCH 2/2] nnmaildir: Use a 'num' file, instead of a directory John Wiegley
2010-06-24 17:52 ` Ted Zlatanov
2010-06-26 17:33 ` Paul Jarc
2010-08-13  0:15   ` Ted Zlatanov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.