From: Daiki Ueno Date: Fri, 1 Jul 2011 07:35:39 +0000 (+0900) Subject: Add plstore-delete. X-Git-Tag: emacs-pretest-24.0.90~104^2~152^2~283 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f3078a00412e29aac774f9a6780963313d4aebc9;p=emacs.git Add plstore-delete. * auth-source.el (plstore-delete): Autoload. (auth-source-plstore-search): Support delete operation. * plstore.el (plstore-delete): New function. --- diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 9bb234a1189..1b0b31c0088 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -1,3 +1,9 @@ +2011-07-01 Daiki Ueno + + * auth-source.el (plstore-delete): Autoload. + (auth-source-plstore-search): Support delete operation. + * plstore.el (plstore-delete): New function. + 2011-07-01 Katsumi Yamaoka * gnus-draft.el (gnus-draft-clear-marks): Revert last change; diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el index 9d62d6a81c4..1b5b4840085 100644 --- a/lisp/gnus/auth-source.el +++ b/lisp/gnus/auth-source.el @@ -60,6 +60,7 @@ (autoload 'plstore-open "plstore") (autoload 'plstore-find "plstore") (autoload 'plstore-put "plstore") +(autoload 'plstore-delete "plstore") (autoload 'plstore-save "plstore") (autoload 'plstore-get-file "plstore") @@ -1523,11 +1524,6 @@ authentication tokens: type max host user port &allow-other-keys) "Search the PLSTORE; spec is like `auth-source'." - - ;; TODO - (assert (not delete) nil - "The PLSTORE auth-source backend doesn't support deletion yet") - (let* ((store (oref backend data)) (max (or max 5000)) ; sanity check: default to stop at 5K (ignored-keys '(:create :delete :max :backend :require)) @@ -1551,6 +1547,7 @@ authentication tokens: '(:host :login :port :secret) search-keys))) (items (plstore-find store search-spec)) + (item-names (mapcar #'car items)) (items (butlast items (- (length items) max))) ;; convert the item to a full plist (items (mapcar (lambda (item) @@ -1574,9 +1571,10 @@ authentication tokens: returned-keys)) plist)) items))) - ;; if we need to create an entry AND none were found to match - (when (and create - (not items)) + (cond + ;; if we need to create an entry AND none were found to match + ((and create + (not items)) ;; create based on the spec and record the value (setq items (or @@ -1589,6 +1587,11 @@ authentication tokens: ;; the result will be returned, even if the search fails (apply 'auth-source-plstore-search (plist-put spec :create nil))))) + ((and delete + item-names) + (dolist (item-name item-names) + (plstore-delete store item-name)) + (plstore-save store))) items)) (defun* auth-source-plstore-create (&rest spec diff --git a/lisp/gnus/plstore.el b/lisp/gnus/plstore.el index 360388d002e..8d973a9b0ae 100644 --- a/lisp/gnus/plstore.el +++ b/lisp/gnus/plstore.el @@ -337,6 +337,24 @@ SECRET-KEYS is a plist containing secret data." (cons (cons name secret-plist) (plstore--get-secret-alist plstore))))) (plstore--merge-secret plstore))) +(defun plstore-delete (plstore name) + "Delete an entry with NAME from PLSTORE." + (let ((entry (assoc name (plstore--get-alist plstore)))) + (if entry + (plstore--set-alist + plstore + (delq entry (plstore--get-alist plstore)))) + (setq entry (assoc name (plstore--get-secret-alist plstore))) + (if entry + (plstore--set-secret-alist + plstore + (delq entry (plstore--get-secret-alist plstore)))) + (setq entry (assoc name (plstore--get-merged-alist plstore))) + (if entry + (plstore--set-merged-alist + plstore + (delq entry (plstore--get-merged-alist plstore)))))) + (defvar pp-escape-newlines) (defun plstore-save (plstore) "Save the contents of PLSTORE associated with a FILE."