1cdf0e10cSrcweirpackage filehelper; 2cdf0e10cSrcweir 3*9780544fSAndrew Rist#************************************************************** 4*9780544fSAndrew Rist# 5*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 6*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 7*9780544fSAndrew Rist# distributed with this work for additional information 8*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 9*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 10*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 11*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 14*9780544fSAndrew Rist# 15*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 16*9780544fSAndrew Rist# software distributed under the License is distributed on an 17*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 19*9780544fSAndrew Rist# specific language governing permissions and limitations 20*9780544fSAndrew Rist# under the License. 21*9780544fSAndrew Rist# 22*9780544fSAndrew Rist#************************************************************** 23*9780544fSAndrew Rist 24*9780544fSAndrew Rist 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse strict; 27cdf0e10cSrcweiruse warnings; 28cdf0e10cSrcweiruse strict; 29cdf0e10cSrcweiruse English; # $OSNAME, ... 30cdf0e10cSrcweiruse stringhelper; 31cdf0e10cSrcweir 32cdf0e10cSrcweirBEGIN { 33cdf0e10cSrcweir use Exporter (); 34cdf0e10cSrcweir our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); 35cdf0e10cSrcweir 36cdf0e10cSrcweir $VERSION = 1.00; 37cdf0e10cSrcweir # if using RCS/CVS, this may be preferred 38cdf0e10cSrcweir $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker 39cdf0e10cSrcweir @ISA = qw(Exporter); 40cdf0e10cSrcweir @EXPORT = qw(&dospath &unixpath &appendPath &appendClass &setPrefix &getToolsPrefix &rmkdir &getJavaPathSeparator &getJavaFileDirSeparator &getFromPathes &convertCygwinPath); 41cdf0e10cSrcweir %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], 42cdf0e10cSrcweir # your exported package globals go here, 43cdf0e10cSrcweir # as well as any optionally exported functions 44cdf0e10cSrcweir @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3); 45cdf0e10cSrcweir} 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir# ------------------------------------------------------------------------------ 49cdf0e10cSrcweir# helper, to change all file separators 50cdf0e10cSrcweirsub dospath($) 51cdf0e10cSrcweir{ 52cdf0e10cSrcweir my $sPath = shift; 53cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 54cdf0e10cSrcweir { 55cdf0e10cSrcweir # make out of '/' a '\' 56cdf0e10cSrcweir $sPath =~ s/\//\\/g; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir else 59cdf0e10cSrcweir { 60cdf0e10cSrcweir } 61cdf0e10cSrcweir return $sPath; 62cdf0e10cSrcweir} 63cdf0e10cSrcweir 64cdf0e10cSrcweirsub unixpath($) 65cdf0e10cSrcweir{ 66cdf0e10cSrcweir my $sPath = shift; 67cdf0e10cSrcweir if ($OSNAME ne "MSWin32") 68cdf0e10cSrcweir { 69cdf0e10cSrcweir # make out of '\' a '/' 70cdf0e10cSrcweir $sPath =~ s/\\/\//g; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir else 73cdf0e10cSrcweir { 74cdf0e10cSrcweir } 75cdf0e10cSrcweir return $sPath; 76cdf0e10cSrcweir} 77cdf0e10cSrcweir 78cdf0e10cSrcweir# ------------------------------------------------------------------------------ 79cdf0e10cSrcweir# sub getGlobalInstSet() 80cdf0e10cSrcweir# { 81cdf0e10cSrcweir# my $sJumbo; 82cdf0e10cSrcweir# if ($OSNAME eq "MSWin32") 83cdf0e10cSrcweir# { 84cdf0e10cSrcweir# # $sJumbo = "\\\\so-gfxcmp-lin\\jumbo_ship\\install"; 85cdf0e10cSrcweir# $sJumbo = "\\\\jumbo.germany.sun.com\\ship\\install"; 86cdf0e10cSrcweir# } 87cdf0e10cSrcweir# elsif ($OSNAME eq "cygwin") 88cdf0e10cSrcweir# { 89cdf0e10cSrcweir# $sJumbo = "//jumbo.germany.sun.com/ship/install"; 90cdf0e10cSrcweir# } 91cdf0e10cSrcweir# else 92cdf0e10cSrcweir# { 93cdf0e10cSrcweir# $sJumbo = "/net/jumbo.germany.sun.com/ship/install"; 94cdf0e10cSrcweir# } 95cdf0e10cSrcweir# return $sJumbo; 96cdf0e10cSrcweir# } 97cdf0e10cSrcweir 98cdf0e10cSrcweir# ------------------------------------------------------------------------------ 99cdf0e10cSrcweir# sub getSolarisLockFile() 100cdf0e10cSrcweir# { 101cdf0e10cSrcweir# my $sSolarisLockFile = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e"; 102cdf0e10cSrcweir# return $sSolarisLockFile; 103cdf0e10cSrcweir# } 104cdf0e10cSrcweir# 105cdf0e10cSrcweir# sub checkForSolarisLock() 106cdf0e10cSrcweir# { 107cdf0e10cSrcweir# if ($OSNAME eq "solaris") 108cdf0e10cSrcweir# { 109cdf0e10cSrcweir# # wait until the internal installer lock is gone 110cdf0e10cSrcweir# while ( -e getSolarisLockFile() ) 111cdf0e10cSrcweir# { 112cdf0e10cSrcweir# while ( -e getSolarisLockFile() ) 113cdf0e10cSrcweir# { 114cdf0e10cSrcweir# log_print( "Warning: Wait active until installer lock is gone. \n"); 115cdf0e10cSrcweir# sleep 1; 116cdf0e10cSrcweir# } 117cdf0e10cSrcweir# sleep 5; 118cdf0e10cSrcweir# } 119cdf0e10cSrcweir# log_print( "[ok], lock is gone.\n"); 120cdf0e10cSrcweir# } 121cdf0e10cSrcweir# } 122cdf0e10cSrcweir# 123cdf0e10cSrcweir# sub deleteSolarisLock() 124cdf0e10cSrcweir# { 125cdf0e10cSrcweir# if ($OSNAME eq "solaris") 126cdf0e10cSrcweir# { 127cdf0e10cSrcweir# sleep 1; 128cdf0e10cSrcweir# unlink getSolarisLockFile(); 129cdf0e10cSrcweir# 130cdf0e10cSrcweir# sleep 1; 131cdf0e10cSrcweir# if ( -e getSolarisLockFile() ) 132cdf0e10cSrcweir# { 133cdf0e10cSrcweir# # try delete the file as super user? 134cdf0e10cSrcweir# `sudo rm -f getSolarisLockFile()`; 135cdf0e10cSrcweir# sleep 1; 136cdf0e10cSrcweir# } 137cdf0e10cSrcweir# } 138cdf0e10cSrcweir# } 139cdf0e10cSrcweir 140cdf0e10cSrcweir# ------------------------------------------------------------------------------ 141cdf0e10cSrcweirsub appendPath($$) 142cdf0e10cSrcweir{ 143cdf0e10cSrcweir my $sPath = shift; 144cdf0e10cSrcweir my $sAddPath = shift; 145cdf0e10cSrcweir if ($sPath && $sAddPath) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir if (! endswith($sPath, "/") && 148cdf0e10cSrcweir ! endswith($sPath, "\\")) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir # getJavaFileDirSeparator(); 151cdf0e10cSrcweir $sPath .= "/"; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir $sPath .= $sAddPath; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir return $sPath; 156cdf0e10cSrcweir} 157cdf0e10cSrcweir 158cdf0e10cSrcweirsub appendClass($$) 159cdf0e10cSrcweir{ 160cdf0e10cSrcweir my $sPath = shift; 161cdf0e10cSrcweir my $sAddPath = shift; 162cdf0e10cSrcweir 163cdf0e10cSrcweir my $sSeparator = getJavaPathSeparator(); 164cdf0e10cSrcweir if ($sPath && $sAddPath) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir if (! endswith($sPath, $sSeparator)) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir # getJavaFileDirSeparator(); 169cdf0e10cSrcweir $sPath .= $sSeparator; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir $sPath .= $sAddPath; 172cdf0e10cSrcweir } 173cdf0e10cSrcweir return $sPath; 174cdf0e10cSrcweir} 175cdf0e10cSrcweir 176cdf0e10cSrcweir# ------------------------------------------------------------------------------ 177cdf0e10cSrcweir 178cdf0e10cSrcweirour $sPrefix; 179cdf0e10cSrcweirsub setPrefix($) 180cdf0e10cSrcweir{ 181cdf0e10cSrcweir $sPrefix = shift; 182cdf0e10cSrcweir} 183cdf0e10cSrcweir 184cdf0e10cSrcweirsub getPrefix() 185cdf0e10cSrcweir{ 186cdf0e10cSrcweir return $sPrefix; 187cdf0e10cSrcweir} 188cdf0e10cSrcweir 189cdf0e10cSrcweir# ------------------------------------------------------------------------------ 190cdf0e10cSrcweirour $programprefix; 191cdf0e10cSrcweir 192cdf0e10cSrcweir# sub getProgramPrefix($) 193cdf0e10cSrcweir# { 194cdf0e10cSrcweir# my $sDBDistinct = shift; 195cdf0e10cSrcweir# 196cdf0e10cSrcweir# my $sProgramPrefix; 197cdf0e10cSrcweir# if (! $programprefix) 198cdf0e10cSrcweir# { 199cdf0e10cSrcweir# if ($OSNAME eq "MSWin32") 200cdf0e10cSrcweir# { 201cdf0e10cSrcweir# # $programprefix = "C:/gfxcmp/programs"; 202cdf0e10cSrcweir# $programprefix = "C:"; 203cdf0e10cSrcweir# if (getPrefix() eq "performance") 204cdf0e10cSrcweir# { 205cdf0e10cSrcweir# $programprefix = "D:"; 206cdf0e10cSrcweir# } 207cdf0e10cSrcweir# $programprefix = appendPath($programprefix, "gp"); 208cdf0e10cSrcweir# } 209cdf0e10cSrcweir# elsif ($OSNAME eq "linux") 210cdf0e10cSrcweir# { 211cdf0e10cSrcweir# $programprefix = "/space/" . getPrefix() . "/programs"; 212cdf0e10cSrcweir# } 213cdf0e10cSrcweir# elsif ($OSNAME eq "solaris") 214cdf0e10cSrcweir# { 215cdf0e10cSrcweir# $programprefix = "/space/" . getPrefix() . "/programs"; 216cdf0e10cSrcweir# } 217cdf0e10cSrcweir# else 218cdf0e10cSrcweir# { 219cdf0e10cSrcweir# print "Error: This environment isn't supported yet.\n"; 220cdf0e10cSrcweir# exit(1); 221cdf0e10cSrcweir# } 222cdf0e10cSrcweir# } 223cdf0e10cSrcweir# $sProgramPrefix = appendPath($programprefix, substr($sDBDistinct, 0, 19)); 224cdf0e10cSrcweir# return $sProgramPrefix; 225cdf0e10cSrcweir# } 226cdf0e10cSrcweir# ------------------------------------------------------------------------------ 227cdf0e10cSrcweirour $toolsprefix; 228cdf0e10cSrcweir 229cdf0e10cSrcweirsub getToolsPrefix() 230cdf0e10cSrcweir{ 231cdf0e10cSrcweir my $sToolsPrefix; 232cdf0e10cSrcweir if (! $toolsprefix) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 235cdf0e10cSrcweir { 236cdf0e10cSrcweir $toolsprefix = "C:"; 237cdf0e10cSrcweir if (getPrefix() eq "performance") 238cdf0e10cSrcweir { 239cdf0e10cSrcweir $toolsprefix = "D:"; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir } 242cdf0e10cSrcweir elsif ($OSNAME eq "linux") 243cdf0e10cSrcweir { 244cdf0e10cSrcweir $toolsprefix = "/space"; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir elsif ($OSNAME eq "solaris") 247cdf0e10cSrcweir { 248cdf0e10cSrcweir $toolsprefix = "/space"; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir else 251cdf0e10cSrcweir { 252cdf0e10cSrcweir print "Error: This environment isn't supported yet.\n"; 253cdf0e10cSrcweir exit(1); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir $toolsprefix = appendPath($toolsprefix, getPrefix()); 256cdf0e10cSrcweir $toolsprefix = appendPath($toolsprefix, "tools"); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir $sToolsPrefix = $toolsprefix; 259cdf0e10cSrcweir return $sToolsPrefix; 260cdf0e10cSrcweir} 261cdf0e10cSrcweir 262cdf0e10cSrcweir# also Windows safe 263cdf0e10cSrcweirsub rmkdir($) 264cdf0e10cSrcweir{ 265cdf0e10cSrcweir my($tpath) = shift; 266cdf0e10cSrcweir my $dir; 267cdf0e10cSrcweir my $accum = ""; 268cdf0e10cSrcweir 269cdf0e10cSrcweir my @dirs = split(/\//, $tpath); 270cdf0e10cSrcweir if ( $#dirs eq 0 ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir @dirs = split("\\\\", $tpath); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir foreach $dir (@dirs) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir $accum = "$accum$dir/"; 278cdf0e10cSrcweir if($dir ne "") 279cdf0e10cSrcweir { 280cdf0e10cSrcweir if(! -d "$accum") 281cdf0e10cSrcweir { 282cdf0e10cSrcweir mkdir ($accum); 283cdf0e10cSrcweir chmod (0777,$accum); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } 286cdf0e10cSrcweir } 287cdf0e10cSrcweir} 288cdf0e10cSrcweir 289cdf0e10cSrcweir# ------------------------------------------------------------------------------ 290cdf0e10cSrcweirsub getJavaPathSeparator() 291cdf0e10cSrcweir{ 292cdf0e10cSrcweir my $ps = ":"; 293cdf0e10cSrcweir if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin") 294cdf0e10cSrcweir { 295cdf0e10cSrcweir $ps = ";"; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir return $ps; 298cdf0e10cSrcweir} 299cdf0e10cSrcweir# ------------------------------------------------------------------------------ 300cdf0e10cSrcweirsub getJavaFileDirSeparator() 301cdf0e10cSrcweir{ 302cdf0e10cSrcweir my $sfs = "/"; 303cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 304cdf0e10cSrcweir { 305cdf0e10cSrcweir $sfs = "\\"; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir return $sfs; 308cdf0e10cSrcweir} 309cdf0e10cSrcweir# ------------------------------------------------------------------------------ 310cdf0e10cSrcweirsub getFromPathes($$) 311cdf0e10cSrcweir{ 312cdf0e10cSrcweir my $sPathesIni = shift; 313cdf0e10cSrcweir my $searchvalue = shift; 314cdf0e10cSrcweir my $sResult; 315cdf0e10cSrcweir if ( -e $sPathesIni) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir local *PATHES; 318cdf0e10cSrcweir if (open(PATHES, "$sPathesIni")) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir my $line; 321cdf0e10cSrcweir while ($line = <PATHES>) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir chomp($line); 324cdf0e10cSrcweir if ($line =~ /^$searchvalue=(.*)$/) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir $sResult = $1; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir } 329cdf0e10cSrcweir close(PATHES); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir } 332cdf0e10cSrcweir return $sResult; 333cdf0e10cSrcweir} 334cdf0e10cSrcweir 335cdf0e10cSrcweirsub convertCygwinPath($) 336cdf0e10cSrcweir{ 337cdf0e10cSrcweir my $sPath = shift; 338cdf0e10cSrcweir 339cdf0e10cSrcweir if ($OSNAME eq "cygwin") 340cdf0e10cSrcweir { 341cdf0e10cSrcweir # print "Cygwin Path Patch.\n" if ($verbose); 342cdf0e10cSrcweir if ($sPath =~ /\/cygdrive\/(.)/) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir my $Letter = $1; 345cdf0e10cSrcweir $sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/; 346cdf0e10cSrcweir # print "Cygwin Path Patch: '$sPath'\n" if ($verbose); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir } 349cdf0e10cSrcweir return $sPath; 350cdf0e10cSrcweir} 351cdf0e10cSrcweir 352cdf0e10cSrcweir 353cdf0e10cSrcweir 354cdf0e10cSrcweir1; 355