Subject: bug#20002: closed (Re: sed: tmp file left when there are errors and -i is used)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 10 May 2015 13:46:04 +0000

Your bug report

#20002: sed: tmp file left when there are errors and -i is used

which was filed against the sed package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
20002: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20002
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: sed: tmp file left when there are errors and -i is used
From: Jim Meyering <[email-masked]>
To: David Jones <[email-masked]>, [email-masked]
Date: Sun, 10 May 2015 06:45:21 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

[David Jones reported this in http://bugs.gnu.org/20002]
Thank you for the report.
That was indeed a bug.
I have attached the patch I expect to push:

[PATCH] sed -i: don't leave behind a temporary sedXXXXXX file

For example, running a command like "sed -i s//b/ F" would fail
to remove a temporary file named sedXXXXXX (for random XXXXXX)
in the directory alongside F.
* sed/sed.c (G_file_to_unlink): New global.
(register_cleanup_file, cancel_cleanup, cleanup): New functions.
(main): Call atexit.
* sed/execute.c (open_next_file): Register for unlink.
(closedown): Call cancel_cleanup right after the rename.
* sed/sed.h: Declare two of the new functions.
* NEWS (Bug fixes): Mention it.
* testsuite/temp-file-cleanup.sh: New file.  Test for this.
* testsuite/Makefile.am (T): Add it.
Reported by David Jones in http://bugs.gnu.org/20002.

Subject: sed: tmp file left when there are errors and -i is used
From: David Jones <[email-masked]>
To: [email-masked]
Date: Wed, 4 Mar 2015 17:32:37 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

sed -i sometimes leave its temporary files around:

Here's some terminal output:

drj$ ls
foo
drj$ sed -i 's//b/' foo
sed: -e expression #1, char 0: no previous regular expression
drj$ ls
foo  sedaelyL4

Note that the sedaelyL4 file is obviously a temp file left by sed. sed
had an error because of the bad sed program. But sed should clean up
after itself.

Cheers,
 drj

The output of sed --version is:

$ sed --version
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email-masked]>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.