Bug #524
sed -i usage: link("test", "test-e") Err#17 EEXIST
100%
Description
Illumos-gate revision 13258, debug build.
$ echo "test" > test
$ sed -i -e 's/test/test123/' test
$ sed -i -e 's/test/test123/' test
sed: link(): File exists
$ truss -t link sed -i -e 's/test/test123/' test
link("test", "test-e") Err#17 EEXIST
sed: link(): File exists
$ sed -i "" -e 's/test/test123/' test
It seems on FreeBSD sed replaces a backup file.
History
Updated by Garrett D'Amore over 9 years ago
- Assignee set to Garrett D'Amore
This is a regression I introduced. (The FreeBSD code used rename, instead of link. I changed that because the rename method left the possibility of exiting without leaving even the original file intact.)
Fortunately, the fix is super easy.
diff -r feaf4b4bed62 usr/src/cmd/sed/main.c
--- a/usr/src/cmd/sed/main.c Wed Dec 15 22:28:29 2010 -0800
+++ b/usr/src/cmd/sed/main.c Thu Dec 16 08:09:33 2010 -0800
@@ -336,6 +336,8 @@
if (infile != NULL) {
(void) fclose(infile);
if (*oldfname != '\0') {
+ /* if there was an backup file, remove it */
+ (void) unlink(oldfname);
if (link(fname, oldfname) != 0) {
warn("link()");
(void) unlink(tmpfname);
Updated by Garrett D'Amore over 9 years ago
Btw, -i requires an argument. Apparently GNU sed doesn't. Not sure how that is achieved, but this might be a GNUism that we don't quite achieve.
Updated by Garrett D'Amore over 9 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
Pushed with:
changeset: 13259:8dc1138162bb
tag: tip
user: Garrett D'Amore <garrett@nexenta.com>
date: Thu Dec 16 09:43:44 2010 -0800
description:
524 sed -i usage: link("test", "test-e") Err#17 EEXIST
Reviewed by: matt@greenviolet.net
Reviewed by: meths@btinternet.com
Reviewed by: gwr@nexenta.com
Approved by: gwr@nexenta.com