From 9c05a1ff40ffb2b1a9b14437e1b8440eaea1839c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 2 Mar 2021 01:36:05 -0700 Subject: [PATCH] Girocco/Project.pm: implement _property_fput nosetsame for file props When requested, avoid rewriting exactly the same data to file-based properties provided the file exists and can be read and contains exactly the same data that would be written. Support for this behavior for non-file-based properties already existed and this brings parity for the file-based properties. Signed-off-by: Kyle J. McKay --- Girocco/Project.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index 11897d4..9c52c67 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -258,11 +258,25 @@ sub _property_fput { return; } - my $P = lock_file($self->_property_path($pname)); + my $propfile = $self->_property_path($pname); + my $P = lock_file($propfile); chomp $value; - $value ne '' and print $P "$value\n"; + $value ne '' and $value .= "\n"; + if ($nosetsame && -e $propfile && -f _) { + if (open my $fd, '<', $propfile) { + my $contents = undef; + {local $/ = undef; $contents = <$fd>;} + close $fd; + if (defined($contents) && $contents eq $value) { + close $P; + unlock_file($propfile, 1); + return; + } + } + } + $value ne '' and print $P $value; close $P; - unlock_file($self->_property_path($pname)); + unlock_file($propfile); } sub _cleanup_datetime { -- 2.11.4.GIT