art-helpers

simple helper scripts for managing images processed by ART
git clone https://git.clttr.info/art-helpers.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 3c0250f27937d1858c35cb494cffd2f132e8ec3b
parent 83e1ce87cb589fa34c39f9da7ddd9e349d56f636
Author: René Wagner <apollo@rw-net.de>
Date:   Thu,  2 Jan 2020 21:06:25 +0100

fixes #5 and #8

silkypix_multiversion_sidecar_cleaner.pl: handle file version greater 9 correctly
README.md: remove unused Perl modules

Diffstat:
A.gitignore | 1+
Msilkypix_multiversion_sidecar_cleaner.pl | 33++++++++++-----------------------
2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +testdir diff --git a/silkypix_multiversion_sidecar_cleaner.pl b/silkypix_multiversion_sidecar_cleaner.pl @@ -14,7 +14,7 @@ use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; -my $VERSION = '0.3'; +my $VERSION = '0.5'; my $PROGRAM = 'Multiversion Sidecar Cleaner'; # read commandline switches @@ -52,7 +52,7 @@ sub delete_files foreach my $file ( @files ) { - if ( exist_newer_file($file) ) + if ( exist_newer_file($file, @files) ) { print $file .'...'; $file_counter++; @@ -76,32 +76,19 @@ sub delete_files sub exist_newer_file { - my ( $original_file ) = @_; + my ( $original_file, @files_hash ) = @_; if ( -f $original_file ) { - # build the regex for newer versions - # the version must be atleast 1 above the current version - my $filename = basename($original_file); - my @fileparts = split /\./, $filename; - - my $version_regex; - # HACK: file versions greater 8 will not be checked as the regex can't handle that atm - if ( $fileparts[2] > 8 ) - { - return 0; - } - else - { - $version_regex = '['. ($fileparts[2] + 1) .'-9]'; - } - - my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]"; + # build the regex to find all versions of this file + my @original_file_parts = split /\./, basename($original_file); + my $filefinder_regex = "$original_file_parts[0]\\.$original_file_parts[1]\\.[0-9]+\\.$original_file_parts[3]"; my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) ); - - if ( scalar @version_files ) + + foreach my $version_file ( @version_files ) { - return 1; + my @version_file_parts = split /\./, $version_file; + if ( $version_file_parts[2] > $original_file_parts[2] ) { return 1; } } }