From 95b5d54bac9dc0cb47c67444c9e19c1d68b0d520 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 25 Apr 2022 16:34:51 +0200 Subject: [PATCH] =?utf8?q?SL:Webdav:File.pm->store:=20unge=C3=A4nderte=20D?= =?utf8?q?okumente=20nicht=20doppelt=20speichern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Einfacher Größenvergleich mit letzter Version. --- SL/Webdav/File.pm | 16 ++++++++++++++++ SL/Webdav/Object.pm | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/SL/Webdav/File.pm b/SL/Webdav/File.pm index 313c9ff31..54af37a3a 100644 --- a/SL/Webdav/File.pm +++ b/SL/Webdav/File.pm @@ -58,6 +58,19 @@ sub store { $params{new_version} = 1; } + # Do not create a new version of the document if file size of last version is the same. + if ($params{new_version}) { + my $last_file_size = $last->size; + my $new_file_size; + if ($params{file}) { + croak 'No valid file' unless -f $params{file}; + $new_file_size = (stat($params{file}))[7]; + } else { + $new_file_size = length(${ $params{data} }); + } + $params{new_version} = 0 if $last_file_size == $new_file_size; + } + if ($params{new_version}) { my $new_version = $self->webdav->version_scheme->next_version($last); my $sep = $self->webdav->version_scheme->separator; @@ -153,6 +166,9 @@ C and C are exclusive. If param C is set, force a new version, even if the versioning scheme would keep the old one. +No new version is stored if the file or data size is euqal to the size of +the last stored version. + =back =head1 SEE ALSO diff --git a/SL/Webdav/Object.pm b/SL/Webdav/Object.pm index 8779d0961..e4ece7969 100644 --- a/SL/Webdav/Object.pm +++ b/SL/Webdav/Object.pm @@ -42,6 +42,10 @@ sub full_filedescriptor { File::Spec->catfile($self->webdav->webdav_path, $self->filename); } +sub size { + ($_[0]->stat)[7]; +} + sub atime { DateTime->from_epoch(epoch => ($_[0]->stat)[8]); } @@ -132,6 +136,10 @@ Returns the version string. Returns the extension. +=item C + +wrapped stat[7] + =item C L wrapped stat[8] -- 2.20.1