From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: package.el support for file: URLs Date: Sat, 14 Aug 2010 18:13:26 -0400 Message-ID: <87sk2g267t.fsf@stupidchicken.com> References: <874oh2z8kp.fsf@stupidchicken.com> <87d3tmbc80.fsf@lifelogs.com> <87sk2hdyqx.fsf_-_@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1281824021 9897 80.91.229.12 (14 Aug 2010 22:13:41 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Aug 2010 22:13:41 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 15 00:13:39 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OkOyu-0008T4-K1 for ged-emacs-devel@m.gmane.org; Sun, 15 Aug 2010 00:13:37 +0200 Original-Received: from localhost ([127.0.0.1]:38020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkOyt-0003xT-Ti for ged-emacs-devel@m.gmane.org; Sat, 14 Aug 2010 18:13:35 -0400 Original-Received: from [140.186.70.92] (port=43320 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkOyo-0003xA-8K for emacs-devel@gnu.org; Sat, 14 Aug 2010 18:13:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OkOym-0003Y1-Oi for emacs-devel@gnu.org; Sat, 14 Aug 2010 18:13:30 -0400 Original-Received: from pantheon-po41.its.yale.edu ([130.132.50.98]:45789) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OkOym-0003Xm-Mu for emacs-devel@gnu.org; Sat, 14 Aug 2010 18:13:28 -0400 Original-Received: from furry (173-14-147-246-NewEngland.hfc.comcastbusiness.net [173.14.147.246]) (authenticated bits=0) by pantheon-po41.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o7EMDQwQ032228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 14 Aug 2010 18:13:26 -0400 Original-Received: by furry (Postfix, from userid 1000) id 8C7D116D402; Sat, 14 Aug 2010 18:13:26 -0400 (EDT) In-Reply-To: <87sk2hdyqx.fsf_-_@lifelogs.com> (Ted Zlatanov's message of "Sat, 14 Aug 2010 10:01:42 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:128706 Archived-At: Ted Zlatanov writes: > Also, package.el assumes HTTP URLs so it breaks if you try to set up a > local ELPA repo. I made it work with these changes to just two > functions. The change introduces filep and uses it to determine if we > need to do: > > (package-handle-response) > (re-search-forward "^$" nil 'move) > (forward-char) > > Patch attached, please review as I don't know package.el so well. It > seems to work for me. Don't we need to do the re-search-forward and forward-char even for file:// URLs? Those lines are intended to skip over the `Content-type' and `Content-length' headers, which `url-retrieve-synchronously' produces regardless of the URL type. Also, you forgot `package-download-single' and package-x.el. I modified your patch as follows. Does it do the right thing? === modified file 'lisp/emacs-lisp/package.el' *** lisp/emacs-lisp/package.el 2010-08-09 18:05:56 +0000 --- lisp/emacs-lisp/package.el 2010-08-14 22:11:57 +0000 *************** *** 625,653 **** (let ((load-path (cons pkg-dir load-path))) (byte-recompile-directory pkg-dir 0 t))))) ! (defun package-handle-response () ! "Handle the response from the server. ! Parse the HTTP response and throw if an error occurred. ! The url package seems to require extra processing for this. This should be called in a `save-excursion', in the download buffer. It will move point to somewhere in the headers." ! ;; We assume HTTP here. ! (require 'url-http) ! (let ((response (url-http-parse-response))) ! (when (or (< response 200) (>= response 300)) ! (display-buffer (current-buffer)) ! (error "Error during download request:%s" ! (buffer-substring-no-properties (point) (progn ! (end-of-line) ! (point))))))) (defun package-download-single (name version desc requires) "Download and install a single-file package." ! (let ((buffer (url-retrieve-synchronously ! (concat (package-archive-url name) ! (symbol-name name) "-" version ".el")))) (with-current-buffer buffer ! (package-handle-response) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point)) --- 625,653 ---- (let ((load-path (cons pkg-dir load-path))) (byte-recompile-directory pkg-dir 0 t))))) ! (defun package-handle-response (url) ! "Handle the response from the server we accessed via URL. ! If URL is a HTTP URL, parse the HTTP response and signal an error ! if a HTTP error occurred. For other URL types, nothing is done. This should be called in a `save-excursion', in the download buffer. It will move point to somewhere in the headers." ! (when (equal "http" (url-type (url-generic-parse-url url))) ! (require 'url-http) ! (let ((response (url-http-parse-response))) ! (when (or (< response 200) (>= response 300)) ! (display-buffer (current-buffer)) ! (error "Error during download request:%s" ! (buffer-substring-no-properties (point) (progn ! (end-of-line) ! (point)))))))) (defun package-download-single (name version desc requires) "Download and install a single-file package." ! (let* ((url (concat (package-archive-url name) ! (symbol-name name) "-" version ".el")) ! (buffer (url-retrieve-synchronously url))) (with-current-buffer buffer ! (package-handle-response url) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point)) *************** *** 656,666 **** (defun package-download-tar (name version) "Download and install a tar package." ! (let ((tar-buffer (url-retrieve-synchronously ! (concat (package-archive-url name) ! (symbol-name name) "-" version ".tar")))) (with-current-buffer tar-buffer ! (package-handle-response) (re-search-forward "^$" nil 'move) (forward-char) (package-unpack name version) --- 656,666 ---- (defun package-download-tar (name version) "Download and install a tar package." ! (let* ((url (concat (package-archive-url name) ! (symbol-name name) "-" version ".tar")) ! (tar-buffer (url-retrieve-synchronously url))) (with-current-buffer tar-buffer ! (package-handle-response url) (re-search-forward "^$" nil 'move) (forward-char) (package-unpack name version) *************** *** 995,1003 **** (archive-url (cdr archive)) (dir (expand-file-name "archives" package-user-dir)) (dir (expand-file-name archive-name dir)) ! (buffer (url-retrieve-synchronously (concat archive-url file)))) (with-current-buffer buffer ! (package-handle-response) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point)) --- 995,1004 ---- (archive-url (cdr archive)) (dir (expand-file-name "archives" package-user-dir)) (dir (expand-file-name archive-name dir)) ! (url (concat archive-url file)) ! (buffer (url-retrieve-synchronously url))) (with-current-buffer buffer ! (package-handle-response url) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point)) *** lisp/emacs-lisp/package-x.el 2010-08-09 18:05:56 +0000 --- lisp/emacs-lisp/package-x.el 2010-08-14 22:07:23 +0000 *************** *** 133,144 **** (pkg-buffer (current-buffer)) ;; Download latest archive-contents. ! (buffer (url-retrieve-synchronously ! (concat archive-url "archive-contents")))) ;; Parse archive-contents. (set-buffer buffer) ! (package-handle-response) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point)) --- 133,144 ---- (pkg-buffer (current-buffer)) ;; Download latest archive-contents. ! (url (concat archive-url "archive-contents")) ! (buffer (url-retrieve-synchronously url))) ;; Parse archive-contents. (set-buffer buffer) ! (package-handle-response url) (re-search-forward "^$" nil 'move) (forward-char) (delete-region (point-min) (point))