From 662c4aca93d8abea686cd90a9a4a2640a06e820e Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Wed, 26 Nov 2025 09:54:11 -0700 Subject: [PATCH 1/3] replace existing content in file rather than using spew_utf8 --- lib/Data/Section/Writer.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Data/Section/Writer.pm b/lib/Data/Section/Writer.pm index 7d34969..b77e391 100644 --- a/lib/Data/Section/Writer.pm +++ b/lib/Data/Section/Writer.pm @@ -42,6 +42,7 @@ The name of the Perl source file. If not provided then the source for the calle use Class::Tiny qw( perl_filename _files _same _formats ); use Ref::Util qw( is_coderef is_blessed_ref is_plain_arrayref ); use MIME::Base64 qw(encode_base64); + use File::Temp (); sub BUILD ($self, $) { @@ -161,8 +162,19 @@ Starting with version 0.02, this method will not write to the file if the conten $self->_same(0); } - # re-write the perl with the - $self->perl_filename->spew_utf8($perl); + if(-f $self->perl_filename) { + use autodie qw( truncate close ); + # re-write the perl to the file, using the existing inode + my $backup = Path::Tiny->new(File::Temp::tempnam($self->perl_filename->parent, $self->perl_filename->basename)); + $self->perl_filename->copy($backup) if -f $self->perl_filename; + my $fh = $self->perl_filename->openrw_utf8; + truncate $fh, 0; + print $fh $perl or die "unable to write to @{[ $self->perl_filename ]} $!"; + close $fh; + $backup->remove if -f $backup; + } else { + $self->perl_filename->spew_utf8($perl); + } return $self; } From 4d2e5421c744ec758a6a692b09ba26e7ccbdfbaf Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Wed, 26 Nov 2025 09:57:33 -0700 Subject: [PATCH 2/3] update changes --- Changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changes b/Changes index 5a03590..ad012d8 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,12 @@ Revision history for {{$dist->name}} {{$NEXT}} + - The update_file method will replace the content in an existing file + rather than creating a new one. A backup of the original file is + made while the new content is being written, in the unlikely event + of an error during content replacement. The backup will be removed + if the replacement succeeds. A new file will be created if one does + not exist, as before. (gh#6) 0.04 2024-12-15 20:35:06 -0700 - I somehow forgot how to write POD and had to fix some (gh#5) From 9760645c70651e9dead8d92fc4d11a0b877613f1 Mon Sep 17 00:00:00 2001 From: Graham Ollis Date: Wed, 26 Nov 2025 09:58:20 -0700 Subject: [PATCH 3/3] bump ci version --- .github/workflows/linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 9ffcdae..e458af9 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -34,7 +34,7 @@ jobs: CIP_TAG: ${{ matrix.cip_tag }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Bootstrap CIP run: | @@ -47,7 +47,7 @@ jobs: cip cache-key - name: Cache CPAN modules - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.cip key: ${{ runner.os }}-build-${{ steps.cache-key.outputs.key }}