Bug 620401 - sed overwrites symlinks
Summary: sed overwrites symlinks
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: doc-Migration_Guide   
(Show other bugs)
Version: 6.0
Hardware: All
OS: Linux
Target Milestone: rc
: ---
Assignee: Laura Bailey
QA Contact: ecs-bugs
Keywords: Documentation, Regression
Depends On:
TreeView+ depends on / blocked
Reported: 2010-08-02 12:48 UTC by Miroslav Vadkerti
Modified: 2013-02-05 23:55 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2010-08-03 21:23:35 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Miroslav Vadkerti 2010-08-02 12:48:02 UTC
Description of problem:
sed overwrites symlinks and creates ordinary file instead. This is a Regression of bz#189016.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. touch src
2. ln -s src lnk
3. sed -i 's.o.n.g' lnk
Actual results:
lnk is overwritten

Expected results:
lnk not overwritten

Additional info:

Comment 2 Paolo Bonzini 2010-08-02 13:28:57 UTC
This change was done in Fedora 11 and is by design. 

RHEL 3 included this change without even looking at the manual or contacting upstream.  In doing so it deviated unnecessarily from what is documented in its own "info sed", from upstream, from basically all other Linux distros, and also from "perl -i" behavior.

The implementation was also bad, since there are bugs in symlink following in RHEL5 -- bug #490473 -- while realpath(3) could have been used much more simply...

RHEL6 sed provides --follow-symlinks which achieves this behavior.

I suggest documenting it in the release notes.

Comment 3 Paolo Bonzini 2010-08-02 13:32:22 UTC
From the sed manual of RHEL6

`-i' clobbers read-only files
     In short, `sed -i' will let you delete the contents of a read-only
     file, and in general the `-i' option (*note Invocation: Invoking
     sed.) lets you clobber protected files.  This is not a bug, but
     rather a consequence of how the Unix filesystem works.

     The permissions on a file say what can happen to the data in that
     file, while the permissions on a directory say what can happen to
     the list of files in that directory.  `sed -i' will not ever open
     for writing  a file that is already on disk.  Rather, it will work
     on a temporary file that is finally renamed to the original name:
     if you rename or delete files, you're actually modifying the
     contents of the directory, so the operation depends on the
     permissions of the directory, not of the file.  For this same
     reason, `sed' does not let you use `-i' on a writeable file in a
     read-only directory, and will break hard or symbolic links when
     `-i' is used on such a file.

Everything except "and will break hard or symbolic links when `-i' is used on such a file" is present also in RHEL5 (however it could be inferred from the description, which says it is renaming a temporary file to the original name).

Comment 4 Paolo Bonzini 2010-08-02 13:38:10 UTC
See also http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=339793 (comments #31 to #51 -- that's just five comments actually).

Comment 5 Denise Dumas 2010-08-02 20:26:21 UTC
Scott, Migration Guide text in comment 3

Comment 8 Denise Dumas 2010-08-03 12:51:05 UTC
Scott, this is a Migration Guide blocker for 6.0

Comment 9 Scott Radvan 2010-08-03 21:23:35 UTC
Note added to Migration Guide. Changes will appear on next publish.

Note You need to log in before you can comment on or make changes to this bug.