security/nss/coreconf/import.pl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 #! /usr/local/bin/perl
     2 #
     3 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this
     5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 print STDERR "import.pl\n";
     9 require('coreconf.pl');
    12 $returncode =0;
    15 #######-- read in variables on command line into %var
    17 $var{UNZIP} = "unzip -o";
    19 &parse_argv;
    21 if (! ($var{IMPORTS} =~ /\w/)) {
    22     print STDERR "nothing to import\n";
    23 }
    25 ######-- Do the import!
    27 foreach $import (split(/ /,$var{IMPORTS}) ) {
    29     print STDERR "\n\nIMPORTING .... $import\n-----------------------------\n";
    32 # if a specific version specified in IMPORT variable
    33 # (if $import has a slash in it)
    35     if ($import =~ /\//) {
    36         # $component=everything before the first slash of $import
    38 	$import =~ m|^([^/]*)/|; 
    39 	$component = $1;
    41 	$import =~ m|^(.*)/([^/]*)$|;
    43 	# $path=everything before the last slash of $import
    44 	$path = $1;
    46 	# $version=everything after the last slash of $import
    47 	$version = $2;
    49 	if ($var{VERSION} ne "current") {
    50 	    $version = $var{VERSION};
    51 	}
    52     }
    53     else {
    54 	$component = $import;
    55 	$path = $import;
    56 	$version = $var{VERSION};
    57     }
    59     $releasejardir = "$var{RELEASE_TREE}/$path";
    60     if ($version eq "current") {
    61 	print STDERR "Current version specified. Reading 'current' file ... \n";
    63 	open(CURRENT,"$releasejardir/current") || die "NO CURRENT FILE\n";
    64 	$version = <CURRENT>;
    65 	$version =~ s/(\r?\n)*$//; # remove any trailing [CR/]LF's
    66 	close(CURRENT);
    67 	print STDERR "Using version $version\n";
    68 	if ( $version eq "") {
    69 	    die "Current version file empty. Stopping\n";
    70 	}
    71     }
    73     $releasejardir = "$releasejardir/$version";
    74     if ( ! -d $releasejardir) {
    75 	die "$releasejardir doesn't exist (Invalid Version?)\n";
    76     }
    77     foreach $jarfile (split(/ /,$var{FILES})) {
    79 	($relpath,$distpath,$options) = split(/\|/, $var{$jarfile});
    81 	if ($var{'OVERRIDE_IMPORT_CHECK'} eq 'YES') {
    82 	    $options =~ s/v//g;
    83 	}
    85 	if ( $relpath ne "") { $releasejarpathname = "$releasejardir/$relpath";}
    86 	else { $releasejarpathname = $releasejardir; }
    88 # If a component doesn't have IDG versions, import the DBG ones
    89     if( ! -e "$releasejarpathname/$jarfile" ) {
    90         if( $relpath =~ /IDG\.OBJ$/ ) {
    91             $relpath =~ s/IDG.OBJ/DBG.OBJ/;
    92             $releasejarpathname = "$releasejardir/$relpath";
    93         } elsif( $relpath =~ /IDG\.OBJD$/ ) {
    94             $relpath =~ s/IDG.OBJD/DBG.OBJD/;
    95             $releasejarpathname = "$releasejardir/$relpath";
    96         }
    97     }
    99 	if (-e "$releasejarpathname/$jarfile") {
   100 	    print STDERR "\nWorking on jarfile: $jarfile\n";
   102 	    if ($distpath =~ m|/$|) {
   103 		$distpathname = "$distpath$component";
   104 	    }
   105 	    else {
   106 		$distpathname = "$distpath"; 
   107 	    }
   110 #the block below is used to determine whether or not the xp headers have
   111 #already been imported for this component
   113 	    $doimport = 1;
   114 	  if ($options =~ /v/) {   # if we should check the imported version
   115 	      print STDERR "Checking if version file exists $distpathname/version\n";
   116 	      if (-e "$distpathname/version") {
   117 		  open( VFILE, "<$distpathname/version") ||
   118 		      die "Cannot open $distpathname/version for reading. Permissions?\n";
   119 		  $importversion = <VFILE>;
   120 		  close (VFILE);
   121 		  $importversion =~ s/\r?\n$//;   # Strip off any trailing CR/LF
   122 		  if ($version eq $importversion) {
   123 		      print STDERR "$distpathname version '$importversion' already imported. Skipping...\n";
   124 		      $doimport =0;
   125 		  }
   126 	      }
   127 	  }
   129 	  if ($doimport == 1) {
   130 	      if (! -d "$distpathname") {
   131 		  &rec_mkdir("$distpathname");
   132 	      }
   133 	      # delete the stuff in there already.
   134 	      # (this should really be recursive delete.)
   136 	      if ($options =~ /v/) {
   137 		  $remheader = "\nREMOVING files in '$distpathname/' :";
   138 		  opendir(DIR,"$distpathname") ||
   139 		      die ("Cannot read directory $distpathname\n");
   140 		  @filelist = readdir(DIR);
   141 		  closedir(DIR);
   142 		  foreach $file ( @filelist ) {
   143 		      if (! ($file =~ m!/.?.$!) ) {
   144 			  if (! (-d $file)) {
   145 			      $file =~ m!([^/]*)$!;
   146 			      print STDERR "$remheader $1";
   147 			      $remheader = " ";
   148 			      unlink "$distpathname/$file";
   149 			  }
   150 		      }
   151 		  }
   152 	      }
   155 	      print STDERR "\n\n";
   157 	      print STDERR "\nExtracting jarfile '$jarfile' to local directory $distpathname/\n";
   159 	      print STDERR "$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname\n";
   160 	      system("$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname");
   162 	      $r = $?;
   164 	      if ($options =~ /v/) {
   165 		  if ($r == 0) {
   166 		      unlink ("$distpathname/version");
   167 		      if (open(VFILE,">$distpathname/version")) {
   168 			  print VFILE "$version\n";
   169 			  close(VFILE);
   170 		      }
   171 		  }
   172 		  else {
   173 		      print STDERR "Could not create '$distpathname/version'. Permissions?\n";
   174 		      $returncode ++;
   175 		  }
   176 	      }
   177 	  }  # if (doimport)
   178 	} # if (-e releasejarpathname/jarfile)
   179     } # foreach jarfile)
   180 } # foreach IMPORT
   184 exit($returncode);

mercurial