aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2019-05-31 00:54:05 -0400
committerStefan Monnier2019-05-31 00:54:05 -0400
commitb3df3729596332a39404c364798a61bfef2adcc2 (patch)
treee58793c048b3b3f6f78a44a80567fc9618ee98b0
parent134edc10367a8434167656e631865c85b5f10c42 (diff)
downloademacs-b3df3729596332a39404c364798a61bfef2adcc2.tar.gz
emacs-b3df3729596332a39404c364798a61bfef2adcc2.zip
* lisp/emacs-lisp/package.el: Obey buffer-file-coding-system (bug#35739)
`url-insert-file-contents` saves in buffer-file-coding-system the coding-system used to decode the contents. Preserve this as the contents is moved from buffer to string to buffer, and use it when saving the contents to file, so as to try and better preserve the original byte sequence. (package--buffer-string, package--cs): New functions. (package--check-signature): Encode `string` if a coding-system was specified in buffer-file-coding-system. (package--download-one-archive, package-install-from-archive): Obey and preserve the buffer-file-coding-system if specified. Do not merge.
-rw-r--r--lisp/emacs-lisp/package.el36
1 files changed, 27 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 1a185de4a52..46f7c912726 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1241,6 +1241,17 @@ errors."
1241 (signal 'bad-signature (list sig-file))) 1241 (signal 'bad-signature (list sig-file)))
1242 good-signatures))) 1242 good-signatures)))
1243 1243
1244(defun package--buffer-string ()
1245 (let ((string (buffer-string)))
1246 (when (and buffer-file-coding-system
1247 (> (length string) 0))
1248 (put-text-property 0 1 'package--cs buffer-file-coding-system string))
1249 string))
1250
1251(defun package--cs (string)
1252 (and (> (length string) 0)
1253 (get-text-property 0 'package--cs string)))
1254
1244(defun package--check-signature (location file &optional string async callback unwind) 1255(defun package--check-signature (location file &optional string async callback unwind)
1245 "Check signature of the current buffer. 1256 "Check signature of the current buffer.
1246Download the signature file from LOCATION by appending \".sig\" 1257Download the signature file from LOCATION by appending \".sig\"
@@ -1260,8 +1271,12 @@ Otherwise, an error is signaled.
1260 1271
1261UNWIND, if provided, is a function to be called after everything 1272UNWIND, if provided, is a function to be called after everything
1262else, even if an error is signaled." 1273else, even if an error is signaled."
1263 (let ((sig-file (concat file ".sig")) 1274 (let* ((sig-file (concat file ".sig"))
1264 (string (or string (buffer-string)))) 1275 (string (or string (package--buffer-string)))
1276 (cs (package--cs string)))
1277 ;; Re-encode the downloaded file with the coding-system with which
1278 ;; it was decoded, so we (hopefully) get the exact same bytes back.
1279 (when cs (setq string (encode-coding-string string cs)))
1265 (package--with-response-buffer location :file sig-file 1280 (package--with-response-buffer location :file sig-file
1266 :async async :noerror t 1281 :async async :noerror t
1267 ;; Connection error is assumed to mean "no sig-file". 1282 ;; Connection error is assumed to mean "no sig-file".
@@ -1529,7 +1544,7 @@ similar to an entry in `package-alist'. Save the cached copy to
1529 :error-form (package--update-downloads-in-progress archive) 1544 :error-form (package--update-downloads-in-progress archive)
1530 (let* ((location (cdr archive)) 1545 (let* ((location (cdr archive))
1531 (name (car archive)) 1546 (name (car archive))
1532 (content (buffer-string)) 1547 (content (package--buffer-string))
1533 (dir (expand-file-name (format "archives/%s" name) package-user-dir)) 1548 (dir (expand-file-name (format "archives/%s" name) package-user-dir))
1534 (local-file (expand-file-name file dir))) 1549 (local-file (expand-file-name file dir)))
1535 (when (listp (read content)) 1550 (when (listp (read content))
@@ -1538,7 +1553,8 @@ similar to an entry in `package-alist'. Save the cached copy to
1538 (member name package-unsigned-archives)) 1553 (member name package-unsigned-archives))
1539 ;; If we don't care about the signature, save the file and 1554 ;; If we don't care about the signature, save the file and
1540 ;; we're done. 1555 ;; we're done.
1541 (progn (let ((coding-system-for-write 'utf-8)) 1556 (progn (let ((coding-system-for-write
1557 (or (package--cs content) 'utf-8)))
1542 (write-region content nil local-file nil 'silent)) 1558 (write-region content nil local-file nil 'silent))
1543 (package--update-downloads-in-progress archive)) 1559 (package--update-downloads-in-progress archive))
1544 ;; If we care, check it (perhaps async) and *then* write the file. 1560 ;; If we care, check it (perhaps async) and *then* write the file.
@@ -1546,7 +1562,7 @@ similar to an entry in `package-alist'. Save the cached copy to
1546 location file content async 1562 location file content async
1547 ;; This function will be called after signature checking. 1563 ;; This function will be called after signature checking.
1548 (lambda (&optional good-sigs) 1564 (lambda (&optional good-sigs)
1549 (let ((coding-system-for-write 'utf-8)) 1565 (let ((coding-system-for-write (or (package--cs content) 'utf-8)))
1550 (write-region content nil local-file nil 'silent)) 1566 (write-region content nil local-file nil 'silent))
1551 ;; Write out good signatures into archive-contents.signed file. 1567 ;; Write out good signatures into archive-contents.signed file.
1552 (when good-sigs 1568 (when good-sigs
@@ -1838,15 +1854,17 @@ if all the in-between dependencies are also in PACKAGE-LIST."
1838 (let ((save-silently t)) 1854 (let ((save-silently t))
1839 (package-unpack pkg-desc)) 1855 (package-unpack pkg-desc))
1840 ;; If we care, check it and *then* write the file. 1856 ;; If we care, check it and *then* write the file.
1841 (let ((content (buffer-string))) 1857 (let ((content (package--buffer-string)))
1842 (package--check-signature 1858 (package--check-signature
1843 location file content nil 1859 location file content nil
1844 ;; This function will be called after signature checking. 1860 ;; This function will be called after signature checking.
1845 (lambda (&optional good-sigs) 1861 (lambda (&optional good-sigs)
1846 ;; Signature checked, unpack now. 1862 ;; Signature checked, unpack now.
1847 (with-temp-buffer (insert content) 1863 (with-temp-buffer
1848 (let ((save-silently t)) 1864 (insert content)
1849 (package-unpack pkg-desc))) 1865 (setq buffer-file-coding-system (package--cs content))
1866 (let ((save-silently t))
1867 (package-unpack pkg-desc)))
1850 ;; Here the package has been installed successfully, mark it as 1868 ;; Here the package has been installed successfully, mark it as
1851 ;; signed if appropriate. 1869 ;; signed if appropriate.
1852 (when good-sigs 1870 (when good-sigs