[Toybox] Fwd: Re: [patch] add sed

Rob Landley rob at landley.net
Wed Aug 7 10:01:12 PDT 2013


On 08/04/2013 02:45:46 AM, Dave wrote:
> On 8/3/2013 7:25 PM, Strake wrote:
>> 
>>> Besides that there's -i, which could be done easily by open()ing a
>>> temporary file, writing to that, then renaming to the original  
>>> filename.
>> This violates the doctrine to do one thing well. Alas, users want it,
>> and scripts use it.
>> 
>> Giving flags to users is like giving cigarettes to children.
> Frequently on a space constrained device you are forced to edit large  
> files
> with ed because there is not enough temp space to create that temp  
> file.
> Frequently in a recovery situation there is zero temp space. If you  
> wanted
> to implement the -i so it /really really /edits files *i*n place, that
> would be a good reason to eliminate ed.

I'm guessing you're using ed instead of vi because the standard  
behavior of vi
is to write the new file to a temp name and then do an atomic rename  
over the
old file.

The behavior you're talking about wouldn't break hardlinks, but would  
stomp
every copy of the hardlinked file. If bad things happen partway through  
the
write your file is gone. Other users see partial file contents. If your
modification extends the file and you're _exactly_ filling up the disk,  
your
file will get truncated.

If you can't free up enough space on the filesystem to safely use sed,  
I'm
happy to provide a HEX EDITOR that will edit files in place via mmap.  
But
making sed -i do that would be a really, really bad idea.

Rob

 1375894872.0


More information about the Toybox mailing list