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.

253 lines
6.3 KiB

  1. @echo off
  2. if defined _echo echo on
  3. if defined verbose echo on
  4. setlocal ENABLEDELAYEDEXPANSION
  5. REM ***********************************************************
  6. REM Symsrv.cmd
  7. REM
  8. REM This is the script that the symbol server uses to process
  9. REM add requests
  10. REM ***********************************************************
  11. set Symsrv=d:\symbols\symbols
  12. set BDir=d:\symbols\build
  13. set LogFile=d:\symbols\requests.log
  14. if not exist %BDir%\add_requests md %BDir%\add_requests
  15. if not exist %BDir%\add_working md %BDir%\add_working
  16. if not exist %BDir%\add_finished md %BDir%\add_finished
  17. if not exist %BDir%\add_errors md %BDir%\add_errors
  18. if not exist %BDir%\del_requests md %BDir%\del_requests
  19. if not exist %BDir%\del_working md %BDir%\del_working
  20. if not exist %BDir%\del_finished md %BDir%\del_finished
  21. if not exist %BDir%\del_errors md %BDir%\del_errors
  22. :lookagain
  23. for %%a in ( bin pri pub ) do (
  24. if exist %BDir%\add_requests\*.%%a (
  25. for /f %%b in ('dir /b %BDir%\add_requests\*.%%a') do (
  26. if exist %Bdir%\add_requests\%%b.loc (
  27. echotime /t | tee -a %LogFile%
  28. call :AddRequest %%b
  29. echotime /t | tee -a %LogFile%
  30. echo.
  31. )
  32. )
  33. )
  34. )
  35. sleep 5
  36. goto lookagain
  37. endlocal
  38. goto :EOF
  39. REM ***************************************************************
  40. REM AddRequest
  41. REM
  42. REM Params:
  43. REM %1 Name of file to add
  44. REM
  45. REM ***************************************************************
  46. :AddRequest
  47. echo Adding Request %1 ... | tee -a %LogFile%
  48. REM Check the share location and make sure it exists
  49. for /f %%a in ( %BDir%\add_requests\%1.loc ) do (
  50. dir %%a >nul 2>nul
  51. if !ERRORLEVEL! NEQ 0 (
  52. echo Cannot find the share %%a | tee -a %LogFile%
  53. echo Will try to add this later | tee -a %LogFile%
  54. goto :EOF
  55. )
  56. )
  57. REM See if the files have actually been copied to the share
  58. REM **** To be done ******
  59. for %%a in (bin pri pub) do (
  60. call :DeleteIfExists %Bdir%\add_working\%%a
  61. if defined ThereWereErrors goto ErrEndAddRequest
  62. call :DeleteIfExists %BDir%\add_working\%%a.loc
  63. if defined ThereWereErrors goto ErrEndAddRequest
  64. call :DeleteIfExists %BDir%\add_working\%%a.log
  65. if exist %BDir%\add_finished\%%a (
  66. echo WARNING: %BDir%\add_finished\%%a already exists | tee -a %LogFile%
  67. )
  68. if exist %BDir%\add_finished\%%a.loc (
  69. echo WARNING: %BDir%\add_finished\%%a.loc already exists | tee -a %LogFile%
  70. )
  71. if exist %BDir%\add_finished\%%a.log (
  72. echo WARNING: %BDir%\add_finished\%%a.log already exists | tee -a %LogFile%
  73. )
  74. )
  75. if not exist %BDir%\add_requests\%1 (
  76. echo ERROR: %BDir%\add_requests\%1 is missing | tee -a %LogFile%
  77. goto ErrEndAddRequest
  78. )
  79. if not exist %BDir%\add_requests\%1.loc (
  80. echo ERROR: %BDir%\add_requests\%1.loc is missing | tee -a %Logfile%
  81. goto ErrEndAddRequest
  82. )
  83. REM Try to copy both files to add_working
  84. REM If this is unsuccessful keep trying for 5 times, then give up and
  85. REM go to ErrEndAddRequest
  86. set /a count=1
  87. :TryAgainCopy1
  88. call :CopyFileAndDelete %BDir%\add_requests\%1 %BDir%\add_working\%1
  89. if defined ThereWereErrors (
  90. set /a count="!count!+1"
  91. sleep 5
  92. if !count! LEQ 5 goto TryAgainCopy1
  93. echo Giving up on indexing this request | tee -a %LogFile%
  94. goto :ErrEndAddRequest
  95. )
  96. set /a count=1
  97. :TryAgainCopy2
  98. call :CopyFileAndDelete %BDir%\add_requests\%1.loc %BDir%\add_working\%1.loc
  99. if defined ThereWereErrors (
  100. set /a count="!count!+1"
  101. sleep 5
  102. if !count! LEQ 5 goto TryAgainCopy2
  103. echo Giving up on indexing this request | tee -a %LogFile%
  104. goto ErrEndAddRequest
  105. )
  106. REM We already did this, but just in case
  107. REM make sure there is something in %1.loc
  108. set Share=
  109. for /f %%a in ( %BDir%\add_working\%1.loc ) do (
  110. set Share=%%a
  111. )
  112. if not defined Share (
  113. echo ERROR: %BDir%\add_working\%1.loc does not have a location inside | tee -a %LogFile%
  114. goto ErrEndAddRequest
  115. )
  116. REM Index the file
  117. echo Indexing %BDir%\add_working\%1 | tee -a %LogFile%
  118. symstore.exe add /y %Bdir%\add_working\%1 /g %Share% /s %Symsrv% /t %1 /c %Share% /p > %BDir%\add_working\%1.log
  119. if %ERRORLEVEL% NEQ 0 (
  120. echo There were errors in symbol indexing | tee -a %LogFile%
  121. for %%a in ( %1 %1.loc %1.log ) do (
  122. call :CopyFileAndDelete %BDir%\add_working\%%a %BDir%\add_errors\%%a
  123. )
  124. goto ErrEndAddRequest
  125. )
  126. REM Copy the files to add_finished
  127. for %%a in ( %1 %1.loc %1.log ) do (
  128. call :CopyFileAndDelete %BDir%\add_working\%%a %BDir%\add_finished\%%a
  129. )
  130. goto :EndAddRequest
  131. :EndAddRequest
  132. echo Indexing finished successfully | tee -a %LogFile%
  133. goto :EOF
  134. :ErrEndAddRequest
  135. echo Request finished with errors | tee -a %LogFile%
  136. for %%a in ( %1 %1.loc ) do (
  137. for %%b in ( add_requests add_working add_finished ) do (
  138. if exist %BDir%\%%b\%%a (
  139. call :CopyFileAndDelete %BDir%\%%b\%%a %BDir%\add_errors\%%a
  140. )
  141. )
  142. )
  143. echo Indexing had errors ... see %BDir%\add_errors\%1.log | tee -a %LogFile%
  144. goto :EOF
  145. REM ***************************************************
  146. REM DeleteIfExists
  147. REM
  148. REM Params:
  149. REM %1 File to delete
  150. REM
  151. REM Return Value:
  152. REM ThereWereErrors not defined if success
  153. REM yes, if not successful
  154. REM
  155. REM ****************************************************
  156. :DeleteIfExists %1
  157. set ThereWereErrors=
  158. if not exist %1 goto EndDeleteIfExists
  159. del /q %1
  160. if not exist %1 goto EndDeleteIfExists
  161. echo ERROR: Failed to delete %1 | tee -a %LogFile%
  162. set ThereWereErrors=yes
  163. :EndDeleteIfExists
  164. goto :EOF
  165. REM *****************************************************
  166. REM CopyFile
  167. REM
  168. REM Params:
  169. REM %1 Source file
  170. REM %2 Destination file
  171. REM
  172. REM *****************************************************
  173. :CopyFileAndDelete %1 %2
  174. set ThereWereErrors=
  175. copy %1 %2 >nul 2>nul
  176. if not exist %2 (
  177. echo ERROR: %1 could not be copied to %2 | tee -a %LogFile%
  178. set ThereWereErrors=yes
  179. goto :EndCopyFileAndDelete
  180. )
  181. del /q %1 >nul 2>nul
  182. if exist %1 (
  183. echo ERROR: %1 could not be deleted | tee -a %LogFile%
  184. set ThereWereErrors=yes
  185. goto :EndCopyFileAndDelete
  186. )
  187. :EndCopyFileAndDelete
  188. goto :EOF
  189. :end
  190. goto :EOF
  191. :errend
  192. goto :EOF