[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Sponge [was: Delete all after a pattern]



Quoting tomas@tuxteam.de (2019-09-03 16:23:02)
> On Tue, Sep 03, 2019 at 09:54:21AM -0400, Greg Wooledge wrote:
> > On Sat, Aug 31, 2019 at 06:28:15PM +0200, tomas@tuxteam.de wrote:
> > > Me too, I didn't know about sponge. Small, nifty utility, doing 
> > > one thing -- pretty Unixy.
> > 
> > Oh god, no.  Don't use sponge unless you enjoy data loss.
> > 
> > See <https://mywiki.wooledge.org/BashPitfalls#pf13>.
> 
> There are two possible issues there:
> 
>  - sponge doesn't close its stdin before writing to 'file'. This would 
>    be a downright error, but easy to check.
> 
>  - the issue with a crash you mention in your article (nicely written 
>    articles, BTW -- thanks for them!): well, don't do it on a 
>    "precious" file: better keep a copy around. But that would be 
>    general sound advice while mucking around with an interactive shell 
>    near your data, anyway :-)

I see nothing broken in that nice article - it is simply that sponge 
loads output into memory and then dumps memory to disk - and it is true 
that if getting interrupted during that the latter part then data is 
lost.

See "man sponge" for the details.  Quite short man page which explicitly 
describes in which corner cases writing is not done atomically and 
therefore can loose data.

I find it misleading to throw that short remark of "Oh god, no" quoted 
above: I very much doubt that these corner cases is gonna be your 
biggest causes of data loss, but oh well...


 - Jonas

-- 
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

Attachment: signature.asc
Description: signature


Reply to: