From: Eli Zaretskii <eliz@gnu.org>
To: Glenn Morris <rgm@gnu.org>
Cc: 18141@debbugs.gnu.org, Vincent Lefevre <vincent@vinc17.net>,
yamaoka@jpl.org
Subject: bug#18141: 24.4.50; saving .gz file breaks file coding
Date: Wed, 06 Aug 2014 17:36:00 +0300 [thread overview]
Message-ID: <83iom5ptwv.fsf@gnu.org> (raw)
In-Reply-To: <xu7g2nnxlw.fsf@fencepost.gnu.org>
> From: Glenn Morris <rgm@gnu.org>
> Date: Tue, 05 Aug 2014 04:34:35 -0400
> Cc: Katsumi Yamaoka <yamaoka@jpl.org>
>
> Perhaps someone could bisect this to find the cause?
I looked into this bug. It is a side effect of the following commit:
revno: 111638
fixes bug: http://debbugs.gnu.org/13522
committer: Glenn Morris <rgm@gnu.org>
branch nick: trunk
timestamp: Wed 2013-01-30 22:35:45 -0800
message:
Reduce delay between backing up a file and saving new version
* lisp/files.el (basic-save-buffer-2):
Choose coding system for writing the file before backing it up.
* src/fileio.c (choose_write_coding_system): Make it callable from Lisp.
(Fwrite_region): If coding-system-for-write is set, don't call
choose_write_coding_system.
Move the last piece of choose_write_coding_system here.
(syms_of_fileio): Add choose-write-coding-system.
That commit determines the encoding using the .gz file name, which of
course yields no-conversion. Thus jka-compr is forced to use
no-conversion when it writes a temporary file to be submitted to gzip.
I can fix that with the simple changes at the end of this message.
However, I'd like first to argue that the changes in the above commit
are ill-advised and should be reverted. Here's why:
. Bug#13522, which these changes were trying to solve, happens when
Emacs is killed by an external signal during the time between
backing up the original file and writing the new one. (This time
can be quite large if write-region asks the user to choose a
suitable encoding for the new content.) That is a pretty rare
situation, and IMO it's perfectly OK for Emacs to leave just the
backup file if it was brutally killed during that time window.
. The problem reported in bug#13522 exists because backing up the old
contents and writing the new one is not a transaction. The changes
in r111638 didn't change that basic fact, they just made the window
between the backup and the saving smaller, when Emacs needs to ask
the user about the encoding. But the window, albeit a smaller one,
is still there, and so it is still possible to cause the same
problem by killing Emacs at a suitably chosen opportune moment.
. The changes effectively moved the selection of the encoding to the
very beginning of write-region. By contrast, the place where
write-region calls choose-write-coding-system was carefully chosen
through a long trial-and-error process. As shown by this bug
report, doing so too early is clearly wrong for "magic" and remote
files, but it is also wrong for files whose saving needs to use
annotations, as this comment in write-region says:
/* Decide the coding-system to encode the data with.
We used to make this choice before calling build_annotations, but that
leads to problems when a write-annotate-function takes care of
unsavable chars (as was the case with X-Symbol). */
So I guess X-Symbol is likely also broken now, as are potentially
any packages that use write-annotate-functions. It took us 1.5
years to find this bug; who knows how much time will pass until we
find and fix those with write-annotate-functions, a feature that is
nowadays used very little?
If we do want to make sure the users of write-annotate-functions
are not broken, we should probably also refrain from calling
choose-write-coding-system from basic-save-buffer-2 when
write-annotate-functions are non-nil. But that means part of
write-region will now be dragged into basic-save-buffer-2. Where
does that end?
So I think simply reverting the r111638 changes and leaving bug#13522
as wontfix is an easier way out.
An even better fix would be to make the backing up and saving a
transaction-like process. That would solve the problem entirely. But
I'm not sure this is feasible/practical, with parts of the puzzle
implemented in C and parts in Lisp. If it is possible, it will
probably be anything but simple, and so likely inappropriate for the
emacs-24 branch.
Here's the patch I promised that solves this particular bug without
reverting r111638:
--- lisp/files.el~0 2014-06-29 06:54:20 +0300
+++ lisp/files.el 2014-08-06 17:26:42 +0300
@@ -4835,13 +4835,17 @@
(nth 1 setmodes)))
(set-file-modes buffer-file-name
(logior (car setmodes) 128))))))
- (let (success)
+ (let ((filename-is-magic (find-file-name-handler buffer-file-name
+ 'write-region))
+ success)
(unwind-protect
;; Pass in nil&nil rather than point-min&max to indicate
;; we're saving the buffer rather than just a region.
;; write-region-annotate-functions may make us of it.
- (let ((coding-system-for-write writecoding)
- (coding-system-require-warning nil))
+ (let ((coding-system-for-write
+ (if filename-is-magic coding-system-for-write writecoding))
+ (coding-system-require-warning
+ (if filename-is-magic coding-system-require-warning)))
(write-region nil nil
buffer-file-name nil t buffer-file-truename)
(setq success t))
next prev parent reply other threads:[~2014-08-06 14:36 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 6:59 bug#18141: 24.4.50; saving .gz file breaks file coding Katsumi Yamaoka
2014-07-30 0:10 ` Glenn Morris
2014-07-30 2:36 ` Katsumi Yamaoka
2014-07-30 13:15 ` Katsumi Yamaoka
2014-08-05 8:34 ` Glenn Morris
2014-08-06 14:36 ` Eli Zaretskii [this message]
2014-08-06 16:43 ` Vincent Lefevre
2014-08-06 17:32 ` Eli Zaretskii
2014-08-06 19:08 ` Vincent Lefevre
2014-08-06 19:45 ` Eli Zaretskii
2014-08-07 0:31 ` Vincent Lefevre
2014-08-07 12:20 ` Stefan Monnier
2014-08-07 14:23 ` Vincent Lefevre
2014-08-11 1:06 ` Glenn Morris
2014-08-06 17:48 ` Stefan Monnier
2014-08-06 18:10 ` Eli Zaretskii
2014-08-07 0:45 ` Stefan Monnier
2014-08-07 15:14 ` Eli Zaretskii
2014-08-07 19:08 ` Stefan Monnier
2014-08-07 19:37 ` Eli Zaretskii
2014-08-07 20:43 ` Stefan Monnier
2014-08-08 5:51 ` Eli Zaretskii
2014-08-06 23:45 ` Glenn Morris
2014-08-07 0:03 ` Glenn Morris
2014-08-07 12:14 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83iom5ptwv.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=18141@debbugs.gnu.org \
--cc=rgm@gnu.org \
--cc=vincent@vinc17.net \
--cc=yamaoka@jpl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.