Remove stale entities
authorvitaly <v.mayatskih@gmail.com>
Thu, 26 Mar 2009 10:04:27 +0000 (26 11:04 +0100)
committervitaly <v.mayatskih@gmail.com>
Thu, 26 Mar 2009 10:04:27 +0000 (26 11:04 +0100)
Wl doesn't remove old entities which are not referenced by any
live message any more.

elmo/modb-standard.el

index 1ecfcd6..43c3562 100644 (file)
                           entities))
       (ignore-errors (delete-file filename)))))
 
+(defun modb-standard-cleanup-stale-entities (modb path)
+  (message "Removing stale entities...")
+  (let ((entities (elmo-uniq-list
+                  (mapcar
+                   #'(lambda (x) (/ x modb-standard-divide-number))
+                   (modb-standard-number-list-internal modb))))
+       (files (mapcar #'(lambda(x)
+                          (when (string-match "^entity-\\([0-9]+\\)" x)
+                            (string-to-int (match-string 1 x))))
+                      (directory-files path nil "^entity-"))))
+    (dolist (entity (car (elmo-list-diff-nonsortable files entities)))
+      (ignore-errors (delete-file (expand-file-name
+                                  (modb-standard-entity-filename entity) path))))))
+
 (defun modb-standard-save-entity (modb path)
   (let ((modified (modb-generic-message-modified-internal modb)))
     (cond ((listp modified)
             (dolist (section sections)
               (modb-standard-save-entity-1 modb path section))))
          (modified
-          (modb-standard-save-entity-1 modb path)))))
+          (modb-standard-save-entity-1 modb path))))
+  (modb-standard-cleanup-stale-entities modb path))
 
 ;;; Implement
 ;;