releasing/cbrtools/perl/Utils.pm
author kelvzhu
Mon, 18 Oct 2010 16:16:46 +0800
changeset 655 3f65fd25dfd4
parent 602 3145852acc89
permissions -rw-r--r--
sync up SVN codes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
package Utils;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
use base qw(Exporter);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use Win32;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use Win32::File;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use Win32::Console;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use File::stat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use File::Find;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use File::Temp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use File::Spec;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
use FindBin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
use Cwd 'abs_path';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
use Data::Dumper;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
use Time::Local;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
use IPC::Open2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
use Cwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
use Symbian::IPR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
$|++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
# Constants.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
use constant EPOC_RELATIVE => 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
use constant SOURCE_RELATIVE => 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
use constant MAX_OS_PATH_LENGTH => 255;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
our @EXPORT = qw(EPOC_RELATIVE SOURCE_RELATIVE);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
# Globals;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
my $console; # Needs to be global because (for some reason) file descriptors get screwed up if it goes out of scope.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
my $tempDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
my $haveCheckedEpocRoot;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
my $haveCheckedSrcRoot;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
our %zipFileCache; # used to cache the Archive::Zip object of the last zip file used
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
# Subs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
sub StripWhiteSpace {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  my $a = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
  $$a =~ s/^\s*//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  $$a =~ s/\s*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
sub TidyFileName {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
  my $a = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
  $$a =~ s/\//\\/g;      # Change forward slashes to back slashes.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  $$a =~ s/\\\.\\/\\/g;  # Change "\.\" into "\".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  if ($$a =~ /^\\\\/) {  # Test for UNC paths.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
    $$a =~ s/\\\\/\\/g;  # Change "\\" into "\".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
    $$a =~ s/^\\/\\\\/;  # Add back a "\\" at the start so that it remains a UNC path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
    $$a =~ s/\\\\/\\/g;  # Change "\\" into "\".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
  # Colapse '\..\' sequences.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
  my $hasLeadingSlash = $$a =~ s/^\\//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  my $hasTrailingSlash = $$a =~ s/\\$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  my @elements = split (/\\/, $$a);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
  my @result; # An array to store the colapsed result in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
  foreach my $element (@elements) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
    if ($element eq '..') {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
      my $last = pop @result;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
      if ($last) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
	if ($last eq '..') { # Throw away the previous element, unless it's another '..'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
	  push (@result, $last);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
	  push (@result, $element);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
	next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
    push (@result, $element);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
  if ($hasLeadingSlash) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    $$a = '\\';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
    $$a = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  $$a .= join ('\\', @result);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  if ($hasTrailingSlash) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
    $$a .= '\\';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
sub IsAbsolute {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  if ($path =~ /^[\\\/]/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
  return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
sub AbsoluteFileName {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
  my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
  (my $base, my $path) = fileparse($$fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
  my $absPath = abs_path($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  $absPath =~ s/^\D://; # Remove drive letter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
  $$fileName = $absPath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
  unless ($$fileName =~ /[\\\/]$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
    $$fileName .= "\\";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
  $$fileName .= $base;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  TidyFileName($fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
sub AbsolutePath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
  my $absPath = abs_path($$path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  $absPath =~ s/^\D://; # Remove drive letter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
  $$path = $absPath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
  TidyFileName($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
sub EpocRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
  my $epocRoot = $ENV{EPOCROOT};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
  unless ($haveCheckedEpocRoot) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
    #use Carp qw/cluck/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
    #cluck "Checking for EpocRoot";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
    die "Error: Must set the EPOCROOT environment variable\n" if (!defined($epocRoot));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
    die "Error: EPOCROOT must not include a drive letter\n" if ($epocRoot =~ /^.:/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
    die "Error: EPOCROOT must be an absolute path without a drive letter\n" if ($epocRoot !~ /^\\/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    die "Error: EPOCROOT must not be a UNC path\n" if ($epocRoot =~ /^\\\\/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
    die "Error: EPOCROOT must end with a backslash\n" if ($epocRoot !~ /\\$/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
    die "Error: EPOCROOT must specify an existing directory\n" if (!-d $epocRoot);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
    $haveCheckedEpocRoot = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
  return $epocRoot;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
sub SourceRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
  my $srcRoot = $ENV{SRCROOT};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
  unless ($haveCheckedSrcRoot) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
    if (defined $srcRoot) { # undefined SRCROOTs are OK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
      die "Error: SRCROOT must not include a drive letter\n" if ($srcRoot =~ /^.:/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
      die "Error: SRCROOT must be an absolute path without a drive letter\n" if ($srcRoot !~ /^\\/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
      die "Error: SRCROOT must not be a UNC path\n" if ($srcRoot =~ /^\\\\/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
      die "Error: SRCROOT must end with a backslash\n" if ($srcRoot !~ /\\$/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
      die "Error: SRCROOT must specify an existing directory\n" if (!-d $srcRoot);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
    $haveCheckedSrcRoot = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
  return $srcRoot || "\\";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
sub CheckWithinEpocRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
  die "Error: \"$path\" is not within EPOCROOT\n" unless (WithinEpocRoot($path));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
sub WithinEpocRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
  my $epocRoot = EpocRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
  return ($path =~ /^\Q$epocRoot\E/i);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
sub PrependEpocRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
  if (EpocRoot() ne "\\") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
    #use Carp qw/cluck/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
    #cluck "here";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
    die "Error: EPOCROOT already present in \"$path\"\n" if ($path =~ /^\Q$ENV{EPOCROOT}\E/i);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
  $path =~ s!^[\\\/]!!; # Remove leading slash.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
  return EpocRoot().$path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
sub RelativeToAbsolutePath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
	my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
	my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
	my $pathType = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
	if ( $pathType == SOURCE_RELATIVE ) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
		if( $iniData->HasMappings() && SourceRoot() eq "\\" ) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
			$path = $iniData->PerformMapOnFileName( $path );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
		else{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
			$path = PrependSourceRoot( $path );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
	else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
		$path = PrependEpocRoot( $path );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
	return $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
sub RemoveEpocRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
  unless ($path =~ s/^\Q$ENV{EPOCROOT}\E//i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
    die "Error: Path does not contain EPOCROOT - EPOCROOT:\"$ENV{EPOCROOT}\" - Path:\"$path\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
  return $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
sub CheckWithinSourceRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
  die "Error: \"$path\" is not within SRCROOT\n" unless (WithinSourceRoot($path));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
sub WithinSourceRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
  my $sourceRoot = SourceRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
  return ($path =~ /^\Q$sourceRoot\E/i);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
sub PrependSourceRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
  my $sourceRoot = SourceRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
  if ($sourceRoot ne "\\") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
    die "Error: SRCROOT already present in \"$path\"\n" if ($path =~ /^\Q$sourceRoot\E/i);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
  $path =~ s!^[\\\/]!!; # Remove leading slash.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
  return SourceRoot() . $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
sub RemoveSourceRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
  my $sourceRoot = SourceRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
  unless ($path =~ s/^\Q$sourceRoot\E//i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
    die "Error: Couldn't remove \"$sourceRoot\" from \"$path\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
  return $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
sub MakeDir ($) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
  my $dir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
  $dir =~ s/\//\\/g; # Convert all forward slashes to back slashes in path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
  unless (-e $dir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
    if ($dir =~ /^\\\\/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
      # This is a UNC path - make path manually because UNC isn't supported by mkpath.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
      my $dirToMake = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
      my @dirs = split /\\/, $dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
      shift @dirs;  # Get rid of undefined dir.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
      shift @dirs;  # Get rid of undefined dir.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
      my $server = shift @dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
      my $share = shift @dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
      $dirToMake .= "\\\\$server\\$share";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
      unless (-e $dirToMake) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
	die "Error: Network share \"$dirToMake\" does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
      foreach my $thisDir (@dirs) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
	$dirToMake .=  "\\$thisDir";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
	unless (-e $dirToMake) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
	  mkdir($dirToMake,0) or die "Error: Couldn't make directory $dirToMake: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
      my @warnings;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
      local $SIG{__WARN__} = sub {push @warnings, $!};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
      eval {mkpath($dir)};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
      if (@warnings) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
        die "Error: Couldn't make path \"$dir\": " . (join ', ', @warnings) . "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
sub FileModifiedTime {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
  my $st = stat($file) or return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
  return TimeMinusDaylightSaving($st->mtime);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
sub FileSize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
  my $st = stat($file) or return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
  return $st->size;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
sub FileModifiedTimeAndSize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
  my $st = stat($file) or return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
  return (TimeMinusDaylightSaving($st->mtime), $st->size);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
sub TimeMinusDaylightSaving {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
  my $time = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
  (undef, undef, undef, undef, undef, undef, undef, undef, my $isDaylightSaving) = localtime;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
  if ($isDaylightSaving) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
    $time -= 3600;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
  return $time;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
sub TextTimeToEpochSeconds {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
  my $textTime = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
  $textTime =~ /(\S+) (\S+) {1,2}(\d+) {1,2}(\d+):(\d+):(\d+) {1,2}(\d+)/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
  my $weekDay = $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
  my $month = $2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
  my $monthDay = $3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
  my $hours = $4;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
  my $minutes = $5;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
  my $seconds = $6;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
  my $year = $7 - 1900;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
  if    ($month eq 'Jan') { $month = 0; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
  elsif ($month eq 'Feb') { $month = 1; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
  elsif ($month eq 'Mar') { $month = 2; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
  elsif ($month eq 'Apr') { $month = 3; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
  elsif ($month eq 'May') { $month = 4; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
  elsif ($month eq 'Jun') { $month = 5; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
  elsif ($month eq 'Jul') { $month = 6; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
  elsif ($month eq 'Aug') { $month = 7; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
  elsif ($month eq 'Sep') { $month = 8; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
  elsif ($month eq 'Oct') { $month = 9; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
  elsif ($month eq 'Nov') { $month = 10; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
  elsif ($month eq 'Dec') { $month = 11; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
  return timelocal($seconds, $minutes, $hours, $monthDay, $month, $year);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
sub TextDateToEpochSeconds {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
  my $textDate = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
  (my $day, my $month, my $year) = split (/\//, $textDate, 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
  unless ($day and $month and $year) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
    die "Error: Invalid date specification: \"$textDate\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
  return timelocal(0, 0, 0, $day, $month - 1, $year - 1900);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
sub SetFileReadOnly {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
  Utils::TidyFileName(\$file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
  system "attrib +r $file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
sub SetFileWritable {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
  Utils::TidyFileName(\$file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
  system "attrib -r $file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
sub SplitFileName {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
  my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
  my $path = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
  my $base = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
  my $ext = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
  if ($fileName =~ /\\?([^\\]*?)(\.[^\\\.]*)?$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
    $base = $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
  if ($fileName =~ /^(.*\\)/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
    $path = $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
  if ($fileName =~ /(\.[^\\\.]*)$/o) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
    $ext =  $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
  unless ($fileName eq "$path$base$ext") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
    my $prob = ($^V eq "v5.6.0")?" There is a known defect in Perl 5.6.0 which triggers this issue with filenames with two extensions (e.g. .exe.map). Please upgrade to Perl 5.6.1.":"";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
    die "Couldn't parse filename \"$fileName\".$prob";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
  return ($path, $base, $ext);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
sub SplitQuotedString {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
  my $string = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
  my $original = $string;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
  my @output = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
  $string =~ s/^\s+//; # Remove leading delimiter if present.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
  while ($string) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
    if ($string =~ s/^\"(.*?)\"//    # Match and remove next quoted string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
	or $string =~ s/^(.*?)\s+//  # or, match and remove next (but not last) unquoted string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
	or $string =~ s/^(.*)$//) {  # or, match and remove last unquoted string.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
      push (@output, $1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
      $string =~ s/^\s+//; # Remove delimiter if present.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
      die "Error: Unable to decode string \"$original\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
  return @output;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
sub ConcatenateDirNames {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
  my $dir1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
  my $dir2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
  TidyFileName(\$dir1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
  TidyFileName(\$dir2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
  $dir1 =~ s/([^\\]$)/$1\\/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
  $dir2 =~ s/^\\//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
  return $dir1.$dir2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
sub FindInPath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
  unless (exists $ENV{PATH}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
    die "Error: No path environment variable\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
  foreach my $dir (split (/;/, $ENV{PATH})) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
    if (-e "$dir\\$file") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
      return "$dir\\$file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
  die "Error: \"$file\" not found in path\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
sub ReadDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
  my $dir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
  my @dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
  opendir(DIR, $dir) or die "Error: Couldn't open directory \"$dir\": $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
  while (defined(my $file = readdir(DIR))) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
    next if ($file eq '.' or $file eq '..');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
    push (@dir, $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
  closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
  return \@dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
sub ReadGlob {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
  my $glob = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
  (my $path, my $base, my $ext) = SplitFileName($glob);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
  $glob = "$base$ext";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
  $glob =~ s/\./\\\./g; # Escape '.'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
  $glob =~ s/\*/\.\*/g; # '*' -> '.*'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
  $glob =~ s/\?/\./g;   # '?' -> '.'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
  my @entries;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
  foreach my $entry (@{ReadDir($path)}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
    if ($entry =~ /$glob/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
      push (@entries, "$path$entry");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
  return \@entries;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
sub ReadDirDescendingDateOrder {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
  my $dir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
  my $unsortedList = ReadDir($dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
  my %mtimeHash;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
  foreach my $entry (@$unsortedList) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
    my $mTime = FileModifiedTime("$dir\\$entry");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
    while (exists $mtimeHash{$mTime}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
      ++$mTime;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
    $mtimeHash{$mTime} = $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
  my @dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
  foreach my $key (sort { $b <=> $a } keys %mtimeHash) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
    push (@dir, $mtimeHash{$key});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
  return \@dir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
sub SignificantDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
  my $dir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
  my $significantSubDirs = FindSignificantSubDirs($dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
  my $commonDir = CommonDir($significantSubDirs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
  return $commonDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
# For a given directory, find which sub-directories contain files (rather than just other sub-directories).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
sub FindSignificantSubDirs {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
  my $dir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
  my $dirContents = ReadDir($dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
  my @files;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
  my @dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
  foreach my $thisEntry (@$dirContents) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
    if (-f "$dir\\$thisEntry") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
      push (@files, "$dir\\$thisEntry");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
    elsif (-d "$dir\\$thisEntry") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
      push (@dirs, "$dir\\$thisEntry");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
  if (scalar @files > 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
    # This directory contains some files, so it is significant.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
    return [$dir];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
  elsif (scalar @dirs > 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
    # Only sub-directories in this directory, so recurse.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
    my @significantSubDirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
    foreach my $thisDir (@dirs) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
      push (@significantSubDirs, @{FindSignificantSubDirs($thisDir)});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
    return \@significantSubDirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
    # Nothing of interest;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
    return [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
sub CrossCheckDirs {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
  my $dir1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
  my $dir2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
  my $matched = CrossCheckDirsOneWay($dir1, $dir2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
  if ($matched) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
    $matched = CrossCheckDirsOneWay($dir2, $dir1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
  return $matched;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
sub CrossCheckDirsOneWay {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
  my $dir1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
  my $dir2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
  my $matched = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
  opendir(DIR1, $dir1) or die "Error: Couldn't open directory $dir1: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
  while (defined(my $dir1File = readdir(DIR1))) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
    next if ($dir1File eq '.' or $dir1File eq '..');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
    $dir1File = "$dir1\\$dir1File";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
    (my $dir1MTime, my $dir1Size) = Utils::FileModifiedTimeAndSize($dir1File);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
    (undef, my $base, my $extension) = Utils::SplitFileName($dir1File);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
    my $dir2File = "$dir2\\$base$extension";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
    if (-e $dir2File) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
      (my $dir2MTime, my $dir2Size) = Utils::FileModifiedTimeAndSize($dir2File);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
      unless ($dir2MTime == $dir1MTime and $dir2Size == $dir1Size) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
	print "\"$dir1File\" does not match modified time and size of \"$dir2File\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
	$matched = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
      print "\"$dir2File\" not found\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
      $matched = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
  closedir(DIR1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
  return $matched;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
sub ZipSourceList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
  my $list = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
  my $relativeTo = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
  if (scalar(@$list) == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
    if ($verbose) { print "No files to put into $zipName...\n"; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
    return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
  my $dirName = dirname($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
  unless (-d $dirName) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
    MakeDir($dirName) || die "ERROR: Unable to create directory.";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
  if ($verbose) { print "Creating $zipName...\n"; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
  my $zip = Archive::Zip->new() or die "ERROR: Unable to create new zip.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
  my $processedDirs = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
  foreach my $file (@$list) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
    my $fileToZip = $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
    $file = "$relativeTo"."$file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
    if(-f $file) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
	  # We need to add distribution policy files for each directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
	  my $dirname = dirname($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
	  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
	  if (!exists $processedDirs->{$dirname}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
		if (-e File::Spec->catdir($dirname, 'distribution.policy')) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
		  push @$list, Utils::RemoveSourceRoot(File::Spec->catdir($dirname, 'distribution.policy'));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
		  $processedDirs->{$dirname} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
	  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
	  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
      if($iniData->HasMappings()){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
        $fileToZip = $iniData->PerformReverseMapOnFileName($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
        $fileToZip = Utils::RemoveSourceRoot($fileToZip);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
      my $member = $zip->addFile($file, $fileToZip);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
      if (!defined $member) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
        die "ERROR: Cannot add file '$file' to new zip.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
      $member->fileAttributeFormat(FA_MSDOS);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
      my $attr = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
      Win32::File::GetAttributes($file, $attr);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
      $member->{'externalFileAttributes'} |= $attr; # preserve win32 attrs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
    elsif(-e $file){}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
      die "ERROR: $file does not exist, so can not add to $zipName.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
  # Warning message appears when an error code (which is a non zero) is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
  my $returnVal = $zip->writeToFileNamed($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
  if ($returnVal) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
    die "Error: Failed to write ZIP file '$zipName'\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
sub ZipList {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
  my $list = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
  my $noCompress = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
  my $relativeTo = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
  if (scalar(@$list) == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
    if ($verbose) { print "No files to put into $zipName...\n"; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
    return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
  my $dirName = dirname($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
  unless (-e $dirName) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
    MakeDir($dirName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
  if ($verbose) { print "Creating $zipName...\n"; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
  my $cwd = Cwd::cwd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
  if ($relativeTo) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
    chdir($relativeTo) or die "Error: Couldn't change working directory to \"$relativeTo\": $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
  my @opts = ('-@');;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
  if ($verbose == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
    push @opts, '-qq';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
  elsif ($verbose == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
    push @opts, '-q';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
  elsif ($verbose > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
    push @opts, '-v';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
  if ($noCompress) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
    push @opts, '-0';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
  my $missing = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
  my $retval;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
  my $count = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
  do{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
     open(ZIP, "| \"$FindBin::Bin\\zip\" @opts $zipName") or die "Error: Couldn't execute _zip.exe - $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
     foreach my $file (@$list) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
       unless (-e $file) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
         $missing = $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
         last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
       }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
       $file =~ s/\[/\[\[\]/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
       print ZIP "$file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
     }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
     close(ZIP);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
     
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
     $count ++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
     $retval = $? >> 8;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
     if (!$missing && $retval > 1){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
       print "Warning: Zipping failed with error code $retval for the $count times.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
     }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
     
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
  }while(!$missing && $retval > 1 && $count < 10);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
  if ($relativeTo) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
    chdir($cwd) or die "Error: Couldn't change working directory back to \"$cwd\": $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
  if ($missing) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
    die "Error: \"" . Utils::ConcatenateDirNames($relativeTo, $missing) . "\" does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
  die "Zipping failed with error code $retval\n" if $retval > 1; # 1 is warnings only
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
# So EnvDb::UnpackBinaries can be called from the test suite, use %INC to find path instead of FindBin::Bin
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
sub UnzipPath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
    my $unzippath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
    my $envdbpath = $INC{'EnvDb.pm'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
    if(defined $envdbpath) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
	# find the unzip binary
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
	$envdbpath =~ s/\\/\//g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
	$envdbpath =~ s/\/[^\/]+$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
	$unzippath .= $envdbpath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
	$unzippath .= $FindBin::Bin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
    $unzippath .= "\\unzip";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
    $unzippath = "\"$unzippath\"";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
    return $unzippath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
sub UnzipSource {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
  my $destinationPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
  my $overwrite = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
  my $toValidate = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
  unless(defined $overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
    $overwrite = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
  if($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
    print "Unpacking ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
    if($overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
      print "[in overwrite mode] ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
    print "$zipName...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
  my $catInArchive;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
  my $changeInCat = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
  my $fileDirBuffer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
  # Sets $catInArchive to the category found on the source zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
  if($toValidate==1 && $zipName =~ /source(.*).zip/){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
    $catInArchive = $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
  my $zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
  my @members = $zip->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
  # Only print warning message if validation is not being performed, destination path is \\ and verbose is set.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
  if($toValidate==0 && $destinationPath ne "\\" && $verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
    print "Warning: Ignoring all mappings defined since either source path or SRCROOT is set as $destinationPath.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
  foreach my $member (@members) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
    my $fileName = $member->fileName();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
    $fileName =~ s/\//\\/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
    if($fileName !~ /^\\/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
      $fileName = "\\$fileName";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
    $iniData->CheckFileNameForMappingClash($fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
    my $newFileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
    # PerfromMapOnFileName is only used for an validation and if the destintionPath is \\.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
    if($toValidate==1 || $destinationPath eq "\\") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
      $newFileName = $iniData->PerformMapOnFileName($fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
      $newFileName = $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
    # Check if the category has changed. Only occurs for validation.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
    if(defined $catInArchive && -e $newFileName && $toValidate==1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
      my $fileDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
      my $classifySourceFlag = 1; # Classify source using function ClassifySourceFile only if set as 1 and not when set as 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
      if(defined $fileDirBuffer) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
        ($fileDir) = SplitFileName($newFileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
        if($fileDirBuffer =~ /^\Q$fileDir\E$/i){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
          $classifySourceFlag = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
      if($classifySourceFlag){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
        my ($catInEnv, $errors) = ClassifyPath($iniData, $newFileName, 0, 0, $comp); # verbose = 0 and logErrors = 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
        if($catInArchive !~ /$catInEnv/i){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
          $changeInCat = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
        ($fileDirBuffer) = SplitFileName($newFileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
    ExtractFile($destinationPath, $newFileName, $member, $toValidate, $overwrite, $verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
  return $changeInCat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
sub ExtractFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
  my $destinationPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
  my $newFileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
  my $member = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
  my $toValidate = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
  my $overwrite = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
  my $unzipRetVal = shift; # The return value from unzip if it has already been tried
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
  my $extractFlag = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
  my $attr;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
  # If the file is a distribution.policy file then set the overwrite flag to true
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
  if ($newFileName =~ /distribution\.policy/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
	$overwrite = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
  # If extracting file for validation or destination path is not equal to \\ unzip file to $destinationPath.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
  if($toValidate==1 || $destinationPath ne "\\") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
    $newFileName = File::Spec->catfile($destinationPath, $newFileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
  CheckPathLength($newFileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
  # If the file exists need to check if file is to be overwritten.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
  if(-f $newFileName) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
    if($overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
      if((Win32::File::GetAttributes($newFileName, $attr)) && ($attr & HIDDEN)){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
      	Win32::File::SetAttributes($newFileName, ARCHIVE|NORMAL) || die "ERROR: Unable to overwrite the hidden file $newFileName: $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
	  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
	  elsif(!-w $newFileName){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
        chmod(0777,$newFileName) || die "ERROR: Unable to overwrite the read-only file $newFileName: $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
      $extractFlag = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
      if($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
        print "Ignoring the file $newFileName, as this is already present.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
  else{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
    $extractFlag = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
  if($extractFlag){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
      #DEF122018
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
      # Invalid paths will cause Archive::Zip to give an error.  We capture the error and re-format it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
      my @warnings;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
      local $SIG{__WARN__} = sub {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
        push @warnings, $!;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
      };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
      eval { mkpath(dirname($newFileName)) };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
      if (@warnings) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
        die "Error: Unable to make the directory \"$newFileName\": " . (join "\n", @warnings) . "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
    # A non-zero is returned if there is a problem with extractToFileNamed().
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
    if($member->extractToFileNamed($newFileName)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862
      warn "ERROR: Failed to extract $newFileName.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   863
      CheckUnzipError($unzipRetVal);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   864
      die;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   865
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   866
    utime($member->lastModTime(), $member->lastModTime(), $newFileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   867
    my $newattr = $member->externalFileAttributes() & 0xFFFF;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   868
    Win32::File::SetAttributes($newFileName, $newattr); # reapply win32 attrs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   869
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   870
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   871
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   872
sub Unzip {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   873
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   874
  my $destinationPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   875
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   876
  my $overwrite = shift || '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   877
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   878
  $overwrite = '-o' if $overwrite eq '1'; # Some callers to this method may send a boolean value rather then an unzip option
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   879
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   880
  if ($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   881
    print "Unpacking ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   882
    if ($overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   883
      print "[in overwrite mode] ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   884
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   885
    print "$zipName...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   886
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   887
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   888
  my $v;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   889
  if ($verbose == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   890
    $v = "-qq";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   891
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   892
  elsif ($verbose == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   893
    $v = "-q";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   894
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   895
  if ($verbose > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   896
    $v = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   897
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   898
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   899
  # Here we check that the files in the zip file are not so long they can not be unpacked
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   900
  my $zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   901
  my @members = $zip->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   902
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   903
  foreach my $member (@members) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   904
    my $fileName = File::Spec->catdir('\.', $destinationPath, $member->fileName());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   905
    CheckPathLength($fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   906
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   907
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   908
  MakeDir($destinationPath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   909
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   910
  # prepare command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   911
  my $cmd = "unzip $overwrite $v $zipName -d $destinationPath 2>&1";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   912
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   913
  # run $cmd, fetching io handles for it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   914
  my $pid = open2(\*IN, \*OUT, $cmd);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   915
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   916
  # one character per read
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   917
  local $/ = \1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   918
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   919
  # command output line buffer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   920
  my $line = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   921
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   922
  while (<IN>) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   923
    # accumulate line data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   924
    $line .= $_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   925
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   926
    # look for expected output
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   927
    if ($line =~ /^(?:(replace).*\[r\]ename|new name): $/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   928
      # dump line buffer so user can read prompt
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   929
      print $line and $line = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   930
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   931
      # read whole lines for user response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   932
      local $/ = "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   933
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   934
      # read user's response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   935
      chomp(my $response = <STDIN>);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   936
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   937
      if (defined $1) { # matched "replace"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   938
	# set overwrite mode if the user chooses to replace [A]ll
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   939
	$overwrite = '-o' if $response =~ /^A/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   940
	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   941
	# set no-overwrite mode if the user chooses to replace [N]one
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   942
	$overwrite = '-n' if $response =~ /^N/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   943
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   944
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   945
      # convey response to the command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   946
      print OUT "$response\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   947
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   948
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   949
    # dump line buffer at EOL
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   950
    print $line and $line = '' if $line =~ /\n$/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   951
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   952
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   953
  close (OUT);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   954
  close (IN);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   955
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   956
  waitpid($pid,0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   957
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   958
  CheckUnzipError($?);  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   959
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   960
  return $overwrite;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   961
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   962
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   963
sub CheckUnzipError {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   964
  my $retval = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   965
  $retval = $retval >> 8;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   966
  # Error numbers found in unzip (Info-ZIP) source code: there doesn't
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   967
  # seem to be a manual. Common with return values from PKZIP so
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   968
  # unlikely to change
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   969
  # Error 1 is just a warning, so we only care about those > 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   970
  die "Unzip reported an out-of-memory error ($retval)\n" if ($retval>3 && $retval<9);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   971
  die "Unzip reported a problem with the zip file ($retval)\n" if ($retval>1 && $retval<4);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   972
  die "Unzip reported disk full (though this might mean it's trying to overwrite files in use) ($retval)\n" if ($retval==50);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   973
  die "Unzip reported error code ($retval)" if ($retval>1 && $retval<52);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   974
  warn "Warning: Unzip returned an unexpected error code ($retval)\n" if ($retval >51)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   975
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   976
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   977
sub UnzipSingleFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   978
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   979
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   980
  my $destinationPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   981
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   982
  my $overwrite = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   983
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   984
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   985
  unless (defined $overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   986
    $overwrite = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   987
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   988
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   989
  if ($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   990
    print "Unpacking ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   991
    if ($overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   992
      print "[in overwrite mode] ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   993
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   994
    print "\"$file\" from \"$zipName\"...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   995
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   996
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   997
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   998
  my $v;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   999
  if ($verbose == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1000
    $v = "-qq";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1001
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1002
  elsif ($verbose == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1003
    $v = "-q";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1004
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1005
  if ($verbose > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1006
    $v = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1007
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1008
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1009
  my $o = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1010
  if ($overwrite) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1011
    $o = "-o";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1012
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1013
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1014
  MakeDir($destinationPath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1015
  my $retval = system(UnzipPath()." $o $v \"$zipName\" \"$file\" -d \"$destinationPath\"");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1016
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1017
  unless (-e ConcatenateDirNames($destinationPath, $file)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1018
    #Fallback to using archive::zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1019
    print "Unable to extract $file using unzip. Trying alternative extraction method...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1020
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1021
    my $zip = GetArchiveZipObject($zipName, $comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1022
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1023
    my $fileWithForwardSlashes = $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1024
    $fileWithForwardSlashes =~ s/\\/\//g; # Archive::Zip stores file names with forward slashes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1025
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1026
    my $member = $zip->memberNamed($fileWithForwardSlashes);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1027
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1028
    if (!defined $member) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1029
      # Archive::Zip is also case-sensitive.  If it doesn't find the required file we compile the filename into
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1030
      # a case insensitive regex and try again.  This takes longer than just calling memberNamed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1031
      my $fileNameRegEx = qr/$fileWithForwardSlashes/i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1032
      ($member) = $zip->membersMatching($fileNameRegEx);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1033
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1034
      # If it still can't find the file then it doesn't exist in the zip file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1035
      if (!defined $member) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1036
        warn "Unable to find $file in $zipName\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1037
        CheckUnzipError($retval);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1038
        die;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1039
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1040
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1041
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1042
    ExtractFile($destinationPath, $file, $member, 0, $overwrite, $verbose, $retval);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1043
    print "Successfully extracted $file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1044
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1045
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1046
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1047
sub ListZip {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1048
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1049
  my @list;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1050
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1051
  my $zipper = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1052
  unless ($zipper->read($zipName) == AZ_OK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1053
    die "Error: problem reading \"$zipName\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1054
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1055
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1056
  my @members = $zipper->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1057
  foreach my $thisMember (@members) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1058
    my $file = $thisMember->fileName();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1059
    TidyFileName(\$file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1060
    unless ($file =~ /^\\/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1061
      $file = "\\$file";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1062
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1063
    push (@list, $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1064
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1065
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1066
  return \@list;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1067
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1068
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1069
sub CheckZipFileContentsNotPresent {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1070
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1071
  my $where = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1072
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1073
  my $checkFailed = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1074
  foreach my $thisFile (@{ListZip($zipName)}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1075
    if ($thisFile =~ /\\$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1076
      next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1077
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1078
    my $fullName = ConcatenateDirNames($where, $thisFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1079
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1080
    if($iniData->HasMappings()){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1081
      $fullName = $iniData->PerformMapOnFileName($fullName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1082
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1083
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1084
	if ($fullName =~ /distribution\.policy$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1085
	  return $checkFailed;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1086
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1087
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1088
    if (-e $fullName) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1089
      print "Error: \"$fullName\" would be overwritten by unpacking \"$zipName\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1090
      $checkFailed = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1091
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1092
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1093
  return $checkFailed;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1094
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1095
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1096
sub SignificantZipDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1097
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1098
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1099
  my $zipper = Archive::Zip->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1100
  unless ($zipper->read($zipName) == AZ_OK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1101
    die "Error: problem reading \"$zipName\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1102
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1104
  my %dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1105
  my @members = $zipper->members();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1106
  foreach my $thisMember (@members) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1107
    my $file = $thisMember->fileName();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1108
    my $dir = lc(dirname($file));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1109
    TidyFileName(\$dir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1110
    unless (exists $dirs{$dir}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1111
      $dirs{$dir} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1112
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1113
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1115
  my @dirs = sort keys %dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1116
  return CommonDir(\@dirs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1117
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1119
# Given an array of directories, find the common directory they share.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1120
sub CommonDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1121
  my $dirs = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1122
  my $disectedDirs = DisectDirs($dirs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1123
  my $numDirs = scalar @$dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1124
  if ($numDirs == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1125
	# if there is only one signifigant directory then this has to be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1126
	# the common one so return it.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1127
	return $dirs->[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1128
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1129
  my $commonDir = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1130
  my $dirLevel = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1131
  while (1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1132
    my $toMatch;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1133
    my $allMatch = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1134
    for (my $ii = 0; $ii < $numDirs; ++$ii, ++$allMatch) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1135
      if ($dirLevel >= scalar @{$disectedDirs->[$ii]}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1136
        $allMatch = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1137
        last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1138
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1139
      if (not $toMatch) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1140
        $toMatch = $disectedDirs->[0][$dirLevel];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1141
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1142
      elsif ($disectedDirs->[$ii][$dirLevel] ne $toMatch) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1143
        $allMatch = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1144
        last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1145
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1146
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1147
    if ($allMatch) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1148
      if ($toMatch =~ /^[a-zA-Z]:/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1149
        $commonDir .= $toMatch;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1150
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1151
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1152
        $commonDir .= "\\$toMatch";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1153
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1154
      ++$dirLevel;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1155
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1156
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1157
      last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1158
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1159
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1160
  return $commonDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1161
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1162
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1163
sub DisectDirs {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1164
  my $dirs = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1165
  my $disectedDirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1166
  my $numDirs = scalar @$dirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1167
  for (my $ii = 0; $ii < $numDirs; ++$ii) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1168
    my $thisDir = $dirs->[$ii];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1169
    $thisDir =~ s/^\\//; # Remove leading backslash to avoid first array entry being empty.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1170
    my @thisDisectedDir = split(/\\/, $thisDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1171
    push (@$disectedDirs, \@thisDisectedDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1172
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1173
  return $disectedDirs;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1174
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1176
sub CheckExists {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1177
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1178
  unless (-e $file) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1179
    die "Error: $file does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1180
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1181
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1183
sub CheckIsFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1184
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1185
  unless (-f $file) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1186
    die "Error: $file is not a file\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1187
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1188
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1189
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1190
sub CurrentDriveLetter {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1191
  my $drive = Win32::GetCwd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1192
  $drive =~ s/^(\D:).*/$1/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1193
  return $drive;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1194
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1195
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1196
sub InitialiseTempDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1197
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1198
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1199
  if (defined $iniData->TempDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1200
    $tempDir = mkdtemp($iniData->TempDir().'\_XXXX');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1201
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1202
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1203
    my $fstempdir = File::Spec->tmpdir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1204
    $fstempdir =~ s/[\\\/]$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1205
    $tempDir = mkdtemp($fstempdir.'\_XXXX');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1206
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1207
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1208
  die "Error: Problem creating temporary directory \"$tempDir\": $!\n" if (!$tempDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1209
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1210
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1211
sub RemoveTempDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1212
  die unless $tempDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1213
  rmtree $tempDir or die "Error: Problem emptying temporary directory \"$tempDir\": $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1214
  undef $tempDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1215
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1216
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1217
sub TempDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1218
  die unless $tempDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1219
  return $tempDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1220
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1221
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1222
sub ToolsVersion {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1223
  my $relPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1224
  unless (defined $relPath) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1225
    $relPath = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1226
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1227
  my $file = "$FindBin::Bin/$relPath" . 'version.txt';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1228
  open (VER, $file) or die "Error: Couldn't open \"$file\": $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1229
  my $ver = <VER>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1230
  chomp $ver;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1231
  close (VER);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1232
  return $ver;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1233
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1234
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1235
sub QueryPassword {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1236
  unless ($console) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1237
    $console = Win32::Console->new(STD_INPUT_HANDLE);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1238
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1239
  my $origMode = $console->Mode();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1240
  $console->Mode(ENABLE_PROCESSED_INPUT);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1241
  my $pw = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1242
  my $notFinished = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1243
  while ($notFinished) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1244
    my $char = $console->InputChar();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1245
    if ($char and $char eq "\r") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1246
      print "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1247
      $notFinished = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1248
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1249
    elsif ($char and $char eq "\b") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1250
      if ($pw) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1251
	$pw =~ s/.$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1252
	print "\b \b";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1253
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1254
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1255
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1256
      $pw .= $char;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1257
      print '*';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1258
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1259
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1260
  $console->Mode($origMode);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1261
  return $pw;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1262
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1264
sub PrintDeathMessage {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1265
  my $exitCode = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1266
  my $msg = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1267
  my $relPath = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1268
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1269
  my $ver = ToolsVersion($relPath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1270
  print "$msg\nLPD Release Tools version $ver\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1271
  exit $exitCode;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1272
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1274
sub PrintTable {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1275
  my $data = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1276
  my $doHeading = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1278
  require IniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1279
  my $iniData = New IniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1280
  my $tf = $iniData->TableFormatter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1281
  $tf->PrintTable($data, $doHeading);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1282
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1284
sub QueryUnsupportedTool {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1285
  my $warning = shift; # optional
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1286
  my $reallyrun = shift; # optional - value of a '-f' (force) flag or similar
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1287
  return if $reallyrun;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1289
  $warning ||= <<GUILTY;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1290
Warning: this tool is unsupported and experimental. You may use it, but there
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1291
may be defects. Use at your own risk, and if you find a problem, please report
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1292
it to us. Do you want to continue? (y/n)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1293
GUILTY
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1295
  print $warning."\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1296
  my $resp = <STDIN>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1297
  chomp $resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1298
  die "Cancelled. You typed \"$resp\".\n" unless $resp =~ m/^y/i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1299
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1301
sub CompareVers($$) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1302
  my ($version1, $version2) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1303
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1304
  # New format or old format?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1305
  my $style1 = (($version1 =~ /^(\d+\.\d+)/) and ($1 >= 2.8));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1306
  my $style2 = (($version2 =~ /^(\d+\.\d+)/) and ($1 >= 2.8));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1307
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1308
  # Validate version strings
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1309
  if ($style1 == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1310
    $version1 = ValidateNewFormatVersion($version1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1311
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1312
    ValidateOldFormatVersion($version1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1313
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1315
  if ($style2 == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1316
    $version2 = ValidateNewFormatVersion($version2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1317
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1318
    ValidateOldFormatVersion($version2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1319
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1320
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1321
  # Compare version strings
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1322
  if ($style1 != $style2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1323
    return $style1-$style2; # New format always beats old format
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1324
  } else  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1325
    return CompareVerFragment($version1, $version2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1326
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1327
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1328
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1329
sub ValidateOldFormatVersion($) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1330
  my ($version) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1332
  if (($version !~ /^\d[\.\d]*$/) or ($version !~ /\d$/)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1333
    die "Error: $version is not a valid version number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1334
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1335
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1336
  return $version;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1337
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1339
sub ValidateNewFormatVersion($) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1340
  my ($version) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1341
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1342
  my $ver; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1343
  if ($version !~ /^(\d+\.\d+)\.(.+)$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1344
    die "Error: $version is not a valid version number; patch number must be given\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1345
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1346
    $ver = $1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1347
    my $patch = $2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1348
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1349
    if (($patch =~ /^\d*$/) and ($patch > 9999)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1350
      die "Error: Version number $version has an invalid patch number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1351
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1352
    } elsif ($patch =~ /\./) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1353
      die "Error: Version number $version has an invalid patch number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1354
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1355
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1356
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1357
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1358
  return $ver; # Return significant version number only
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1359
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1360
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1361
sub CompareVerFragment($$) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1362
  # 1.xxx = 01.xxx, while .1.xxx = .10.xxx
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1363
  my ($frag1, $frag2) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1364
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1365
  my $isfrag1 = defined($frag1) ? 1 : 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1366
  my $isfrag2 = defined($frag2) ? 1 : 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1367
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1368
  my $compare;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1369
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1370
  if ($isfrag1 and $isfrag2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1371
    my ($rest1, $rest2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1372
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1373
    $frag1=~s/^(\.?\d+)(\..*)$/$1/ and $rest1=$2; # If pattern fails, $rest1 is undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1374
    $frag2=~s/^(\.?\d+)(\..*)$/$1/ and $rest2=$2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1375
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1376
    $compare = $frag1-$frag2; # Numeric comparison: .1=.10 but .1>.01
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1377
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1378
    if ($compare == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1379
      $compare = &CompareVerFragment($rest1, $rest2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1380
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1381
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1382
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1383
    $compare = $isfrag1-$isfrag2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1384
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1385
  return $compare;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1386
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1387
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1388
sub ClassifyPath {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1389
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1390
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1391
  if (!WithinSourceRoot($path)){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1392
   $path = Utils::PrependSourceRoot($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1393
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1394
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1395
  my $logDistributionPolicyErrors = shift; # 0 = no, 1 = yes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1396
  my $component = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1397
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1398
  if ($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1399
    print "Finding category of source file $path...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1400
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1401
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1402
  Utils::TidyFileName(\$path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1403
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1404
  my $cat = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1405
  my $errors = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1406
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1407
  my $symbianIPR = Symbian::IPR->instance($iniData->UseDistributionPolicyFilesFirst(), $iniData->DisallowUnclassifiedSource(), 'MRPDATA', $verbose, $logDistributionPolicyErrors);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1408
  $symbianIPR->PrepareInformationForComponent($component);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1409
  eval {($cat, $errors) = $symbianIPR->Category($path)};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1410
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1411
  if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1412
    print $@;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1413
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1414
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1415
  if (uc $cat eq "X" and $iniData->DisallowUnclassifiedSource()) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1416
    die "Error: \"$path\" contains unclassified source code\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1417
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1418
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1419
  if ($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1420
    print "ClassifySource for $path: returning cat $cat";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1421
    if (scalar (@$errors) > 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1422
      print " and errors @$errors";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1423
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1424
    print "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1425
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1426
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1427
  return uc($cat), $errors; # copy of $errors
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1428
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1429
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1430
sub ClassifyDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1431
  return ClassifyPath(IniData->New(), @_);  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1432
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1433
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1434
sub ClassifySourceFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1435
  return ClassifyPath(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1436
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1437
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1438
sub CheckForUnicodeCharacters {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1439
  my $filename = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1440
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1441
  # Unicode characters in filenames are converted to ?'s 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1442
  $filename =~ /\?/ ? return 1 : return 0; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1443
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1444
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1445
sub CheckIllegalVolume {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1446
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1447
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1448
  my ($volume) = File::Spec->splitpath(cwd());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1449
  $volume =~ s/://; # remove any : from $volume
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1450
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1451
  # Check that the environment is not on an illegal volume - INC105548
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1452
  if (grep /$volume/i, $iniData->IllegalWorkspaceVolumes()) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1453
    die "Error: Development is not permitted on an excluded volume: " . (join ',', $iniData->IllegalWorkspaceVolumes()) . "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1454
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1455
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1456
sub ListAllFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1457
  my $directory = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1458
  my $list = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1459
  find(sub { push @{$list}, $File::Find::name if (! -d);}, $directory);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1460
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1461
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1462
sub CheckPathLength {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1463
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1464
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1465
  if (length($path) > MAX_OS_PATH_LENGTH) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1466
    my $extraMessage = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1467
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1468
    if ($tempDir && $path =~ /^\Q$tempDir\E/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1469
      $extraMessage = "\nThe folder you are extracting to is under your temp folder \"$tempDir\". Try reducing the size of your temp folder by using the temp_dir <folder> keyword in your reltools.ini file.";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1470
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1471
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1472
    die "Error: The path \"$path\" contains too many characters and can not be extracted.$extraMessage\n"; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1473
  }  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1474
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1475
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1476
sub GetArchiveZipObject {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1477
  my $zipName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1478
  my $comp = lc(shift);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1479
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1480
  my $zip;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1481
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1482
  if ($comp) { # If $comp is defined then we need to cache Archive::Zip objects by component
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1483
    if (exists $zipFileCache{$comp}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1484
      if (defined $zipFileCache{$comp}->{$zipName}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1485
        $zip = $zipFileCache{$comp}->{$zipName};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1486
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1487
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1488
	$zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1489
	$zipFileCache{$comp}->{$zipName} = $zip;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1490
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1491
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1492
    else { # New component
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1493
      %zipFileCache = (); # Delete the cache as it is no longer required
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1494
      $zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1495
      $zipFileCache{$comp}->{$zipName} = $zip;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1496
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1497
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1498
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1499
    $zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1500
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1501
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1502
  return $zip;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1503
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1504
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1505
sub CheckDirectoryName {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1506
  my $dirName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1507
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1508
  my @dirParts = split /[\\\/]/, $dirName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1509
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1510
  foreach my $dirPart (@dirParts) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1511
    next if ($dirPart =~ /^\w:$/ && $dirName =~ /^$dirPart/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1512
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1513
    if ($dirPart =~ /[:\?\*\"\<\>\|]/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1514
      die "Error: The directory \"$dirName\" can not contain the characters ? * : \" < > or |\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1515
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1516
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1517
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1518
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1519
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1520
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1521
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1522
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1523
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1524
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1525
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1526
Utils.pm - General utility functions.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1527
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1528
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1529
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1530
=head2 StripWhiteSpace
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1531
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1532
Expects a reference to a string. Strips white space off either end of the string.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1533
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1534
=head2 TidyFileName
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1535
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1536
Expects a reference to a string. Changes any forward slashes to back slashes. Also changes "\.\" and "\\" to "\" (preserving the "\\" at the start of UNC paths). This is necessary to allow effective comparison of file names.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1537
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1538
=head2 AbsoluteFileName
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1540
Expects a reference to a string containing a file name. Modifies the string to contain the corresponding absolute path version of the file name (without the drive letter). For example, the string ".\test.txt" would generate a return value of "\mydir\test.txt", assuming the current directory is "\mydir".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1541
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1542
=head2 AbsolutePath
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1543
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1544
Expects a reference to a string containing a path. Modifies the string to contain the corresponding absolute path (without the drive letter).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1545
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1546
=head2 FileModifiedTime
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1547
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1548
Expects a filename, returns C<stat>'s last modified time. If there's a problem getting the stats for the file, an C<mtime> of zero is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1549
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1550
=head2 FileSize
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1551
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1552
Expects a filename, returns the file's size.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1553
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1554
=head2 FileModifiedTimeAndSize
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1555
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1556
Expects a filename. Returns a list containing the file's last modified time and size.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1557
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1558
=head2 SetFileReadOnly
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1559
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1560
Expects to be passed a file name. Sets the file's read only flag.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1561
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1562
=head2 SetFileWritable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1563
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1564
Expects to be passed a file name. Clear the file's read only flag.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1565
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1566
=head2 SplitFileName
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1567
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1568
Expects to be passed a file name. Splits this into path, base and extension variables (returned as a list in that order). For example the file name C<\mypath\mybase.myextension> would be split into C<mypath>, C<mybase> and C<.myextension>. An empty string will be returned for segments that don't exist.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1569
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1570
=head2 SplitQuotedString
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1571
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1572
Expects to be passed a string. Splits this string on whitespace, ignoring whitespace between quote (C<">) characters. Returns an array containing the split values.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1573
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1574
=head2 ConcatenateDirNames
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1575
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1576
Expects to be passed a pair of directory names. Returns a string that contains the two directory names joined together. Ensures that there is one (and only one) back slash character between the two directory names.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1577
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1578
=head2 MakeDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1579
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1580
Expects to be passed a directory name. Makes all the directories specified. Can copy with UNC and DOS style drive letter paths.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1581
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1582
=head2 ReadDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1583
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1584
Expects to be passed a directory name. Returns an array of file names found within the specified directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1585
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1586
=head2 ReadGlob
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1587
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1588
Expects to be passed a scalar containing a file name. The file name path may relative or absolute. The file specification may contains C<*> and/or C<?> characters. Returns a reference to an array of file names that match the file specification.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1589
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1590
=head2 SignificantDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1591
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1592
Expects to be passed a directory name. Returns the name of the deepest sub-directory that contains all files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1593
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1594
=head2 CrossCheckDirs
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1595
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1596
Expects to be passed a pair of directory names. Checks that the contents of the directories are identical as regards file names, their last modified times and their size. Returns false if any checks fail, otherwise true.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1597
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1598
=head2 ZipList
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1599
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1600
Expects to be passed a zip filename and a reference to a list of file to be put into the zip file. The zip filename may contain a full path - missing directories will be created if necessary.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1601
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1602
=head2 Unzip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1604
Expects to be passed a zip filename, a destination path, a verbosity level, and optionally a flag indicating whether exisitng files should be overwritten or not. Unpacks the named zip file in the specified directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1605
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1606
=head2 UnzipSingleFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1607
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1608
Expects to be passed a zip filename, a filename to unpack, a destination path, a verbosity level, and optionally a flag indicating whether existing files should be overwritten or not. Unpacks only the specified file from the zip file into the specified directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1609
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1610
=head2 ListZip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1611
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1612
Expects to be passed a zip filename. Returns a reference to a list containing the names of the files contained in the zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1613
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1614
=head2 CheckZipFileContentsNotPresent
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1615
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1616
Expects to be passed a zip filename and a destination path. Prints errors to C<STDOUT> for each file contained within the zip that would overwrite an existing file in the destination path. Returns true if any errors were printed, false otherwise.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1617
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1618
=head2 SignificantZipDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1619
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1620
Expects to be passed a zip filename. Returns the name of the deepest sub-directory that contains all the files within the zip.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1621
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1622
=head2 CheckExists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1623
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1624
Expects to be passed a filename. Dies if the file is not present.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1625
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1626
=head2 CheckIsFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1628
Expects to be passed a filename. Dies if the filename isn't a file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1629
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1630
=head2 CurrentDriveLetter
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1631
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1632
Returns a string containing the current drive letter and a colon.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1633
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1634
=head2 InitialiseTempDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1635
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1636
Creates an empty temporary directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1637
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1638
=head2 RemoveTempDir
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1639
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1640
Removes the temporary directory (recursively removing any other directories contained within it).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1641
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1642
=head2 ToolsVersion
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1643
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1644
Returns the current version of the release tools. This is read from the file F<version.txt> in the directory the release tools are running from.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1645
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1646
=head2 QueryPassword
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1647
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1648
Displays the user's input as '*' characters. Returns the password.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1649
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1650
=head2 PrintDeathMessage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1651
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1652
Expects to be passed a message. Dies with the message plus details of the current tools version.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1653
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1654
=head2 PrintTable
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1655
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1656
Expects to be passed a reference to a two dimentional array (a reference to an array (the rows) of referrences to arrays (the columns)). May optionally be passed a flag requesting that a line break be put between the first and second rows (useful to emphasise headings). Prints the data in a left justified table.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1657
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1658
=head2 TextTimeToEpochSeconds
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1659
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1660
Convert a human readable time/date string in the format generated by C<scalar localtime> into the equivalent number of epoch seconds.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1661
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1662
=head2 TextDateToEpochSeconds
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1663
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1664
Convert a date string in the format C<dd/mm/yyyy> into the equivalent number of epoc seconds.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1665
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1666
=head2 QueryUnsupportedTool
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1667
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1668
Warns the user that the tool is unsupported, and asks whether they wish to continue. Takes two parameters, both optional. The first is the text to display (instead of a default). It must finish with an instruction asking the user to type y/n. The second is an optional flag for a 'force' parameter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1669
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1670
=head2 CompareVers
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1671
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1672
Takes two version numbers in the form of a dot separated list of numbers (e.g 2.05.502) and compares them, returning 0 if they are equivalent, more than 0 if the first version given is greater or less than 0 if the first version is lesser. Dies if versions are not of the required format.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1673
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1674
=head2 CompareVerFragment
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1676
The main code behind C<CompareVers()>. This is not meant to be called directly because it assumes version numbers only consist of numbers and dots.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1677
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1678
=head2 ZipSourceList
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1679
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1680
Expects to be passed a zip filename and a reference to a list of source files to be put into the zip file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1681
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1682
=head2 UnzipSource
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1683
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1684
Expects to be passed a source zip filename, a destination path, a verbosity level, a flag indicating whether existing files should be overwritten or not, an inidata and a flag indicating whether this operation is for a validation or not. Unpacks the named source zip file to the specified directory. If for validation, a check for change in category occurs. Returns a change in category flag, when flag is 1 a change in category has been found.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1685
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1686
=head2 ExtractFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1687
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1688
Expects to be passed a destination path, a file name, a member and a flag indicating whether existing files should be overwritten or not. Is used to extract a file from a zip file to a specified location.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1689
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1690
=head2 ClassifySourceFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1691
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1692
Expects to be passed an iniData, a source filename, a verbosity level, and log error flag. Is used to calculate the category of the source file passed. Returns the category calculated.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1693
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1694
=head2 ListAllFiles
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1695
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1696
Expects to be passed a directory path and an array reference. Lists all files from the directory specified and sub directories into an array reference. Entries in the array contain full path of the file, not just file name.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1697
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1698
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1699
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1700
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1701
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1702
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1704
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1705
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1706
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1707
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1708
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1709
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1710
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1711
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1712
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1713
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1714
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1715
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1716
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1717
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1718
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1719
=cut