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 iP1LJE9ySF/XLgAAsNZ9tg (envelope-from ) for ; Fri, 28 Aug 2020 02:56:15 +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 GL2IH09ySF9AbgAAB5/wlQ (envelope-from ) for ; Fri, 28 Aug 2020 02:56:15 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (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 A6D459404CF for ; Fri, 28 Aug 2020 02:56:13 +0000 (UTC) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 271C9F8DBB; Thu, 27 Aug 2020 22:56:11 -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=AARVOTIalK2G1ieX7kz6TjWv94M=; b=R3MMGWtlvaMWvvX+QMSf gctjrNnCQqkaqADKGM9K5v3/de2UyxpKfgmMVMGoINl4DZJWDQP+LG7bu/aaimfV jNMlML2lFcJFffXaJhBXhQuK+dN1DS06C7QAxYH6bB8QHFd7nNeCFBqkxQzljhbf 7IGgw89SgHZpL8wl3cyunX4= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 20242F8DBA; Thu, 27 Aug 2020 22:56:11 -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=o/GDng1qj08ZSc2VbOO+tJTzkIRzyYurZoTOYsmsZu0=; b=w+lNQYJ7WogzaOT2o4t324wRXuTawieY9RTfGUIF6g6qZXoG27+hcktm+3Sd2VP3ircYPtTU6wTeq2pTlKHA/lWnhROPV3ozJjSdiGllCPt+8WvjEKMUy/Se1FuKoGOmpLkgrfITlRk/iRJdn8Qo0kVpaMFTNCtvCbOIUa9qS1g= 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-smtp21.pobox.com (Postfix) with ESMTPSA id 8BE77F8DB9; Thu, 27 Aug 2020 22:56:08 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] Switch downloads to url-retrieve-synchronously Date: Thu, 27 Aug 2020 22:56:05 -0400 Message-Id: <20200828025605.1106-1-kyle@kyleam.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Pobox-Relay-ID: 05C9A702-E8DA-11EA-ABD3-843F439F7C89-24757444!pb-smtp21.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=R3MMGWtl; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=w+lNQYJ7; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 173.228.157.53 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: KfIGqA0mcyoG piem-download-and-decompress uses url-retrieve and a callback, setting url-asynchronous to nil. This approach doesn't seem to be sufficient because I'm getting intermittent failures in piem-b4--get-am-files related to unfinished processes. And taking a peek at url-retrieve-synchronously suggests that indeed a good amount more is needed to do a synchronous call with url-retrieve. Switch piem-download-and-decompress over to url-retrieve-synchronously. I haven't noticed any issues with the url-retrieve call in piem-inject-thread-into-maildir, but switch that over too for simplicity and consistency. --- piem-b4.el | 11 ++++---- piem.el | 75 +++++++++++++++++++++++++----------------------------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index 39d32be..6de0d2b 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -68,12 +68,11 @@ (defun piem-b4--get-am-files (mid coderepo args) (buffer (condition-case nil (piem-download-and-decompress (concat url mid "/t.mbox.gz")) - (user-error nil)))) - (when (buffer-live-p buffer) - (with-current-buffer buffer - (write-region nil nil mbox-thread)) - (kill-buffer buffer) - (setq local-mbox-p t)))) + (error nil)))) + (with-current-buffer buffer + (write-region nil nil mbox-thread)) + (kill-buffer buffer) + (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" diff --git a/piem.el b/piem.el index ef92e73..42646a0 100644 --- a/piem.el +++ b/piem.el @@ -34,6 +34,7 @@ (require 'subr-x) (require 'url) =20 (defvar url-http-end-of-headers) +(defvar url-http-response-status) =20 =0C ;;;; Options @@ -403,20 +404,19 @@ (defun piem--url-decompress () (delete-region (point) (point-max)) (goto-char (point-min))) =20 -(defun piem--decompress-callback (status) - (if (plist-get status :error) - (kill-buffer (current-buffer)) - (piem--url-remove-header) - (piem--url-decompress))) - (defun piem-download-and-decompress (url) "Retrieve gzipped content at URL and decompress it. -A buffer with the decompressed content is returned. A live -buffer indicates that the request did not result in an error." +A buffer with the decompressed content is returned." (unless (piem-check-gunzip) (user-error "gunzip executable not found")) - (let ((url-asynchronous nil)) - (url-retrieve url #'piem--decompress-callback))) + (when-let ((buffer (url-retrieve-synchronously url 'silent))) + (with-current-buffer buffer + (if (/=3D url-http-response-status 200) + (progn (kill-buffer buffer) + (error "Download of %s failed" url)) + (piem--url-remove-header) + (piem--url-decompress)) + buffer))) =20 =0C ;;;; Maildir injection @@ -460,29 +460,6 @@ (defun piem--write-mbox-to-maildir () (goto-char end))) (cons n-added n-skipped))) =20 -(defun piem--inject-thread-callback (status mid message-only) - (let ((buffer (current-buffer))) - (unwind-protect - (let ((error-status (plist-get status :error))) - (if error-status - (signal (car error-status) (cdr error-status)) - (piem--url-remove-header) - (unless message-only - (piem--url-decompress)) - (pcase-let ((`(,added-count . ,skipped-count) - (piem--write-mbox-to-maildir))) - (message "Added %d message%s%s for %s to %s" - added-count - (if (=3D added-count 1) "" "s") - (if (> skipped-count 0) - (format " (skipping %d)" skipped-count) - "") - mid - (abbreviate-file-name piem-maildir-directory))) - (run-hook-with-args 'piem-after-mail-injection-functions mid= ))) - (and (buffer-live-p buffer) - (kill-buffer buffer))))) - ;;;###autoload (defun piem-inject-thread-into-maildir (mid &optional message-only) "Inject thread containing MID into `piem-maildir-directory'. @@ -504,13 +481,31 @@ (defun piem-inject-thread-into-maildir (mid &option= al message-only) "`piem-maildir-directory' does not look like a Maildir directory")) ((not (or message-only (piem-check-gunzip))) (user-error "gunzip executable not found"))) - (url-retrieve (concat (or (piem-inbox-url) - (user-error - "Could not find inbox URL for current buffe= r")) - mid - (if message-only "/raw" "/t.mbox.gz")) - #'piem--inject-thread-callback - (list mid message-only))) + (when-let ((url (concat (or (piem-inbox-url) + (user-error + "Could not find inbox URL for current buf= fer")) + mid + (if message-only "/raw" "/t.mbox.gz"))) + (buffer (url-retrieve-synchronously url 'silent))) + (unwind-protect + (with-current-buffer buffer + (if (/=3D url-http-response-status 200) + (error "Download of %s failed" url) + (piem--url-remove-header) + (unless message-only + (piem--url-decompress)) + (pcase-let ((`(,added-count . ,skipped-count) + (piem--write-mbox-to-maildir))) + (message "Added %d message%s%s for %s to %s" + added-count + (if (=3D added-count 1) "" "s") + (if (> skipped-count 0) + (format " (skipping %d)" skipped-count) + "") + mid + (abbreviate-file-name piem-maildir-directory))) + (run-hook-with-args 'piem-after-mail-injection-functions mid= ))) + (kill-buffer buffer)))) =20 =0C ;;;; Patch handling base-commit: f028f0c1b225f1522924e052e23f88f125a4ce4a --=20 2.28.0