Re: [dev] [sbase] sponge

From: markus schnalke <meillo_AT_marmaro.de>
Date: Tue, 25 Jun 2013 21:25:06 +0200

[2013-06-25 20:22] Jakob Kramer <jakob.kramer_AT_gmx.de>
>
> I wrote a sponge program, but I am not fully convinced of it yet. What
> do you think?

I think you shouldn't rename(2). Renaming a file and replacing it's
contents are quite different things. Take for example:

        $ mkdir a
        $ chmod 600 a/b

        $ touch a/b
        $ chmod 100 a

        $ echo foo >a/b # this goes well

        $ echo bar >c
        $ mv c a/b # this not
        mv: cannot move `c' to `a/b': Permission denied

Special permissions and owner/group-ships are lost as well.

Either keep the contents in memory or read-write the contents
back.

Or better use what's already available: sort(1).

        #!/bin/sh
        if $# -ne 1 ; then
                echo "Usage: ${0##*/} outfile" >&2
                exit 1
        fi
        sort -m -o "$1"

;-)


meillo
Received on Tue Jun 25 2013 - 21:25:06 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 25 2013 - 21:36:05 CEST