Bug 42596 - sed_inplace fails on symlinks and truncates the file and backup
Summary: sed_inplace fails on symlinks and truncates the file and backup
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Maxim Sobolev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-09 16:00 UTC by Jasper Jongmans
Modified: 2002-10-19 11:34 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jasper Jongmans 2002-09-09 16:00:11 UTC
	When sed_inplace is used on files that are actually symlinks to other
	files (e.g. in the games/gltron port, e.g. system.h -> system_sdl.h) it
	does not function properly. It truncates the original file and the
	backup of that file.

Fix: 

A work around could be to use the old-style inplace using perl:
	perl -pi -e 's/foo/bar/' file.txt

	Or if perl is not available:
	sed 's/foo/bar/' file.txt >file.txt.new && mv file.txt.new file.txt
How-To-Repeat: 	% echo 'This line is long.' >test.txt
	% cat test.txt
	This line is long.
	% sed_inplace -i.bak -e 's/long/short/' test.txt
	% cat test.txt
	This line is short.
	% cat test.txt.bak
	This line is long.

	Nothing strange until now, but when using symlinks:

	% echo 'This line is long.' >test.txt
	% ln -s test.txt test.txt.ln
	% ls test.txt.ln
	lrwx------  1 aprogas  users  8 Sep  9 15:56 test.txt.ln@ -> test.txt
	% cat test.txt.ln
	This line is long.
	% sed_inplace -i.bak -e 's/long/short/' test.txt.ln
	% cat test.txt.ln
	This lin% cat test.txt.ln.bak
	This lin%
Comment 1 Ying-Chieh Liao freebsd_committer freebsd_triage 2002-09-16 18:36:50 UTC
Responsible Changed
From-To: freebsd-ports->sobomax

over to maintainer
Comment 2 Maxim Sobolev freebsd_committer freebsd_triage 2002-10-19 11:33:22 UTC
State Changed
From-To: open->closed

Should be fixed in upgrade to 2002.10.19 snapshot. Thank you for reporting!