From b69ca75b91dbab0cff44e6647684ec3cf71030bb Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <andreas.romeyke@slub-dresden.de>
Date: Thu, 3 Apr 2025 13:21:16 +0200
Subject: [PATCH] - refactoring, rewrite file location and size handling to
 improve readability and efficiency

---
 perl/exit_strategy.pl | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl
index 0223437..49c4082 100644
--- a/perl/exit_strategy.pl
+++ b/perl/exit_strategy.pl
@@ -47,7 +47,7 @@ use File::Basename qw(basename dirname);
 use File::Find;
 use Getopt::Long;
 use IO::Handle;
-use List::Util qw(first);
+use List::Util qw(first zip);
 use Path::Tiny;
 use Pod::Usage;
 use Time::Progress;
@@ -689,21 +689,11 @@ sub parse_iexml($filename, $recovery_flag) {
     my $filegrp = $xp->findnodes("mets:fileGrp[\@ADMID='$repid']", $filesec)->[0];
     $ret->{"filepids"} = get_filepids_ref($xp, $filegrp);
     $ret->{"files"} = get_files_ref($xp, $filegrp);
-    my @loc_and_size = map {
-      my $fpid = $_;
-      my $location = get_file_path($xp, $filegrp, $fpid);
-      #my $location = get_file_path_rx($slurp, $fpid);
-      #say "location=$location";
-      my $size = get_filesize($xp, $fpid);
-      #my $size = get_filesize_rx($slurp, $fpid);
-      #say "size=$size";
-      [ $location, $size ];
-    } @{$ret->{"filepids"}};
-
-    foreach my $entry (@loc_and_size) {
-      my ($location, $size) = @{$entry};
-      $ret->{"sizes"}->{$location} = $size;
-    }
+    my @locations = map {get_file_path($xp, $filegrp, $_)} @{$ret->{"filepids"}};
+    my @sizes = map {get_filesize($xp, $_)} @{$ret->{"filepids"}};
+    my %ls = map { $_->[0] => $_->[1] } zip \@locations, \@sizes;
+    $ret->{"sizes"} = \%ls;
+    #use Data::Printer; p($ret);
 
     return $ret;
   }
-- 
GitLab