From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id 8OYIDOEtcF9VQwAAsNZ9tg (envelope-from ) for ; Sun, 27 Sep 2020 06:14:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0OnUB+EtcF+hQAAAB5/wlQ (envelope-from ) for ; Sun, 27 Sep 2020 06:14:57 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 26AF69404C9 for ; Sun, 27 Sep 2020 06:14:55 +0000 (UTC) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 6CD437EEB3; Sun, 27 Sep 2020 02:14:53 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-transfer-encoding; s=sasl; bh=FDhJazNaO5uAYke1GQOczX5iX4A=; b=u4TT9tlk5fNDHeamXApx VdsCyjk7JK3n18ZBbzGJohQrxQ0QNGOJA/u2m0kTV7MSs0kTZeQs1u3tR2je8Qgr PzfTSQ9fvahITeVMdoUpR44+svJFWo49yqBUlRqKUy9uoseniXVAG8RmCEO6i1NM tmprd0q4GXlbwrzIZtRnlyo= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 6515D7EEB2; Sun, 27 Sep 2020 02:14:53 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:mime-version:content-transfer-encoding; s=mesmtp; bh=1qS/Q5I8b3ex/BCe0M+4LNOmXoKd96ygjDQLGbBufcM=; b=fXFpilvx5H1WhOBJVBp4G8MKOVYkS7Dr2shaXsz7B9GNSSBTAzhwfmlUsE4bP0Wx/3VQhFg7vVgNER4JYlT43dwy/bf+lq7NntmyJVgu1b2ZK6BvIqISDgGoNnTSG1hW7wr9PWMK6HAhorToxx6FKnHj9HyqeAJ1My51dEpBvcY= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id D3ABF7EEB1; Sun, 27 Sep 2020 02:14:52 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] b4: Clean up temporary directories by default Date: Sun, 27 Sep 2020 02:14:46 -0400 Message-Id: <20200927061446.2301-1-kyle@kyleam.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Pobox-Relay-ID: C19E6B8C-0088-11EB-86D0-2F5D23BA3BAF-24757444!pb-smtp2.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=u4TT9tlk; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=fXFpilvx; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 64.147.108.71 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: EL2MciblRYO+ Each piem-b4-am-from-mid call works in a new temporary directory. Aside from debugging, there's no reason to keep these directories around, polluting temporary-file-directory. --- piem-b4.el | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index 75b2344..31bf6f1 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -50,12 +50,18 @@ (defcustom piem-b4-b4-executable "b4" =0C ;;;; Internals =20 +(defvar piem-b4-keep-temp-directory nil + "Don't clean up the directory created by `piem-b4-am-from-mid'. +This is intended to be used for debugging purposes.") + (defun piem-b4--get-am-files (mid coderepo args) (let* ((outdir (file-name-as-directory (make-temp-file "piem-b4-" t))) (root (concat outdir "m")) (mbox-thread (concat root "-piem")) - (local-mbox-p nil)) + (local-mbox-p nil) + (clean-fn (and (not piem-b4-keep-temp-directory) + (lambda () (delete-directory outdir t))))) (when-let ((fn (run-hook-with-args-until-success 'piem-mid-to-thread-functions mid))) (with-temp-file mbox-thread @@ -78,19 +84,25 @@ (defun piem-b4--get-am-files (mid coderepo args) (setq local-mbox-p t))) ;; Move to the coderepo so that we pick up any b4 configuration ;; from there. - (apply #'piem-process-call coderepo piem-b4-b4-executable "am" - (and local-mbox-p - (concat "--use-local-mbox=3D" mbox-thread)) - (concat "--outdir=3D" outdir) - (concat "--mbox-name=3Dm") - (append args (list mid))) + (condition-case err + (apply #'piem-process-call coderepo piem-b4-b4-executable "am" + (and local-mbox-p + (concat "--use-local-mbox=3D" mbox-thread)) + (concat "--outdir=3D" outdir) + (concat "--mbox-name=3Dm") + (append args (list mid))) + (piem-process-error + (when clean-fn + (funcall clean-fn)) + (signal (car err) (cdr err)))) (let ((mbox-cover (concat root ".cover")) (mbox-am (concat root ".mbx"))) (list (and (file-exists-p mbox-cover) mbox-cover) (if (file-exists-p mbox-am) mbox-am - (error "Expected mbox file does not exist: %s" mbox-am))))= )) + (error "Expected mbox file does not exist: %s" mbox-am)) + clean-fn)))) =20 =0C ;;;; Commands @@ -135,15 +147,18 @@ (defun piem-b4-am-from-mid (mid &optional args) args))) (user-error "%s is incompatible with this command" badopt)) (pcase-let* ((coderepo (piem-inbox-coderepo-maybe-read)) - (`(,cover ,mbox-file) + (`(,cover ,mbox-file ,clean-fn) (piem-b4--get-am-files mid coderepo args)) (default-directory coderepo)) - (piem-am mbox-file - nil - (with-temp-buffer - (insert-file-contents (or cover mbox-file)) - (piem-extract-mbox-info)) - coderepo))) + (unwind-protect + (piem-am mbox-file + nil + (with-temp-buffer + (insert-file-contents (or cover mbox-file)) + (piem-extract-mbox-info)) + coderepo) + (when clean-fn + (funcall clean-fn))))) =20 (define-infix-argument piem-b4-am:--outdir () :description "Output directory" base-commit: 4cc9f39ad142600eea706094d3e2a58eba13e073 --=20 2.28.0