[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 21888a9: Don't rewrite buffer contents after saving
From: |
Michael Albinus |
Subject: |
[Emacs-diffs] master 21888a9: Don't rewrite buffer contents after saving by rename (Bug#35497) |
Date: |
Wed, 8 May 2019 03:14:18 -0400 (EDT) |
branch: master
commit 21888a94648df813cef354a22b92be9b23673358
Author: Jonathan Tomer <address@hidden>
Commit: Michael Albinus <address@hidden>
Don't rewrite buffer contents after saving by rename (Bug#35497)
* lisp/files.el (basic-save-buffer-2): Don't rewrite file contents
after saving-by-renaming. (Bug#35497)
* test/lisp/files-tests.el (files-tests-dont-rewrite-precious-files):
* test/lisp/net/tramp-tests.el
(tramp-test10-write-region-file-precious-flag): Regression tests
for this change.
---
lisp/files.el | 4 ++--
test/lisp/files-tests.el | 15 +++++++++++++++
test/lisp/net/tramp-tests.el | 29 +++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index 518394f..8477c22 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5258,7 +5258,7 @@ Before and after saving the buffer, this function runs
(set-file-extended-attributes buffer-file-name
(nth 1 setmodes)))
(set-file-modes buffer-file-name
- (logior (car setmodes) 128))))))
+ (logior (car setmodes) 128)))))
(let (success)
(unwind-protect
(progn
@@ -5274,7 +5274,7 @@ Before and after saving the buffer, this function runs
(and setmodes (not success)
(progn
(rename-file (nth 2 setmodes) buffer-file-name t)
- (setq buffer-backed-up nil))))))
+ (setq buffer-backed-up nil)))))))
setmodes))
(declare-function diff-no-select "diff"
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index ae8ea41..fe2e958 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1244,5 +1244,20 @@ See <https://debbugs.gnu.org/35241>."
(executable-find (file-name-nondirectory tmpfile))))))
(delete-file tmpfile))))
+(ert-deftest files-tests-dont-rewrite-precious-files ()
+ "Test that `file-precious-flag' forces files to be saved by
+renaming only, rather than modified in-place."
+ (let* ((temp-file-name (make-temp-file "files-tests"))
+ (advice (lambda (_start _end filename &rest _r)
+ (should-not (string= filename temp-file-name)))))
+ (unwind-protect
+ (with-current-buffer (find-file-noselect temp-file-name)
+ (advice-add #'write-region :before advice)
+ (setq-local file-precious-flag t)
+ (insert "foobar")
+ (should (null (save-buffer))))
+ (ignore-errors (advice-remove #'write-region advice))
+ (ignore-errors (delete-file temp-file-name)))))
+
(provide 'files-tests)
;;; files-tests.el ends here
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 7d3c434..e35be0e 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -41,6 +41,7 @@
;;; Code:
+(require 'cl-seq)
(require 'dired)
(require 'ert)
(require 'ert-x)
@@ -2270,6 +2271,34 @@ This checks also `file-name-as-directory',
`file-name-directory',
;; Cleanup.
(ignore-errors (delete-file tmp-name))))))
+(ert-deftest tramp-test10-write-region-file-precious-flag ()
+ "Check that `file-precious-flag' is respected with Tramp in use."
+ (skip-unless (tramp--test-enabled))
+ (skip-unless (tramp--test-sh-p))
+
+ (let* ((tmp-name (tramp--test-make-temp-name))
+ written-files
+ (advice (lambda (_start _end filename &rest _r)
+ (push filename written-files))))
+
+ (unwind-protect
+ (with-current-buffer (find-file-noselect tmp-name)
+ ;; Write initial contents. Adapt `visited-file-modtime'
+ ;; in order to suppress confirmation.
+ (insert "foo")
+ (write-region nil nil tmp-name)
+ (set-visited-file-modtime)
+ ;; Run the test.
+ (advice-add 'write-region :before advice)
+ (setq-local file-precious-flag t)
+ (insert "bar")
+ (should (null (save-buffer)))
+ (should-not (cl-member tmp-name written-files :test #'string=)))
+
+ ;; Cleanup.
+ (ignore-errors (advice-remove 'write-region advice))
+ (ignore-errors (delete-file tmp-name)))))
+
(ert-deftest tramp-test11-copy-file ()
"Check `copy-file'."
(skip-unless (tramp--test-enabled))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 21888a9: Don't rewrite buffer contents after saving by rename (Bug#35497),
Michael Albinus <=