From 2b183aaada174244c6241f7effe29493d701908e Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Mon, 30 Nov 2015 00:49:12 -0500 Subject: [PATCH] core: add a basic timeout of 5s to fetch elpa archive New file core-emacs-ext.el This is a basic monkey-patch solution but it will do the job for now. The timeout amount is not configurable for now. Tested on 24.5 and 24.3.1 fixes #3284 --- core/core-emacs-ext.el | 49 ++++++++++++++++++++++++++++++++++++++++++ core/core-spacemacs.el | 1 + 2 files changed, 50 insertions(+) create mode 100644 core/core-emacs-ext.el diff --git a/core/core-emacs-ext.el b/core/core-emacs-ext.el new file mode 100644 index 000000000000..75e791b67fd4 --- /dev/null +++ b/core/core-emacs-ext.el @@ -0,0 +1,49 @@ +;;; core-emacs-ext.el --- Spacemacs Core File +;; +;; Copyright (c) 2012-2014 Sylvain Benner +;; Copyright (c) 2014-2015 Sylvain Benner & Contributors +;; +;; Author: Sylvain Benner +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 +(require 'core-spacemacs-buffer) + +;; for some reason with-eval-after-load does not work here in 24.3 +;; maybe the backport is incorrect! +(eval-after-load 'package + '(progn + (defun package-refresh-contents () + "Download the ELPA archive description if needed. + This informs Emacs about the latest versions of all packages, and + makes them available for download. + +This redefinition adds a timeout of 5 seconds to contact each archive." + (interactive) + ;; the first part is not available before Emacs 24.4 so we just ignore + ;; it to be safe. + (unless (version< emacs-version "24.4") + ;; FIXME: Do it asynchronously. + (unless (file-exists-p package-user-dir) + (make-directory package-user-dir t)) + (let ((default-keyring (expand-file-name "package-keyring.gpg" + data-directory))) + (when (and package-check-signature (file-exists-p default-keyring)) + (condition-case-unless-debug error + (progn + (epg-check-configuration (epg-configuration)) + (package-import-keyring default-keyring)) + (error (message "Cannot import default keyring: %S" (cdr error))))))) + (dolist (archive package-archives) + (condition-case-unless-debug nil + (with-timeout (5 (spacemacs-buffer/warning + "Cannot contact archive %s (reason: timeout)" + (cdr archive))) + (package--download-one-archive archive "archive-contents")) + (error (message "Failed to download `%s' archive." + (car archive))))) + (package-read-all-archive-contents)))) + +(provide 'core-emacs-ext) diff --git a/core/core-spacemacs.el b/core/core-spacemacs.el index 214e20e5121e..36f3966bb447 100644 --- a/core/core-spacemacs.el +++ b/core/core-spacemacs.el @@ -25,6 +25,7 @@ (require 'core-toggle) (require 'core-micro-state) (require 'core-use-package-ext) +(require 'core-emacs-ext) (defgroup spacemacs nil "Spacemacs customizations."