summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/comp.el25
-rw-r--r--lisp/emacs-lisp/package.el31
2 files changed, 55 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 6c152136fb5..3845827f661 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -2277,6 +2277,31 @@ Prepare every function for final compilation and drive the C back-end."
;; Some entry point support code.
+(defun comp--replace-output-file (outfile tmpfile)
+ "Replace OUTFILE with TMPFILE taking the necessary steps when
+dealing with shared libraries that may be loaded into Emacs"
+ (cond ((eq 'windows-nt system-type)
+ (ignore-errors (delete-file outfile))
+ (let ((retry t))
+ (while retry
+ (setf retry nil)
+ (condition-case _
+ (progn
+ ;; outfile maybe recreated by another Emacs in
+ ;; between the following two rename-file calls
+ (if (file-exists-p outfile)
+ (rename-file outfile (make-temp-file-internal
+ (file-name-sans-extension outfile)
+ nil ".eln.old" nil)
+ t))
+ (rename-file tmpfile outfile nil))
+ (file-already-exists (setf retry t))))))
+ ;; Remove the old eln instead of copying the new one into it
+ ;; to get a new inode and prevent crashes in case the old one
+ ;; is currently loaded.
+ (t (delete-file outfile)
+ (rename-file tmpfile outfile))))
+
(defvar comp-files-queue ()
"List of Elisp files to be compiled.")
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 808e4f34fc5..4288d906ef5 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2204,6 +2204,35 @@ If some packages are not installed propose to install them."
(equal (cadr (assq (package-desc-name pkg) package-alist))
pkg))
+(defun package--delete-directory (dir)
+ "Delete DIR recursively.
+In Windows move .eln and .eln.old files that can not be deleted
+to `package-user-dir'."
+ (cond ((eq 'windows-nt system-type)
+ (let ((retry t))
+ (while retry
+ (setf retry nil)
+ (condition-case err
+ (delete-directory dir t)
+ (file-error
+ (cl-destructuring-bind (reason1 reason2 filename) err
+ (if (and (string= "Removing old name" reason1)
+ (string= "Permission denied" reason2)
+ (string-prefix-p (expand-file-name package-user-dir)
+ filename)
+ (or (string-suffix-p ".eln" filename)
+ (string-suffix-p ".eln.old" filename)))
+ (progn
+ (rename-file filename
+ (make-temp-file-internal
+ (concat package-user-dir
+ (file-name-base filename))
+ nil ".eln.old" nil)
+ t)
+ (setf retry t))
+ (signal (car err) (cdr err)))))))))
+ (t (delete-directory dir t))))
+
(defun package-delete (pkg-desc &optional force nosave)
"Delete package PKG-DESC.
@@ -2256,7 +2285,7 @@ If NOSAVE is non-nil, the package is not removed from
(package-desc-name pkg-used-elsewhere-by)))
(t
(add-hook 'post-command-hook #'package-menu--post-refresh)
- (delete-directory dir t)
+ (package--delete-directory dir)
;; Remove NAME-VERSION.signed and NAME-readme.txt files.
;;
;; NAME-readme.txt files are no longer created, but they