Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
7.8 KiB

  1. #---------------------------------------------------------------------
  2. package RelQuality;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version: 1.00 (11/15/2001) : SuemiaoR
  7. #
  8. # Purpose: Update/retrive NT release qulity information.
  9. #---------------------------------------------------------------------
  10. use strict;
  11. use vars qw($VERSION);
  12. $VERSION = '1.00';
  13. use File::Basename;
  14. use Logmsg;
  15. use comlib;
  16. ##### Define order of raise qualities
  17. my %qualityOrder = ( pre => 1, bvt => 2, tst => 3, sav => 4,
  18. idw => 5, ids => 6, idc => 7 );
  19. #
  20. # This is a wrapper to glob that expects and
  21. # returns paths using '\' as the path separator
  22. #
  23. sub globex ($)
  24. {
  25. my $match_criteria = shift;
  26. return if ( !defined $match_criteria );
  27. # Need to use '/' for UNC paths, so just convert to all '/''s
  28. $match_criteria =~ s/\\/\//g;
  29. # Return the results, converting back to '\'
  30. return grep { s/\//\\/g } glob( $match_criteria );
  31. }
  32. #---------------------------------------------------------------------
  33. sub IsValid
  34. {
  35. my ( $pQuality ) = @_;
  36. return 1 if ( exists $qualityOrder{lc $pQuality } );
  37. return 0;
  38. }
  39. #---------------------------------------------------------------------
  40. sub AllQlyFiles
  41. {
  42. my ( $pPath, $pFiles ) = @_;
  43. @{$pFiles} = grep { $_ if ( ! -d $_ ) } globex( "$pPath\\*.qly" );
  44. return 1;
  45. }
  46. #---------------------------------------------------------------------
  47. sub AllQualities
  48. {
  49. my ( $pPath, $pBuildName ) = @_;
  50. my ( @allFiles, @allQualities );
  51. ##### Get existing QLY files
  52. &AllQlyFiles( $pPath, \@allFiles );
  53. for my $theFile ( @allFiles )
  54. {
  55. basename( $theFile ) =~ /^([^\.]+)\.qly$/;
  56. my ( $fileQuality ) = $1;
  57. my @qlyInfo = &comlib::ReadFile( $theFile );
  58. push( @allQualities, $fileQuality) if ( $qlyInfo[0] =~ /$pBuildName/i );
  59. }
  60. return @allQualities;
  61. }
  62. #---------------------------------------------------------------------
  63. sub Exist
  64. {
  65. my ( $pPath, $pBuildName, $pQuality ) = @_;
  66. my @allQualities = &AllQualities( $pPath, $pBuildName );
  67. for my $theQly ( @allQualities )
  68. {
  69. return 1 if( lc $theQly eq $pQuality );
  70. }
  71. return 0;
  72. }
  73. #---------------------------------------------------------------------
  74. sub Which
  75. {
  76. my ( $pPath, $pBuildName, $pRetQly) = @_;
  77. my @allQualities = &AllQualities( $pPath, $pBuildName );
  78. $$pRetQly = $allQualities[0] if( @allQualities == 1 );
  79. return 1;
  80. }
  81. #---------------------------------------------------------------------
  82. sub Add
  83. {
  84. my ( $pPath, $pBuildName, $pQuality ) = @_;
  85. if( &Exist( $pPath, $pBuildName, $pQuality ) )
  86. {
  87. wrnmsg( "Found [$pQuality.qly], skip adding the file." );
  88. return 1;
  89. }
  90. ##### Create new QLY file
  91. if( ! (open QLYFILE, "> $pPath\\$pQuality.qly" ) )
  92. {
  93. errmsg( "Could not open [$pPath\\$pQuality.qly] for write ($!)." );
  94. return 0;
  95. }
  96. dbgmsg( "Adding [$pPath\\$pQuality.qly]..." );
  97. print QLYFILE "$pBuildName\n";
  98. close QLYFILE;
  99. return 1;
  100. }
  101. #---------------------------------------------------------------------
  102. sub Delete
  103. {
  104. my ( $pPath, $pQuality ) = @_;
  105. my $file = "$pPath\\$pQuality.qly";
  106. if( system( "dir /b $file >nul 2>nul" ) )
  107. {
  108. wrnmsg( "[$file] is not existing, skip deleting the file." );
  109. return 1;
  110. }
  111. if( system( "del $file >nul 2>nil" ) )
  112. {
  113. errmsg( "Could not delete $file ($!)." );
  114. return 0;
  115. }
  116. return 1;
  117. }
  118. #---------------------------------------------------------------------
  119. sub Update
  120. {
  121. my ( $pPath, $pBuildName, $pReqQly ) = @_;
  122. if ( !&IsValid( $pReqQly ) )
  123. {
  124. errmsg( "Invalid [$pReqQly ] quality, exit." );
  125. return 0;
  126. }
  127. my @allQualities = &AllQualities($pPath, $pBuildName );
  128. ##### Remove any QLY files that don't match current status
  129. ##### -- there should never be more than one, but we
  130. ##### should handle that case correctly
  131. my $tobeAdd = 1;
  132. for my $theQly ( @allQualities )
  133. {
  134. if ( !exists $qualityOrder{lc $theQly } )
  135. {
  136. wrnmsg( "Invalid quality file [$theQly.qly] found, deleting...");
  137. return 0 if( !&Delete( $pPath, $theQly ));
  138. next;
  139. }
  140. #####Same quality with request
  141. if( lc $theQly eq lc $pReqQly )
  142. {
  143. dbgmsg( "Same quality [$pReqQly] found, skip adding..." );
  144. $tobeAdd = 0;
  145. next;
  146. }
  147. #####Different quality with request
  148. if ( !&AllowQualityTransition( $theQly, $pReqQly ) )
  149. {
  150. errmsg( "Not allowed to go from [$theQly] to [$pReqQly] quality!" );
  151. return 0;
  152. }
  153. #####Remove the previous QLY file
  154. return 0 if( !&Delete( $pPath, $theQly ));
  155. }
  156. #####Add the requested QLY file
  157. return 0 if( $tobeAdd && !&Add( $pPath, $pBuildName, $pReqQly ) );
  158. return 1;
  159. }
  160. #---------------------------------------------------------------------
  161. sub AllowQualityTransition
  162. {
  163. my ( $pLastQly, $pReqQly ) = @_;
  164. ##### Allow transition to sav from any previous quality
  165. return 1 if ( lc $pReqQly eq 'sav' );
  166. ###### Allow transition from pre/bvt to any quality
  167. return 1 if( lc $pLastQly eq "pre" ||lc $pLastQly eq "bvt" );
  168. ##### Don't allow transition from anything else to pre/bvt
  169. return 0 if ( lc $pReqQly eq "pre" || lc $pReqQly eq "bvt" );
  170. ###### Otherwise allow transitions based on order specified in %qualityOrder
  171. return 1 if ( $qualityOrder{lc $pReqQly} >= $qualityOrder{lc $pLastQly} );
  172. return 0;
  173. }
  174. #---------------------------------------------------------------------
  175. =head1 NAME
  176. RelQuality - Access/Update release quality Information.
  177. =head1 SYNOPSIS
  178. use RelQuality;
  179. AllQlyFiles( $path, @return_files)
  180. where $path is the location of the quality files.
  181. where @return_files is the return array contains all the quality file names in the given $path.
  182. AllQualities( $path, $buildname )
  183. where $path is the location of the quality files.
  184. where $buildname is the searach criteria that used to match the content in quality file.
  185. return all the qualities exist in $path and match $buildname.
  186. Exist( $path, $buildname, $quality )
  187. where $path is the location of the quality files.
  188. where $buildname is the searach criteria that used to match the content in quality file.
  189. where $quality is the inquiry candidate.
  190. return true if $quality is existing for $buildname in $path. Otherwise, return false.
  191. Which( $path, $buildname, $return_quality )
  192. where $path is the location of the quality files.
  193. where $buildname is the searach criteria that used to match the content in quality file.
  194. where $return_quality is the return quality value for $buildname in $path.
  195. Add( $path, $buildname, $quality )
  196. where $path is the location of the quality files.
  197. where $buildname is used to be saved in quality file.
  198. where $quality is part of the file name to be created.
  199. Delete( $path, $quality )
  200. where $path is the location of the quality files.
  201. where $quality is part of the file name to be deleted.
  202. Upadte( $path, $buildname, $quality )
  203. where $path is the location of the quality files.
  204. where $buildname is the searach criteria that used to match the content in quality file.
  205. where $quality used to update qulity file name by given $buildname in $path.
  206. AllowQualityTransition( $q1, $q2 )
  207. where $q1 is the quality to be replaced.
  208. where $q2 is the quality to replace.
  209. return true if the replace order is allowed. Otherwise, return false.
  210. =head1 DESCRIPTION
  211. used to access or update release quality information.
  212. =head1 AUTHOR
  213. Suemiao Rossignol <[email protected]>
  214. =head1 COPYRIGHT
  215. Copyright (c) Microsoft Corporation. All rights reserved.
  216. =cut
  217. 1;