Browse code

Merge branch 'master' of /home/rene/git/photo-helpers

René Wagner authored on 03.01.2020 10:19:01
Showing 3 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+testdir
... ...
@@ -15,14 +15,13 @@ The following perl modules are required for running the scripts.
15 15
 - File::Find::Rule
16 16
 - File::Find
17 17
 - File::Spec::Functions
18
-- Switch
19 18
 
20 19
 # usage
21 20
 All scripts are commandline / shell tools which should run on *n*x and Windows when the prerequistes are met.
22 21
 
23 22
 To run a script, open a shell and invoke `perl script.pl`, on most systems it should be sufficient to just invoke `script.pl`.
24 23
 
25
-For information about parameters and usage call `script.pl -h` 
24
+For information about parameters and usage call `script.pl --help` 
26 25
 
27 26
 # generic scripts
28 27
 
... ...
@@ -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,38 +76,26 @@ 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
-	
83
+		# build the regex to find all versions of this file
84
+		my @original_file_parts = split /\./, basename($original_file);
85
+
88 86
 		# don't handle files that doesn't have a version
89
-		if ( scalar @fileparts < 4 )
87
+		if ( scalar @original_file_parts < 4 )
90 88
 		{
91 89
 			return 0;
92 90
 		}
93 91
 
94
-		my $version_regex;
95
-		# HACK: file versions greater 8 will not be checked as the regex can't handle that atm
96
-		if ( $fileparts[2] > 8 )
97
-		{
98
-			return 0;
99
-		}
100
-		else
101
-		{ 
102
-			$version_regex = '['. ($fileparts[2] + 1) .'-9]';
103
-		}
104
-		
105
-		my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]";
92
+		my $filefinder_regex = "$original_file_parts[0]\\.$original_file_parts[1]\\.[0-9]+\\.$original_file_parts[3]";
106 93
 		my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) );
107
-	
108
-		if ( scalar @version_files )
94
+		
95
+		foreach my $version_file ( @version_files )
109 96
 		{
110
-			return 1;
97
+			my @version_file_parts = split /\./, $version_file;
98
+			if ( $version_file_parts[2] > $original_file_parts[2] ) { return 1; }
111 99
 		}
112 100
 	}
113 101