1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::existence; 25cdf0e10cSrcweir 26cdf0e10cSrcweir############################# 27cdf0e10cSrcweir# Test of existence 28cdf0e10cSrcweir############################# 29cdf0e10cSrcweir 30cdf0e10cSrcweirsub exists_in_array 31cdf0e10cSrcweir{ 32cdf0e10cSrcweir my ($searchstring, $arrayref) = @_; 33cdf0e10cSrcweir 34cdf0e10cSrcweir my $alreadyexists = 0; 35cdf0e10cSrcweir 36cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$arrayref}; $i++ ) 37cdf0e10cSrcweir { 38cdf0e10cSrcweir if ( ${$arrayref}[$i] eq $searchstring) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir $alreadyexists = 1; 41cdf0e10cSrcweir last; 42cdf0e10cSrcweir } 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir return $alreadyexists; 46cdf0e10cSrcweir} 47cdf0e10cSrcweir 48cdf0e10cSrcweirsub exists_in_array_of_hashes 49cdf0e10cSrcweir{ 50cdf0e10cSrcweir my ($searchkey, $searchvalue, $arrayref) = @_; 51cdf0e10cSrcweir 52cdf0e10cSrcweir my $valueexists = 0; 53cdf0e10cSrcweir 54cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$arrayref}; $i++ ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir my $hashref = ${$arrayref}[$i]; 57cdf0e10cSrcweir 58cdf0e10cSrcweir if ( $hashref->{$searchkey} eq $searchvalue ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir $valueexists = 1; 61cdf0e10cSrcweir last; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir return $valueexists; 66cdf0e10cSrcweir} 67cdf0e10cSrcweir 68cdf0e10cSrcweir##################################################################### 69cdf0e10cSrcweir# Returning a specified file as base for the new 70cdf0e10cSrcweir# configuration file, defined by its "gid" 71cdf0e10cSrcweir##################################################################### 72cdf0e10cSrcweir 73cdf0e10cSrcweirsub get_specified_file 74cdf0e10cSrcweir{ 75cdf0e10cSrcweir my ($filesarrayref, $searchgid) = @_; 76cdf0e10cSrcweir 77cdf0e10cSrcweir my $foundfile = 0; 78cdf0e10cSrcweir my $onefile; 79cdf0e10cSrcweir 80cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir $onefile = ${$filesarrayref}[$i]; 83cdf0e10cSrcweir my $filegid = $onefile->{'gid'}; 84cdf0e10cSrcweir 85cdf0e10cSrcweir if ( $filegid eq $searchgid ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir $foundfile = 1; 88cdf0e10cSrcweir last; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir my $errorline = "ERROR: Could not find file $searchgid in list of files!"; 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( $installer::globals::patch) { $errorline = "ERROR: Could not find file $searchgid in list of files! intro.bmp must be part of every patch. Please assign the flag PATCH in scp2 project."; } 95cdf0e10cSrcweir 96cdf0e10cSrcweir if (!($foundfile)) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir installer::exiter::exit_program($errorline, "get_specified_file"); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir return $onefile; 102cdf0e10cSrcweir} 103cdf0e10cSrcweir 104cdf0e10cSrcweir##################################################################### 105cdf0e10cSrcweir# Returning a specified file as base for a new file, 106cdf0e10cSrcweir# defined by its "Name" 107cdf0e10cSrcweir##################################################################### 108cdf0e10cSrcweir 109cdf0e10cSrcweirsub get_specified_file_by_name 110cdf0e10cSrcweir{ 111cdf0e10cSrcweir my ($filesarrayref, $searchname) = @_; 112cdf0e10cSrcweir 113cdf0e10cSrcweir my $foundfile = 0; 114cdf0e10cSrcweir my $onefile; 115cdf0e10cSrcweir 116cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir $onefile = ${$filesarrayref}[$i]; 119cdf0e10cSrcweir my $filename = $onefile->{'Name'}; 120cdf0e10cSrcweir 121cdf0e10cSrcweir if ( $filename eq $searchname ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir $foundfile = 1; 124cdf0e10cSrcweir last; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir if (!($foundfile)) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir installer::exiter::exit_program("ERROR: Could not find file $searchname in list of files!", "get_specified_file_by_name"); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir return $onefile; 134cdf0e10cSrcweir} 135cdf0e10cSrcweir 136cdf0e10cSrcweir##################################################################### 137cdf0e10cSrcweir# Checking existence of a specific file, defined by its "Name" 138cdf0e10cSrcweir##################################################################### 139cdf0e10cSrcweir 140cdf0e10cSrcweirsub filename_exists_in_filesarray 141cdf0e10cSrcweir{ 142cdf0e10cSrcweir my ($filesarrayref, $searchname) = @_; 143cdf0e10cSrcweir 144cdf0e10cSrcweir my $foundfile = 0; 145cdf0e10cSrcweir 146cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir my $onefile = ${$filesarrayref}[$i]; 149cdf0e10cSrcweir my $filename = $onefile->{'Name'}; 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( $filename eq $searchname ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir $foundfile = 1; 154cdf0e10cSrcweir last; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir return $foundfile; 159cdf0e10cSrcweir} 160cdf0e10cSrcweir 161cdf0e10cSrcweir##################################################################### 162cdf0e10cSrcweir# Checking existence of a specific file, defined by its "gid" 163cdf0e10cSrcweir##################################################################### 164cdf0e10cSrcweir 165cdf0e10cSrcweirsub filegid_exists_in_filesarray 166cdf0e10cSrcweir{ 167cdf0e10cSrcweir my ($filesarrayref, $searchgid) = @_; 168cdf0e10cSrcweir 169cdf0e10cSrcweir my $foundfile = 0; 170cdf0e10cSrcweir 171cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir my $onefile = ${$filesarrayref}[$i]; 174cdf0e10cSrcweir my $filegid = $onefile->{'gid'}; 175cdf0e10cSrcweir 176cdf0e10cSrcweir if ( $filegid eq $searchgid ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir $foundfile = 1; 179cdf0e10cSrcweir last; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir return $foundfile; 184cdf0e10cSrcweir} 185cdf0e10cSrcweir 186cdf0e10cSrcweir1; 187