Bug #524

sed -i usage: link("test", "test-e") Err#17 EEXIST

Added by Piotr Jasiukajtis over 3 years ago. Updated over 3 years ago.

Status:Resolved Start date:2010-12-16
Priority:Normal Due date:
Assignee:Garrett D'Amore % Done:

100%

Category:cmd - userland programs Spent time: 0.50 hour
Target version:-
Difficulty:Medium Tags:needs-triage

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 3 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 3 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 3 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 <>
date: Thu Dec 16 09:43:44 2010 -0800
description:
524 sed -i usage: link("test", "test-e") Err#17 EEXIST
Reviewed by:
Reviewed by:
Reviewed by:
Approved by:

Also available in: Atom PDF