[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: potential addition of sponge to POSIX
|
From: |
Marc Chantreux |
|
Subject: |
Re: potential addition of sponge to POSIX |
|
Date: |
Sat, 21 Jun 2025 15:56:48 +0200 |
On Fri, Jun 20, 2025 at 09:21:28AM -0400, Michael Stone wrote:
> I agree with this, and question why the austin group is considering it at
> all.
well. I shell almost every day for about 30 years now and I'm really
happy about this because sponge is so convenient.
I wrote my own version of it (called bob) because I needed a -u (update)
flag: change the dest only if the new content differs to the old one.
Usecase:
* an awk script generating hundred of dot files from 1 index file
* a Makefile to get postscript files out of the dotfiles
so
print > base".dot"
became
print | "bob -u "base".dot"
and I spared many dot commands.
> The atomicity guarantees in sponge are too contingent and not
> discoverable (at least without as much work as it would take to reimplement
> sponge).
yet, the only thing to get it is just to close stdin before opening the
dest. a simplified perl version of bob would be:
#! /usr/bin/env perl
use strict;
use warnings;
use autodie;
# all inputs will be slurped as raw bytes
use open qw< :std IO :raw >;
my $dest = shift or die "a dest file expected";
undef $/; # slurp mode :)
my $in = <STDIN>; close STDIN;
$_ = do {
open my $fh, '<' , $dest;
<$fh>
};
exit if $_ eq $in;
open my $fh, '>' , $dest;
print $fh $in;
--
Marc Chantreux
Pôle CESAR (Calcul et services avancés à la recherche)
Université de Strasbourg
14 rue René Descartes,
BP 80010, 67084 STRASBOURG CEDEX
03.68.85.60.79
- potential addition of sponge to POSIX, Eric Blake, 2025/06/19
- Re: potential addition of sponge to POSIX, Pádraig Brady, 2025/06/19
- Re: potential addition of sponge to POSIX, Marc Chantreux, 2025/06/19
- Re: potential addition of sponge to POSIX, Pádraig Brady, 2025/06/19
- Re: potential addition of sponge to POSIX, Marc Chantreux, 2025/06/20
- Re: potential addition of sponge to POSIX, Michael Stone, 2025/06/20
- Re: potential addition of sponge to POSIX,
Marc Chantreux <=
- Re: potential addition of sponge to POSIX, Rob Landley, 2025/06/26
- Re: potential addition of sponge to POSIX, Marc Chantreux, 2025/06/27
- Re: potential addition of sponge to POSIX, Bernhard Voelker, 2025/06/20
- Re: potential addition of sponge to POSIX, Marc Chantreux, 2025/06/20
File a request to Austin group ?, Marc Chantreux, 2025/06/19