Project

General

Profile

Actions

Bug #524

closed

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

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

Status:
Resolved
Priority:
Normal
Category:
cmd - userland programs
Start date:
2010-12-16
Due date:
% Done:

100%

Estimated time:
Difficulty:
Tags:
Gerrit CR:
External Bug:

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.

Actions #1

Updated by Garrett D'Amore over 12 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);
Actions #2

Updated by Garrett D'Amore over 12 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.

Actions #3

Updated by Garrett D'Amore over 12 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:

Actions

Also available in: Atom PDF