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