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.

171 lines
5.9 KiB

  1. # FileName: publish.pl
  2. #
  3. # Function: Given a file, publish it to the requested locations.
  4. #
  5. # Usage: publish.pl <logfile> <publishspec>
  6. # where: <logfile> is the name of the log file to be generated
  7. # <publishspec> is of the form:
  8. # {<filename>=<location>;<location>}{...}
  9. #
  10. # <filename> is a single filename to publish.
  11. # <location> is where to publish the file. Multiple locations
  12. # are delimited with semicolon
  13. #
  14. # or publish <logfile> -f <specfile>
  15. # where: <logfile> is the name of the logfile to be generated
  16. # <specfile> contains one or more <publishspec> entries
  17. #
  18. # Example:
  19. # publish.pl publish.log {kernel32.lib=\public\sdk\lib\amd64\kernel32.lib;\mypub\_kernel32.lib}
  20. #
  21. use File::Basename;
  22. $currenttime = time;
  23. open (CWD, 'cd 2>&1|');
  24. $PublishDir = <CWD>;
  25. close (CWD);
  26. chop $PublishDir;
  27. # strip the logfile name out of the arguments array.
  28. $logfilename = $ARGV[0];
  29. shift;
  30. # print "PUBLISH: logging to $logfilename\n";
  31. if ($ARGV[0] =~ /^[\/-][fF]$/) {
  32. shift;
  33. $indirname = shift;
  34. if (@ARGV || !$indirname) {
  35. die "Build_Status PUBLISH() : error p1000: Invalid syntax - Expected: publish -f FILE\n";
  36. }
  37. # print "PUBLISH: getting input from $indirname\n";
  38. open INDIR, $indirname or die "Build_Status PUBLISH(): error p1005: Could not open: $indirname\n";
  39. @ARGV=<INDIR>;
  40. close INDIR;
  41. } elsif ($ARGV[0] =~ /^[\/-][iI]$/) {
  42. shift;
  43. # print "PUBLISH: getting input from STDIN\n";
  44. @ARGV=<STDIN>;
  45. }
  46. for (@ARGV) {
  47. s/\s//g; # Remove spaces, tabs, newlines, etc
  48. $NextSpec = $_;
  49. # print "PUBLISH: NextSpec = $_";
  50. while ($NextSpec) {
  51. $SaveSpec = $NextSpec;
  52. $Spec1 = "";
  53. $PublishSpec = "";
  54. # Filter out the current publish spec
  55. ($PreCurly,$Spec1) = split (/{/, $NextSpec,2);
  56. # See if there's another one
  57. ($PublishSpec,$NextSpec) = split (/}/, $Spec1,2);
  58. # Break out the filename
  59. ($SourceSpec,$LocationSpec) = split (/=/, $PublishSpec,2);
  60. ($FileName,$AltFileName) = split (/\:\:/, $SourceSpec,2);
  61. # Create the location list
  62. @Location = split ((/\;/), $LocationSpec);
  63. die "PUBLISH(80) : error p1003: Bad input: $SaveSpec\n" unless($PublishSpec && $FileName && $#Location >= 0);
  64. # See if the source exists.
  65. if (!stat($FileName)) {
  66. print "Build_Status PUBLISH() : error p1001: $PublishDir - $FileName does not exist\n";
  67. } else {
  68. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  69. $TimeDate = sprintf "%04d/%02d/%02d-%02d:%02d:%02d", 1900+$year, 1+$mon, $mday, $hour, $min, $sec;
  70. # Run pcopy for every location listed.
  71. for (@Location) {
  72. # print "PUBLISH: pcopy.exe $FileName $_";
  73. system "pcopy.exe $SourceSpec $_";
  74. $ReturnCode = $? / 256;
  75. if ($ReturnCode == 0) {
  76. $CopiedFile=$_;
  77. $PUBLISH_LOG = $ENV{'_NTBINDIR'};
  78. $PUBLISH_LOG="$PUBLISH_LOG\\public\\$logfilename";
  79. # RC == 0 means success.
  80. $ReturnCode = -1;
  81. $LoopCount = 0;
  82. while ($ReturnCode) {
  83. system ("echo $CopiedFile $PublishDir $FileName $currenttime >> $PUBLISH_LOG");
  84. $ReturnCode = $?;
  85. $LoopCount = $LoopCount + 1;
  86. # Retry a max of 100 times to log the change.
  87. if ($LoopCount == 100) {
  88. print "Build_Status PUBLISH() : warning p1002: Unable to log \"$CopiedFile $PublishDir $FileName\" to $PUBLISH_LOG";
  89. $ReturnCode = 0;
  90. }
  91. }
  92. if ($AltFileName) {
  93. # RC == 0 means success.
  94. $ReturnCode = -1;
  95. $LoopCount = 0;
  96. $AltCopiedFile = $CopiedFile;
  97. substr($AltCopiedFile, rindex($AltCopiedFile, '\\')) = substr($AltFileName, rindex($AltFileName, '\\'));
  98. while ($ReturnCode) {
  99. system ("echo $AltCopiedFile $PublishDir $AltFileName $currenttime >> $PUBLISH_LOG");
  100. $ReturnCode = $?;
  101. $LoopCount = $LoopCount + 1;
  102. # Retry a max of 100 times to log the change.
  103. if ($LoopCount == 100) {
  104. print "Build_Status PUBLISH() : warning p1002: Unable to log \"$AltCopiedFile $PublishDir $AltFileName\" to $PUBLISH_LOG";
  105. $ReturnCode = 0;
  106. }
  107. }
  108. }
  109. #
  110. # BUGBUG: Need to log this for build/sd/more build process
  111. #
  112. print "PUBLISHLOG: $PublishDir, $FileName, $CopiedFile, Updated, $TimeDate\n";
  113. if ($AltFileName) {
  114. print "PUBLISHLOG: $PublishDir, $AltFileName, $AltCopiedFile, Updated, $TimeDate\n";
  115. }
  116. } else {
  117. if ($ReturnCode == 255) {
  118. # Current location is good enough.
  119. print "PUBLISHLOG: $PublishDir, $FileName, $_, Current, $TimeDate\n";
  120. if ($AltFileName) {
  121. $AltCopiedFile = $_;
  122. substr($AltCopiedFile, rindex($AltCopiedFile, '\\')) = substr($AltFileName, rindex($AltFileName, '\\'));
  123. print "PUBLISHLOG: $PublishDir, $AltFileName, $AltCopiedFile, Current, $TimeDate\n";
  124. }
  125. } else {
  126. # Problem copying (bad source, missing dest, out of mem, etc).
  127. print "Build_Status PUBLISH() : error p1004: ERROR($ReturnCode) copying $FileName to $_\n";
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }