(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
(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"
(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
;;; Code:
+(require 'cl-seq)
(require 'dired)
(require 'ert)
(require 'ert-x)
;; 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))