+# return true if the files are close enough that we should consider it
+# the same picture
+sub are_the_same_files{
+ my ($f1,$f2) = @_;
+ # load the exif information if we can
+ for my $f (@_) {
+ if (-e $f->{name}) {
+ $f->{exists} = 1;
+ if (not exists $f->{info} or not defined $f->{info}) {
+ $f->{info} = ImageInfo($f->{name},[qw(CreateDate Serial)]);
+ }
+ } else {
+ $f->{exists} = 0;
+ }
+ }
+ # if the files both exist, compare some exif information
+ if (defined $f1->{info} and $f2->{info}) {
+ if ($f1->{info}{CreateDate} eq $f2->{info}{CreateDate} and
+ $f1->{info}{Serial} eq $f2->{info}{Serial}
+ ) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ # ok; can't compare exif. Compare sha256 sums
+ for my $f (@_) {
+ if (-l $f->{name}) {
+ # this is probably a git annex file
+ $f->{sha256} = git_annex_sha256($f->{name});
+ } elsif (-e $f->{name}) {
+ $f->{sha256} = calc_sha256($f->{name})
+ }
+ }
+ # if the sha256 are equal, they're the same. if not, or if we
+ # can't compare, assume they're different.
+ if (defined $f1->{sha256} and
+ defined $f2->{sha256} and
+ $f1->{sha256} eq $f2->{sha256}
+ ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub calc_sha256{
+ my ($fn) = @_;
+
+ my $sha = Digest::SHA->new(256);
+ $sha->addfile($fn);
+ return($sha->hexdigest());
+}
+
+sub git_annex_sha256 {
+ my ($fn) = @_;
+ my $info = capturex('git','-C',dirname($fn),'annex','info',basename($fn));
+ my ($sha256) = $info =~ /key:.+SHA256E-[^-]+--([^\.]+)/;
+ return $sha256;
+}
+