Select Git revision
pom.properties
slubsipbuilderbagit.t 55.73 KiB
#!/usr/bin/perl -w
#===============================================================================
# Copyright (C) 2020
# AUTHORS: Serhiy Bolkun (Serhiy.Bolkun@slub-dresden.de)
# Andreas Romeyke (Andreas.Romeyke@slub-dresden.de)
# Jens Steidl (Jens.Steidl@slub-dresden.de)
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
#===============================================================================
use strict;
use warnings;
use diagnostics;
use Test::More tests => 120;
use Test::Output;
use Test::Exception;
use Test::File;
use Path::Tiny;
use File::Copy::Recursive qw(dircopy);
use File::Path qw(rmtree);
# *** Read before running tests ***
# Usage: perl -I lib/ t/slubsipbuilderbagit.t
# Note: While running tests of "SLUB_SIP_Builder", path "tmp/bagit" will be created.
# Please start test cases in the project directory to run all tests properly.
# Tested on Win10 and Debian 10
sub workaroundBagInfoTXT($$$){
my $file_path = $_[0];
my $key = $_[1];
my $value = $_[2];
# read a data file into an array
open my $handle, '<', $file_path;
chomp(my @lines = <$handle>);
close $handle;
# grep and change certain array element
foreach my $zeile(@lines) {
my @keyvalue = split(/: /, $zeile, 2); # split on first :
if($keyvalue[0] eq $key){
$zeile = "$key: $value";
}
}
# save array back to file
open my $fh, '>', $file_path or die "Cannot open $file_path: $!";
foreach (@lines){
print $fh "$_\n"; # Print each entry in our array to the file
}
close $fh;
}
sub workaroundTagmanifest($$$){
my $file_path = $_[0];
my $key = $_[1];
my $value = $_[2];