Browse code

fixes #5 and #8

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

René Wagner authored on 02.01.2020 21:06:25
Showing 2 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+testdir
... ...
@@ -14,7 +14,7 @@ use Getopt::Std;
14 14
 
15 15
 $Getopt::Std::STANDARD_HELP_VERSION = 'true';
16 16
 
17
-my $VERSION = '0.3';
17
+my $VERSION = '0.5';
18 18
 my $PROGRAM = 'Multiversion Sidecar Cleaner';
19 19
 
20 20
 # read commandline switches
... ...
@@ -52,7 +52,7 @@ sub delete_files
52 52
 	
53 53
 	foreach my $file ( @files )
54 54
 	{
55
-		if ( exist_newer_file($file) )
55
+		if ( exist_newer_file($file, @files) )
56 56
 		{
57 57
 			print $file .'...';
58 58
 			$file_counter++;
... ...
@@ -76,32 +76,19 @@ sub delete_files
76 76
 
77 77
 sub exist_newer_file
78 78
 {
79
-	my ( $original_file ) = @_;
79
+	my ( $original_file, @files_hash ) = @_;
80 80
 	
81 81
 	if ( -f $original_file )
82 82
 	{
83
-		# build the regex for newer versions
84
-		# the version must be atleast 1 above the current version
85
-		my $filename = basename($original_file);
86
-		my @fileparts = split /\./, $filename;
87
-		
88
-		my $version_regex;
89
-		# HACK: file versions greater 8 will not be checked as the regex can't handle that atm
90
-		if ( $fileparts[2] > 8 )
91
-		{
92
-			return 0;
93
-		}
94
-		else
95
-		{ 
96
-			$version_regex = '['. ($fileparts[2] + 1) .'-9]';
97
-		}
98
-		
99
-		my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]";
83
+		# build the regex to find all versions of this file
84
+		my @original_file_parts = split /\./, basename($original_file);
85
+		my $filefinder_regex = "$original_file_parts[0]\\.$original_file_parts[1]\\.[0-9]+\\.$original_file_parts[3]";
100 86
 		my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) );
101
-	
102
-		if ( scalar @version_files )
87
+		
88
+		foreach my $version_file ( @version_files )
103 89
 		{
104
-			return 1;
90
+			my @version_file_parts = split /\./, $version_file;
91
+			if ( $version_file_parts[2] > $original_file_parts[2] ) { return 1; }
105 92
 		}
106 93
 	}
107 94