*** empty log message ***
[gnus] / lisp / gnus-cache.el
1 ;;; gnus-cache.el --- cache interface for Gnus
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'gnus)
31 (require 'gnus-int)
32 (require 'gnus-range)
33 (require 'gnus-start)
34 (eval-when-compile
35   (require 'gnus-sum))
36
37 (defcustom gnus-cache-active-file
38   (concat (file-name-as-directory gnus-cache-directory) "active")
39   "*The cache active file."
40   :group 'gnus-cache
41   :type 'file)
42
43 (defcustom gnus-cache-enter-articles '(ticked dormant)
44   "Classes of articles to enter into the cache."
45   :group 'gnus-cache
46   :type '(set (const ticked) (const dormant) (const unread) (const read)))
47
48 (defcustom gnus-cache-remove-articles '(read)
49   "Classes of articles to remove from the cache."
50   :group 'gnus-cache
51   :type '(set (const ticked) (const dormant) (const unread) (const read)))
52
53 (defcustom gnus-uncacheable-groups nil
54   "*Groups that match this regexp will not be cached.
55
56 If you want to avoid caching your nnml groups, you could set this
57 variable to \"^nnml\"."
58   :group 'gnus-cache
59   :type '(choice (const :tag "off" nil)
60                  regexp))
61
62 \f
63
64 ;;; Internal variables.
65
66 (defvar gnus-cache-removable-articles nil)
67 (defvar gnus-cache-buffer nil)
68 (defvar gnus-cache-active-hashtb nil)
69 (defvar gnus-cache-active-altered nil)
70
71 (eval-and-compile
72   (autoload 'nnml-generate-nov-databases-1 "nnml")
73   (autoload 'nnvirtual-find-group-art "nnvirtual"))
74
75 \f
76
77 ;;; Functions called from Gnus.
78
79 (defun gnus-cache-open ()
80   "Initialize the cache."
81   (when (or (file-exists-p gnus-cache-directory)
82             (and gnus-use-cache
83                  (not (eq gnus-use-cache 'passive))))
84     (gnus-cache-read-active)))
85
86 ;; Complexities of byte-compiling make this kludge necessary.  Eeek.
87 (ignore-errors
88   (gnus-add-shutdown 'gnus-cache-close 'gnus))
89
90 (defun gnus-cache-close ()
91   "Shut down the cache."
92   (gnus-cache-write-active)
93   (gnus-cache-save-buffers)
94   (setq gnus-cache-active-hashtb nil))
95
96 (defun gnus-cache-save-buffers ()
97   ;; save the overview buffer if it exists and has been modified
98   ;; delete empty cache subdirectories
99   (when gnus-cache-buffer
100     (let ((buffer (cdr gnus-cache-buffer))
101           (overview-file (gnus-cache-file-name
102                           (car gnus-cache-buffer) ".overview")))
103       ;; write the overview only if it was modified
104       (when (buffer-modified-p buffer)
105         (save-excursion
106           (set-buffer buffer)
107           (if (> (buffer-size) 0)
108               ;; Non-empty overview, write it to a file.
109               (gnus-write-buffer overview-file)
110             ;; Empty overview file, remove it
111             (when (file-exists-p overview-file)
112               (delete-file overview-file))
113             ;; If possible, remove group's cache subdirectory.
114             (condition-case nil
115                 ;; FIXME: we can detect the error type and warn the user
116                 ;; of any inconsistencies (articles w/o nov entries?).
117                 ;; for now, just be conservative...delete only if safe -- sj
118                 (delete-directory (file-name-directory overview-file))
119               (error nil)))))
120       ;; Kill the buffer -- it's either unmodified or saved.
121       (gnus-kill-buffer buffer)
122       (setq gnus-cache-buffer nil))))
123
124 (defun gnus-cache-possibly-enter-article
125   (group article headers ticked dormant unread &optional force)
126   (when (and (or force (not (eq gnus-use-cache 'passive)))
127              (numberp article)
128              (> article 0)
129              (vectorp headers))         ; This might be a dummy article.
130     ;; If this is a virtual group, we find the real group.
131     (when (gnus-virtual-group-p group)
132       (let ((result (nnvirtual-find-group-art
133                      (gnus-group-real-name group) article)))
134         (setq group (car result)
135               headers (copy-sequence headers))
136         (mail-header-set-number headers (cdr result))))
137     (let ((number (mail-header-number headers))
138           file dir)
139       (when (and number
140                  (> number 0)           ; Reffed article.
141                  (or force
142                      (and (or (not gnus-uncacheable-groups)
143                               (not (string-match
144                                     gnus-uncacheable-groups group)))
145                           (gnus-cache-member-of-class
146                            gnus-cache-enter-articles ticked dormant unread)))
147                  (not (file-exists-p (setq file (gnus-cache-file-name
148                                                  group number)))))
149         ;; Possibly create the cache directory.
150         (gnus-make-directory (setq dir (file-name-directory file)))
151         ;; Save the article in the cache.
152         (if (file-exists-p file)
153             t                           ; The article already is saved.
154           (save-excursion
155             (set-buffer nntp-server-buffer)
156             (let ((gnus-use-cache nil))
157               (gnus-request-article-this-buffer number group))
158             (when (> (buffer-size) 0)
159               (gnus-write-buffer file)
160               (gnus-cache-change-buffer group)
161               (set-buffer (cdr gnus-cache-buffer))
162               (goto-char (point-max))
163               (forward-line -1)
164               (while (condition-case ()
165                          (when (not (bobp))
166                            (> (read (current-buffer)) number))
167                        (error
168                         ;; The line was malformed, so we just remove it!!
169                         (gnus-delete-line)
170                         t))
171                 (forward-line -1))
172               (if (bobp)
173                   (if (not (eobp))
174                       (progn
175                         (beginning-of-line)
176                         (when (< (read (current-buffer)) number)
177                           (forward-line 1)))
178                     (beginning-of-line))
179                 (forward-line 1))
180               (beginning-of-line)
181               ;; [number subject from date id references chars lines xref]
182               (insert (format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n"
183                               (mail-header-number headers)
184                               (mail-header-subject headers)
185                               (mail-header-from headers)
186                               (mail-header-date headers)
187                               (mail-header-id headers)
188                               (or (mail-header-references headers) "")
189                               (or (mail-header-chars headers) "")
190                               (or (mail-header-lines headers) "")
191                               (or (mail-header-xref headers) "")))
192               ;; Update the active info.
193               (set-buffer gnus-summary-buffer)
194               (gnus-cache-update-active group number)
195               (push article gnus-newsgroup-cached)
196               (gnus-summary-update-secondary-mark article))
197             t))))))
198
199 (defun gnus-cache-enter-remove-article (article)
200   "Mark ARTICLE for later possible removal."
201   (when article
202     (push article gnus-cache-removable-articles)))
203
204 (defun gnus-cache-possibly-remove-articles ()
205   "Possibly remove some of the removable articles."
206   (if (not (gnus-virtual-group-p gnus-newsgroup-name))
207       (gnus-cache-possibly-remove-articles-1)
208     (let ((arts gnus-cache-removable-articles)
209           ga)
210       (while arts
211         (when (setq ga (nnvirtual-find-group-art
212                         (gnus-group-real-name gnus-newsgroup-name) (pop arts)))
213           (let ((gnus-cache-removable-articles (list (cdr ga)))
214                 (gnus-newsgroup-name (car ga)))
215             (gnus-cache-possibly-remove-articles-1)))))
216     (setq gnus-cache-removable-articles nil)))
217
218 (defun gnus-cache-possibly-remove-articles-1 ()
219   "Possibly remove some of the removable articles."
220   (unless (eq gnus-use-cache 'passive)
221     (let ((articles gnus-cache-removable-articles)
222           (cache-articles gnus-newsgroup-cached)
223           article)
224       (gnus-cache-change-buffer gnus-newsgroup-name)
225       (while articles
226         (when (memq (setq article (pop articles)) cache-articles)
227           ;; The article was in the cache, so we see whether we are
228           ;; supposed to remove it from the cache.
229           (gnus-cache-possibly-remove-article
230            article (memq article gnus-newsgroup-marked)
231            (memq article gnus-newsgroup-dormant)
232            (or (memq article gnus-newsgroup-unreads)
233                (memq article gnus-newsgroup-unselected))))))
234     ;; The overview file might have been modified, save it
235     ;; safe because we're only called at group exit anyway.
236     (gnus-cache-save-buffers)))
237
238 (defun gnus-cache-request-article (article group)
239   "Retrieve ARTICLE in GROUP from the cache."
240   (let ((file (gnus-cache-file-name group article))
241         (buffer-read-only nil))
242     (when (file-exists-p file)
243       (erase-buffer)
244       (gnus-kill-all-overlays)
245       (insert-file-contents file)
246       t)))
247
248 (defun gnus-cache-possibly-alter-active (group active)
249   "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
250   (when gnus-cache-active-hashtb
251     (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
252       (when cache-active
253         (when (< (car cache-active) (car active))
254           (setcar active (car cache-active)))
255         (when (> (cdr cache-active) (cdr active))
256           (setcdr active (cdr cache-active)))))))
257
258 (defun gnus-cache-retrieve-headers (articles group &optional fetch-old)
259   "Retrieve the headers for ARTICLES in GROUP."
260   (let ((cached
261          (setq gnus-newsgroup-cached (gnus-cache-articles-in-group group))))
262     (if (not cached)
263         ;; No cached articles here, so we just retrieve them
264         ;; the normal way.
265         (let ((gnus-use-cache nil))
266           (gnus-retrieve-headers articles group fetch-old))
267       (let ((uncached-articles (gnus-sorted-intersection
268                                 (gnus-sorted-complement articles cached)
269                                 articles))
270             (cache-file (gnus-cache-file-name group ".overview"))
271             type)
272         ;; We first retrieve all the headers that we don't have in
273         ;; the cache.
274         (let ((gnus-use-cache nil))
275           (when uncached-articles
276             (setq type (and articles
277                             (gnus-retrieve-headers
278                              uncached-articles group fetch-old)))))
279         (gnus-cache-save-buffers)
280         ;; Then we insert the cached headers.
281         (save-excursion
282           (cond
283            ((not (file-exists-p cache-file))
284             ;; There are no cached headers.
285             type)
286            ((null type)
287             ;; There were no uncached headers (or retrieval was
288             ;; unsuccessful), so we use the cached headers exclusively.
289             (set-buffer nntp-server-buffer)
290             (erase-buffer)
291             (insert-file-contents cache-file)
292             'nov)
293            ((eq type 'nov)
294             ;; We have both cached and uncached NOV headers, so we
295             ;; braid them.
296             (gnus-cache-braid-nov group cached)
297             type)
298            (t
299             ;; We braid HEADs.
300             (gnus-cache-braid-heads group (gnus-sorted-intersection
301                                            cached articles))
302             type)))))))
303
304 (defun gnus-cache-enter-article (&optional n)
305   "Enter the next N articles into the cache.
306 If not given a prefix, use the process marked articles instead.
307 Returns the list of articles entered."
308   (interactive "P")
309   (let ((articles (gnus-summary-work-articles n))
310         article out)
311     (while (setq article (pop articles))
312       (gnus-summary-remove-process-mark article)
313       (if (natnump article)
314           (when (gnus-cache-possibly-enter-article
315                  gnus-newsgroup-name article
316                  (gnus-summary-article-header article)
317                  nil nil nil t)
318             (push article out))
319         (gnus-message 2 "Can't cache article %d" article))
320       (gnus-summary-update-secondary-mark article))
321     (gnus-summary-next-subject 1)
322     (gnus-summary-position-point)
323     (nreverse out)))
324
325 (defun gnus-cache-remove-article (n)
326   "Remove the next N articles from the cache.
327 If not given a prefix, use the process marked articles instead.
328 Returns the list of articles removed."
329   (interactive "P")
330   (gnus-cache-change-buffer gnus-newsgroup-name)
331   (let ((articles (gnus-summary-work-articles n))
332         article out)
333     (while articles
334       (setq article (pop articles))
335       (gnus-summary-remove-process-mark article)
336       (when (gnus-cache-possibly-remove-article article nil nil nil t)
337         (push article out))
338       (gnus-summary-update-secondary-mark article))
339     (gnus-summary-next-subject 1)
340     (gnus-summary-position-point)
341     (nreverse out)))
342
343 (defun gnus-cached-article-p (article)
344   "Say whether ARTICLE is cached in the current group."
345   (memq article gnus-newsgroup-cached))
346
347 (defun gnus-summary-insert-cached-articles ()
348   "Insert all the articles cached for this group into the current buffer."
349   (interactive)
350   (let ((cached gnus-newsgroup-cached)
351         (gnus-verbose (max 6 gnus-verbose)))
352     (unless cached
353       (gnus-message 3 "No cached articles for this group"))
354     (while cached
355       (gnus-summary-goto-subject (pop cached) t))))
356
357 (defalias 'gnus-summary-limit-include-cached
358   'gnus-summary-insert-cached-articles)
359
360 ;;; Internal functions.
361
362 (defun gnus-cache-change-buffer (group)
363   (and gnus-cache-buffer
364        ;; See if the current group's overview cache has been loaded.
365        (or (string= group (car gnus-cache-buffer))
366            ;; Another overview cache is current, save it.
367            (gnus-cache-save-buffers)))
368   ;; if gnus-cache buffer is nil, create it
369   (unless gnus-cache-buffer
370     ;; Create cache buffer
371     (save-excursion
372       (setq gnus-cache-buffer
373             (cons group
374                   (set-buffer (get-buffer-create " *gnus-cache-overview*"))))
375       (buffer-disable-undo (current-buffer))
376       ;; Insert the contents of this group's cache overview.
377       (erase-buffer)
378       (let ((file (gnus-cache-file-name group ".overview")))
379         (when (file-exists-p file)
380           (nnheader-insert-file-contents file)))
381       ;; We have a fresh (empty/just loaded) buffer,
382       ;; mark it as unmodified to save a redundant write later.
383       (set-buffer-modified-p nil))))
384
385 ;; Return whether an article is a member of a class.
386 (defun gnus-cache-member-of-class (class ticked dormant unread)
387   (or (and ticked (memq 'ticked class))
388       (and dormant (memq 'dormant class))
389       (and unread (memq 'unread class))
390       (and (not unread) (not ticked) (not dormant) (memq 'read class))))
391
392 (defun gnus-cache-file-name (group article)
393   (concat (file-name-as-directory gnus-cache-directory)
394           (file-name-as-directory
395            (nnheader-translate-file-chars
396             (if (gnus-use-long-file-name 'not-cache)
397                 group
398               (let ((group (nnheader-replace-chars-in-string group ?/ ?_)))
399                 ;; Translate the first colon into a slash.
400                 (when (string-match ":" group)
401                   (aset group (match-beginning 0) ?/))
402                 (nnheader-replace-chars-in-string group ?. ?/)))
403             t))
404           (if (stringp article) article (int-to-string article))))
405
406 (defun gnus-cache-update-article (group article)
407   "If ARTICLE is in the cache, remove it and re-enter it."
408   (when (gnus-cache-possibly-remove-article article nil nil nil t)
409     (let ((gnus-use-cache nil))
410       (gnus-cache-possibly-enter-article
411        gnus-newsgroup-name article (gnus-summary-article-header article)
412        nil nil nil t))))
413
414 (defun gnus-cache-possibly-remove-article (article ticked dormant unread
415                                                    &optional force)
416   "Possibly remove ARTICLE from the cache."
417   (let ((group gnus-newsgroup-name)
418         (number article)
419         file)
420     ;; If this is a virtual group, we find the real group.
421     (when (gnus-virtual-group-p group)
422       (let ((result (nnvirtual-find-group-art
423                      (gnus-group-real-name group) article)))
424         (setq group (car result)
425               number (cdr result))))
426     (setq file (gnus-cache-file-name group number))
427     (when (and (file-exists-p file)
428                (or force
429                    (gnus-cache-member-of-class
430                     gnus-cache-remove-articles ticked dormant unread)))
431       (save-excursion
432         (delete-file file)
433         (set-buffer (cdr gnus-cache-buffer))
434         (goto-char (point-min))
435         (when (or (looking-at (concat (int-to-string number) "\t"))
436                   (search-forward (concat "\n" (int-to-string number) "\t")
437                                   (point-max) t))
438           (delete-region (progn (beginning-of-line) (point))
439                          (progn (forward-line 1) (point)))))
440       (setq gnus-newsgroup-cached
441             (delq article gnus-newsgroup-cached))
442       (gnus-summary-update-secondary-mark article)
443       t)))
444
445 (defun gnus-cache-articles-in-group (group)
446   "Return a sorted list of cached articles in GROUP."
447   (let ((dir (file-name-directory (gnus-cache-file-name group 1)))
448         articles)
449     (when (file-exists-p dir)
450       (setq articles
451             (sort (mapcar (lambda (name) (string-to-int name))
452                           (directory-files dir nil "^[0-9]+$" t))
453                   '<))
454       ;; Update the cache active file, just to synch more.
455       (when articles
456         (gnus-cache-update-active group (car articles) t)
457         (gnus-cache-update-active group (car (last articles))))
458       articles)))
459
460 (defun gnus-cache-braid-nov (group cached &optional file)
461   (let ((cache-buf (get-buffer-create " *gnus-cache*"))
462         beg end)
463     (gnus-cache-save-buffers)
464     (save-excursion
465       (set-buffer cache-buf)
466       (buffer-disable-undo (current-buffer))
467       (erase-buffer)
468       (insert-file-contents (or file (gnus-cache-file-name group ".overview")))
469       (goto-char (point-min))
470       (insert "\n")
471       (goto-char (point-min)))
472     (set-buffer nntp-server-buffer)
473     (goto-char (point-min))
474     (while cached
475       (while (and (not (eobp))
476                   (< (read (current-buffer)) (car cached)))
477         (forward-line 1))
478       (beginning-of-line)
479       (save-excursion
480         (set-buffer cache-buf)
481         (if (search-forward (concat "\n" (int-to-string (car cached)) "\t")
482                             nil t)
483             (setq beg (progn (beginning-of-line) (point))
484                   end (progn (end-of-line) (point)))
485           (setq beg nil)))
486       (when beg
487         (insert-buffer-substring cache-buf beg end)
488         (insert "\n"))
489       (setq cached (cdr cached)))
490     (kill-buffer cache-buf)))
491
492 (defun gnus-cache-braid-heads (group cached)
493   (let ((cache-buf (get-buffer-create " *gnus-cache*")))
494     (save-excursion
495       (set-buffer cache-buf)
496       (buffer-disable-undo (current-buffer))
497       (erase-buffer))
498     (set-buffer nntp-server-buffer)
499     (goto-char (point-min))
500     (while cached
501       (while (and (not (eobp))
502                   (looking-at "2.. +\\([0-9]+\\) ")
503                   (< (progn (goto-char (match-beginning 1))
504                             (read (current-buffer)))
505                      (car cached)))
506         (search-forward "\n.\n" nil 'move))
507       (beginning-of-line)
508       (save-excursion
509         (set-buffer cache-buf)
510         (erase-buffer)
511         (insert-file-contents (gnus-cache-file-name group (car cached)))
512         (goto-char (point-min))
513         (insert "220 ")
514         (princ (car cached) (current-buffer))
515         (insert " Article retrieved.\n")
516         (search-forward "\n\n" nil 'move)
517         (delete-region (point) (point-max))
518         (forward-char -1)
519         (insert "."))
520       (insert-buffer-substring cache-buf)
521       (setq cached (cdr cached)))
522     (kill-buffer cache-buf)))
523
524 ;;;###autoload
525 (defun gnus-jog-cache ()
526   "Go through all groups and put the articles into the cache.
527
528 Usage:
529 $ emacs -batch -l ~/.emacs -l gnus -f gnus-jog-cache"
530   (interactive)
531   (let ((gnus-mark-article-hook nil)
532         (gnus-expert-user t)
533         (nnmail-spool-file nil)
534         (gnus-use-dribble-file nil)
535         (gnus-novice-user nil)
536         (gnus-large-newsgroup nil))
537     ;; Start Gnus.
538     (gnus)
539     ;; Go through all groups...
540     (gnus-group-mark-buffer)
541     (gnus-group-iterate nil
542       (lambda (group)
543         (let (gnus-auto-select-next)
544           (gnus-summary-read-group group nil t)
545           ;; ... and enter the articles into the cache.
546           (when (eq major-mode 'gnus-summary-mode)
547             (gnus-uu-mark-buffer)
548             (gnus-cache-enter-article)
549             (kill-buffer (current-buffer))))))))
550
551 (defun gnus-cache-read-active (&optional force)
552   "Read the cache active file."
553   (gnus-make-directory gnus-cache-directory)
554   (if (or (not (file-exists-p gnus-cache-active-file))
555           (not (zerop (nth 7 (file-attributes gnus-cache-active-file))))
556           force)
557       ;; There is no active file, so we generate one.
558       (gnus-cache-generate-active)
559     ;; We simply read the active file.
560     (save-excursion
561       (gnus-set-work-buffer)
562       (insert-file-contents gnus-cache-active-file)
563       (gnus-active-to-gnus-format
564        nil (setq gnus-cache-active-hashtb
565                  (gnus-make-hashtable
566                   (count-lines (point-min) (point-max)))))
567       (setq gnus-cache-active-altered nil))))
568
569 (defun gnus-cache-write-active (&optional force)
570   "Write the active hashtb to the active file."
571   (when (or force
572             (and gnus-cache-active-hashtb
573                  gnus-cache-active-altered))
574     (nnheader-temp-write gnus-cache-active-file
575       (mapatoms
576        (lambda (sym)
577          (when (and sym (boundp sym))
578            (insert (format "%s %d %d y\n"
579                            (symbol-name sym) (cdr (symbol-value sym))
580                            (car (symbol-value sym))))))
581        gnus-cache-active-hashtb))
582     ;; Mark the active hashtb as unaltered.
583     (setq gnus-cache-active-altered nil)))
584
585 (defun gnus-cache-update-active (group number &optional low)
586   "Update the upper bound of the active info of GROUP to NUMBER.
587 If LOW, update the lower bound instead."
588   (let ((active (gnus-gethash group gnus-cache-active-hashtb)))
589     (if (null active)
590         ;; We just create a new active entry for this group.
591         (gnus-sethash group (cons number number) gnus-cache-active-hashtb)
592       ;; Update the lower or upper bound.
593       (if low
594           (setcar active number)
595         (setcdr active number)))
596     ;; Mark the active hashtb as altered.
597     (setq gnus-cache-active-altered t)))
598
599 ;;;###autoload
600 (defun gnus-cache-generate-active (&optional directory)
601   "Generate the cache active file."
602   (interactive)
603   (let* ((top (null directory))
604          (directory (expand-file-name (or directory gnus-cache-directory)))
605          (files (directory-files directory 'full))
606          (group
607           (if top
608               ""
609             (string-match
610              (concat "^" (regexp-quote
611                           (file-name-as-directory
612                            (expand-file-name gnus-cache-directory))))
613              (directory-file-name directory))
614             (nnheader-replace-chars-in-string
615              (substring (directory-file-name directory) (match-end 0))
616              ?/ ?.)))
617          nums alphs)
618     (when top
619       (gnus-message 5 "Generating the cache active file...")
620       (setq gnus-cache-active-hashtb (gnus-make-hashtable 123)))
621     ;; Separate articles from all other files and directories.
622     (while files
623       (if (string-match "^[0-9]+$" (file-name-nondirectory (car files)))
624           (push (string-to-int (file-name-nondirectory (pop files))) nums)
625         (push (pop files) alphs)))
626     ;; If we have nums, then this is probably a valid group.
627     (when (setq nums (sort nums '<))
628       (gnus-sethash group (cons (car nums) (gnus-last-element nums))
629                     gnus-cache-active-hashtb))
630     ;; Go through all the other files.
631     (while alphs
632       (when (and (file-directory-p (car alphs))
633                  (not (string-match "^\\.\\.?$"
634                                     (file-name-nondirectory (car alphs)))))
635         ;; We descend directories.
636         (gnus-cache-generate-active (car alphs)))
637       (setq alphs (cdr alphs)))
638     ;; Write the new active file.
639     (when top
640       (gnus-cache-write-active t)
641       (gnus-message 5 "Generating the cache active file...done"))))
642
643 ;;;###autoload
644 (defun gnus-cache-generate-nov-databases (dir)
645   "Generate NOV files recursively starting in DIR."
646   (interactive (list gnus-cache-directory))
647   (gnus-cache-close)
648   (let ((nnml-generate-active-function 'identity))
649     (nnml-generate-nov-databases-1 dir)))
650
651 (defun gnus-cache-move-cache (dir)
652   "Move the cache tree to somewhere else."
653   (interactive "FMove the cache tree to: ")
654   (rename-file gnus-cache-directory dir))
655
656 (provide 'gnus-cache)
657
658 ;;; gnus-cache.el ends here