Skip to content

Commit

Permalink
Merge pull request #753 from hplato/master
Browse files Browse the repository at this point in the history
ical2vsdb v5.1 - added in option to sort ical prior to MD5 hash to pr…
  • Loading branch information
hplato committed Feb 21, 2018
2 parents 05d12f0 + 3b03480 commit fc1611c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions bin/ical2vsdb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use strict;
## ignore these entries and use 15 minutes for notification
## also enable a override_alarms to set a standard for all notifications ignoring what's in the ical data
## set to 'all' to remove all user specified alarm settings
## v5.1 02-2018
## Sometimes icals are unchanged, but the order is different when downloading. Add option to sort the ical to ensure
## Data hasn't changed even if the order did. Added option sort_before_md5 = 1 to enable globally or to the specific ical

use lib '../lib', '../lib/site';
use iCal::Parser;
Expand All @@ -44,10 +47,10 @@ use vsLock;
# verify locking works as expected

my $progname = "ical2vsdb";
my $progver = "v5 02-2018";
my $progver = "v5.1 02-2018";
my $DB = 0;

my $days_before = -180; # defaults to avoid large vsdb databases, can be overriden
my $days_before = -180; # defaults to avoid large vsdb databases, can be overridden
my $days_after = 180; #

my $config_file = "";
Expand All @@ -59,6 +62,7 @@ my $md5file = "";
my $local_cache = "";
my $data = "";
my $override_alarms = "0"; #ignore ical alarms and always do $override_alarms in minutes speech events
my $sort_before_md5 = 0;

$config_file = $ARGV[0] if $ARGV[0];

Expand Down Expand Up @@ -200,7 +204,12 @@ while (1) {

#print "\n\n$data\n";

my $digest = md5_hex($data);
my $digest;
if ($sort_before_md5 || defined $ical_data[$loop]->{options}->{sort_before_md5}) {
$digest = md5_hex(join "\n", sort (split(/\n/,$data)));
} else {
$digest = md5_hex($data);
}

# print "Debug: MD5=$digest\n";
# print "Debug: Hash=$ical_data[$loop]->{hash}\n" if (defined $ical_data[$loop]->{hash});
Expand Down Expand Up @@ -608,34 +617,31 @@ sub init {

if ( lc $type eq "output_dir" ) {
$output_dir = $url;

}
elsif ( lc $type eq "days_before" ) {
$days_before = 0 - $url;

}
elsif ( lc $type eq "days_after" ) {
$days_after = $url;

}
elsif ( lc $type eq "sleep_delay" ) {
$sleep_time = $url;

}
elsif ( lc $type eq "md5file" ) {
$md5file = $url;

}
elsif ( lc $type eq "cfg_version" ) {
$version = $url;

}
elsif ( lc $type eq "local_cache_dir" ) {
$local_cache = $url;
}
elsif ( lc $type eq "override_alarms" ) {
$override_alarms = $url;
}
elsif ( lc $type eq "sort_before_md5" ) {
$sort_before_md5 = $url;
}
else {
$ical_data[$count]->{type} = $type;
foreach my $opt ( split /,/, lc $options ) {
Expand Down

0 comments on commit fc1611c

Please sign in to comment.