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):
Steps to Reproduce:
1. touch src
2. ln -s src lnk
3. sed -i 's.o.n.g' lnk
lnk is overwritten
lnk not overwritten
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.
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).
See also http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=339793 (comments #31 to #51 -- that's just five comments actually).
Scott, Migration Guide text in comment 3
Scott, this is a Migration Guide blocker for 6.0
Note added to Migration Guide. Changes will appear on next publish.