commit 9d949972f4fe406b860b6b9095b5742d498bca89
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:
3 files changed, 12 insertions(+), 25 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+testdir
diff --git a/README.md b/README.md
@@ -15,14 +15,13 @@ The following perl modules are required for running the scripts.
- File::Find::Rule
- File::Find
- File::Spec::Functions
-- Switch
# usage
All scripts are commandline / shell tools which should run on *n*x and Windows when the prerequistes are met.
To run a script, open a shell and invoke `perl script.pl`, on most systems it should be sufficient to just invoke `script.pl`.
-For information about parameters and usage call `script.pl -h`
+For information about parameters and usage call `script.pl --help`
# generic scripts
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; }
}
}