Source code of Windows XP (NT5)
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.

512 lines
13 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\add_requests.log
  14. set DelLogFile=d:\symbols\del_requests.log
  15. set DelTmpDir=%tmp%\delrequests
  16. if not exist %DelTmpDir% md %DelTmpDir%
  17. if not exist %BDir%\add_requests md %BDir%\add_requests
  18. if not exist %BDir%\add_waiting md %BDir%\add_waiting
  19. if not exist %BDir%\add_working md %BDir%\add_working
  20. if not exist %BDir%\add_finished md %BDir%\add_finished
  21. if not exist %BDir%\add_errors md %BDir%\add_errors
  22. if not exist %BDir%\del_requests md %BDir%\del_requests
  23. if not exist %BDir%\del_working md %BDir%\del_working
  24. if not exist %BDir%\del_finished md %BDir%\del_finished
  25. if not exist %BDir%\del_errors md %BDir%\del_errors
  26. REM Get the DeleteCleanupNum
  27. if exist cleanup.txt (
  28. for /f %%a in (cleanup.txt) do (
  29. set /a DeleteCleanupNum=%%a
  30. )
  31. ) else (
  32. set /a DeleteCleanupNum=7000
  33. )
  34. echo Starting transaction for delete cleanup is !DeleteCleanupNum!
  35. if not exist %Symsrv%\000admin\deleted md %Symsrv%\000admin\deleted
  36. if not exist %Symsrv%\000admin\deleted (
  37. echo "Cannot create %Symsrv%\000admin\deleted" | tee -a %LogFile%
  38. goto :EOF
  39. )
  40. REM if "%1" == "add" goto ProcessAdds
  41. REM if "%1" == "del" goto ProcessDeletes
  42. REM echo "Incorrect params"
  43. REM goto :EOF
  44. :ProcessAdds
  45. REM Look in the add requests queue
  46. for %%a in ( bin pri pub ) do (
  47. if exist %BDir%\add_requests\*.%%a (
  48. for /f %%b in ('dir /b %BDir%\add_requests\*.%%a') do (
  49. if exist %Bdir%\add_requests\%%b.loc (
  50. echotime /t | tee -a %LogFile%
  51. call :AddRequest %%b
  52. echotime /t | tee -a %LogFile%
  53. echo.
  54. )
  55. )
  56. )
  57. )
  58. REM Look in the add waiting queue
  59. for %%a in ( bin pri pub ) do (
  60. if exist %BDir%\add_waiting\*.%%a (
  61. for /f %%b in ('dir /b %BDir%\add_waiting\*.%%a') do (
  62. if exist %Bdir%\add_waiting\%%b.loc (
  63. for /f %%c in ( %BDir%\add_waiting\%%b.loc ) do (
  64. dir %%c >nul 2>nul
  65. if !ERRORLEVEL! EQU 0 (
  66. echotime /t | tee -a %LogFile%
  67. echo Copying %BDir%\add_waiting\%%b to %BDir%\add_requests | tee -a %LogFile%
  68. call :CopyFileAndDelete %BDir%\add_waiting\%%b %BDir%\add_requests\%%b
  69. echo Copying %BDir%\add_waiting\%%b.loc to %BDir%\add_requests | tee -a %LogFile%
  70. call :CopyFileAndDelete %BDir%\add_waiting\%%b.loc %BDir%\add_requests\%%b.loc
  71. echotime /t | tee -a %LogFile%
  72. )
  73. )
  74. )
  75. )
  76. )
  77. )
  78. sleep 5
  79. goto ProcessDeletes
  80. endlocal
  81. goto :EOF
  82. REM **************************************************
  83. REM Process Deletes
  84. REM
  85. REM **************************************************
  86. :ProcessDeletes
  87. REM take everything that was in working and put it back
  88. REM into requests
  89. for /f %%a in ( 'dir /b %BDir%\del_working' ) do (
  90. call :CopyFileAndDelete %BDir%\del_working\%%a %BDir%\del_requests\%%a
  91. )
  92. REM Look in the del requests queue
  93. for /f %%a in ( 'dir /b %BDir%\del_requests' ) do (
  94. if exist %BDir%\del_requests\%%a (
  95. echotime /t | tee -a %DelLogFile%
  96. call :DelRequest %%a
  97. echotime /t | tee -a %DelLogFile%
  98. echo.
  99. )
  100. )
  101. sleep 5
  102. goto ProcessDeleteCleanup
  103. endlocal
  104. goto :EOF
  105. REM **************************************************
  106. REM Process Delete Cleanup
  107. REM
  108. REM **************************************************
  109. :ProcessDeleteCleanup
  110. REM take everything that was in working and put it back
  111. REM into requests
  112. set /a DeleteCleanupNum=!DeleteCleanupNum!+1
  113. :GetNextCleanupNum
  114. if !DeleteCleanupNum! LSS 10 (
  115. set TransFile=000000000!DeleteCleanupNum!
  116. goto End1
  117. )
  118. if !DeleteCleanupNum! LSS 100 (
  119. set TransFile=00000000!DeleteCleanupNum!
  120. goto End1
  121. )
  122. if !DeleteCleanupNum! LSS 1000 (
  123. set TransFile=0000000!DeleteCleanupNum!
  124. goto End1
  125. )
  126. if !DeleteCleanupNum! LSS 10000 (
  127. set TransFile=000000!DeleteCleanupNum!
  128. goto End1
  129. )
  130. if !DeleteCleanupNum! LSS 100000 (
  131. set TransFile=00000!DeleteCleanupNum!
  132. goto End1
  133. )
  134. if !DeleteCleanupNum! LSS 1000000 (
  135. set TransFile=0000!DeleteCleanupNum!
  136. goto End1
  137. )
  138. :End1
  139. if not exist %Symsrv%\000admin\!TransFile! (
  140. echo !TransFile! does not exist - OK | tee -a %DelLogFile%
  141. goto GetNextCleanupNum
  142. )
  143. for /f "tokens=1,2 delims=," %%a in (%Symsrv%\000admin\!TransFile!) do (
  144. echo Delete Cleanup - Examining !TransFile! | tee -a %DelLogFile%
  145. if not exist %%b (
  146. echo %%b does not exist | tee -a !DelLogFile!
  147. echo Clean up - Deleting transaction id !TransFile! ... | tee -a !DelLogFile!
  148. call symstore del /i !TransFile! /s %Symsrv% >> %BDir%\del_working\%1.log
  149. echo symstore finished successfully | tee -a !DelLogFile!
  150. echo !DeleteCleanupNum! >> cleanup.txt
  151. move %Symsrv%\000admin\!TransFile! %Symsrv%\000admin\deleted
  152. echo.
  153. ) else (
  154. echo %%b exists, !TransFile! will not be deleted | tee -a !DelLogFile!
  155. goto GetNextCleanupNum
  156. )
  157. goto ProcessDeleteCleanupEnd
  158. )
  159. :ProcessDeleteCleanupEnd
  160. set /a count=!count!+1
  161. if !count! LEQ 10 goto ProcessDeleteCleanup
  162. sleep 5
  163. goto ProcessAdds
  164. endlocal
  165. goto :EOF
  166. REM ***************************************************************
  167. REM AddRequest
  168. REM
  169. REM Params:
  170. REM %1 Name of file to add
  171. REM
  172. REM ***************************************************************
  173. :AddRequest
  174. echo Adding Request %1 ... | tee -a %LogFile%
  175. REM Check the share location and make sure it exists
  176. for /f %%a in ( %BDir%\add_requests\%1.loc ) do (
  177. dir %%a >nul 2>nul
  178. if !ERRORLEVEL! NEQ 0 (
  179. echo Cannot find the share %%a | tee -a %LogFile%
  180. echo Will try to add this later | tee -a %LogFile%
  181. call :CopyFileAndDelete %BDir%\add_requests\%1 %BDir%\add_waiting\%1
  182. call :CopyFileAndDelete %BDir%\add_requests\%1.loc %BDir%\add_waiting\%1.loc
  183. goto :EOF
  184. )
  185. )
  186. REM See if the files have actually been copied to the share
  187. REM **** To be done ******
  188. for %%a in (bin pri pub) do (
  189. call :DeleteIfExists %Bdir%\add_working\%%a
  190. if defined ThereWereErrors goto ErrEndAddRequest
  191. call :DeleteIfExists %BDir%\add_working\%%a.loc
  192. if defined ThereWereErrors goto ErrEndAddRequest
  193. call :DeleteIfExists %BDir%\add_working\%%a.log
  194. if exist %BDir%\add_finished\%%a (
  195. echo WARNING: %BDir%\add_finished\%%a already exists | tee -a %LogFile%
  196. )
  197. if exist %BDir%\add_finished\%%a.loc (
  198. echo WARNING: %BDir%\add_finished\%%a.loc already exists | tee -a %LogFile%
  199. )
  200. if exist %BDir%\add_finished\%%a.log (
  201. echo WARNING: %BDir%\add_finished\%%a.log already exists | tee -a %LogFile%
  202. )
  203. )
  204. if not exist %BDir%\add_requests\%1 (
  205. echo ERROR: %BDir%\add_requests\%1 is missing | tee -a %LogFile%
  206. goto ErrEndAddRequest
  207. )
  208. if not exist %BDir%\add_requests\%1.loc (
  209. echo ERROR: %BDir%\add_requests\%1.loc is missing | tee -a %Logfile%
  210. goto ErrEndAddRequest
  211. )
  212. REM Try to copy both files to add_working
  213. REM If this is unsuccessful keep trying for 5 times, then give up and
  214. REM go to ErrEndAddRequest
  215. set /a count=1
  216. :TryAgainCopy1
  217. call :CopyFileAndDelete %BDir%\add_requests\%1 %BDir%\add_working\%1
  218. if defined ThereWereErrors (
  219. set /a count="!count!+1"
  220. sleep 5
  221. if !count! LEQ 5 goto TryAgainCopy1
  222. echo Giving up on indexing this request | tee -a %LogFile%
  223. goto :ErrEndAddRequest
  224. )
  225. set /a count=1
  226. :TryAgainCopy2
  227. call :CopyFileAndDelete %BDir%\add_requests\%1.loc %BDir%\add_working\%1.loc
  228. if defined ThereWereErrors (
  229. set /a count="!count!+1"
  230. sleep 5
  231. if !count! LEQ 5 goto TryAgainCopy2
  232. echo Giving up on indexing this request | tee -a %LogFile%
  233. goto ErrEndAddRequest
  234. )
  235. REM We already did this, but just in case
  236. REM make sure there is something in %1.loc
  237. set Share=
  238. for /f %%a in ( %BDir%\add_working\%1.loc ) do (
  239. set Share=%%a
  240. )
  241. if not defined Share (
  242. echo ERROR: %BDir%\add_working\%1.loc does not have a location inside | tee -a %LogFile%
  243. goto ErrEndAddRequest
  244. )
  245. REM Index the file
  246. echo Indexing %BDir%\add_working\%1 | tee -a %LogFile%
  247. symstore.exe add /y %Bdir%\add_working\%1 /g %Share% /s %Symsrv% /t %1 /c %Share% /p > %BDir%\add_working\%1.log
  248. if %ERRORLEVEL% NEQ 0 (
  249. echo There were errors in symbol indexing | tee -a %LogFile%
  250. for %%a in ( %1 %1.loc %1.log ) do (
  251. call :CopyFileAndDelete %BDir%\add_working\%%a %BDir%\add_errors\%%a
  252. )
  253. goto ErrEndAddRequest
  254. )
  255. REM Copy the files to add_finished
  256. for %%a in ( %1 %1.loc %1.log ) do (
  257. call :CopyFileAndDelete %BDir%\add_working\%%a %BDir%\add_finished\%%a
  258. )
  259. goto :EndAddRequest
  260. :EndAddRequest
  261. echo Indexing finished successfully | tee -a %LogFile%
  262. goto :EOF
  263. :ErrEndAddRequest
  264. echo Request finished with errors | tee -a %LogFile%
  265. for %%a in ( %1 %1.loc ) do (
  266. for %%b in ( add_requests add_working add_finished ) do (
  267. if exist %BDir%\%%b\%%a (
  268. call :CopyFileAndDelete %BDir%\%%b\%%a %BDir%\add_errors\%%a
  269. )
  270. )
  271. )
  272. echo Indexing had errors ... see %BDir%\add_errors\%1.log | tee -a %LogFile%
  273. goto :EOF
  274. REM ***************************************************
  275. REM ProcessDeletes
  276. REM
  277. REM ***************************************************
  278. :DelRequest %1
  279. set ThereWereErrors=
  280. echo Deleting request %1 ... | tee -a %DelLogFile%
  281. REM Try to copy the file to del_working
  282. REM If this is unsuccessful keep trying for 5 times, then give up and
  283. REM go to ErrEndDelRequest
  284. if not exist %BDir%\del_requests\%1 (
  285. echo %BDir%\del_requests\%1 does not exist | tee -a %DelLogFile%
  286. goto :EOF
  287. )
  288. set /a count=1
  289. :TryAgainCopyDel1
  290. call :CopyFileAndDelete %BDir%\del_requests\%1 %BDir%\del_working\%1
  291. if defined ThereWereErrors (
  292. set /a count="!count!+1"
  293. sleep 5
  294. if !count! LEQ 5 goto TryAgainCopyDel1
  295. echo Giving up on deleting this request | tee -a %DelLogFile%
  296. goto :EOF
  297. )
  298. REM Find the entries in server.txt that need to be deleted
  299. findstr %1 %Symsrv%\000admin\server.txt > %DelTmpDir%\%%b.txt
  300. if !ERRORLEVEL! NEQ 0 (
  301. echo "No entries in %Symsrv%\000admin\server.txt to delete" | tee -a %DelLogFile%
  302. echo "No entries in %Symsrv%\000admin\server.txt to delete >> %BDir%\del_working\%1.log
  303. goto DelRequestFinish
  304. )
  305. REM Now delete the entries found
  306. for /f "tokens=1 delims=," %%c in ( %DelTmpDir%\%%b.txt ) do (
  307. echo Deleting transaction id %%c ... | tee -a %DelLogFile%
  308. symstore del /i %%c /s %Symsrv% >> %BDir%\del_working\%1.log
  309. echo symstore finished successfully | tee -a %DelLogFile%
  310. )
  311. :DelRequestFinish
  312. REM Check for errors
  313. if defined ThereWereErrors (
  314. if exist %BDir%\del_working\%1 (
  315. call :CopyFileAndDelete %BDir%\del_working\%1 %BDir%\del_errors\%1
  316. )
  317. if exist %BDir%\del_working\%1.log (
  318. call :CopyFileAndDelete %BDir%\del_working\%1.log %BDir%\del_errors\%1.log
  319. )
  320. goto :EOF
  321. )
  322. REM Put %1 in del_finished and take it out of add_finished
  323. if exist %BDir%\add_finished\%1 (
  324. if exist %BDir%\add_finished\%1 (
  325. call :CopyFileAndDelete %BDir%\add_finished\%1 %BDir%\del_finished\%1
  326. )
  327. if exist %BDir%\del_working\%1 (
  328. del /q %BDir%\del_working\%1
  329. )
  330. ) else (
  331. if exist %BDir%\del_working\%1 (
  332. call :CopyFileAndDelete %BDir%\del_working\%1 %BDir%\del_finished\%1
  333. )
  334. )
  335. if exist %BDir%\add_finished\%1.loc (
  336. call :CopyFileAndDelete %BDir%\add_finished\%1.loc %BDir%\del_finished\%1.loc
  337. )
  338. if exist %BDir%\del_requests\%1.loc (
  339. del /q %BDir%\del_requests\%1.loc
  340. )
  341. REM Put the log file in del_finished
  342. if exist %BDir%\add_finished\%1.log (
  343. call :CopyFileAndDelete %BDir%\add_finished\%1.log %BDir%\del_finished\%1.log
  344. )
  345. if exist %BDir%\del_working\%1.log (
  346. type %BDir%\del_working\%1.log >> %BDir%\del_finished\%1.log
  347. del /q %BDir%\del_working\%1.log
  348. )
  349. goto :EOF
  350. REM ***************************************************
  351. REM DeleteIfExists
  352. REM
  353. REM Params:
  354. REM %1 File to delete
  355. REM
  356. REM Return Value:
  357. REM ThereWereErrors not defined if success
  358. REM yes, if not successful
  359. REM
  360. REM ****************************************************
  361. :DeleteIfExists %1
  362. set ThereWereErrors=
  363. if not exist %1 goto EndDeleteIfExists
  364. del /q %1
  365. if not exist %1 goto EndDeleteIfExists
  366. echo ERROR: Failed to delete %1 | tee -a %LogFile%
  367. set ThereWereErrors=yes
  368. :EndDeleteIfExists
  369. goto :EOF
  370. REM *****************************************************
  371. REM CopyFile
  372. REM
  373. REM Params:
  374. REM %1 Source file
  375. REM %2 Destination file
  376. REM
  377. REM *****************************************************
  378. :CopyFileAndDelete %1 %2
  379. set ThereWereErrors=
  380. copy %1 %2 >nul 2>nul
  381. if not exist %2 (
  382. echo ERROR: %1 could not be copied to %2 | tee -a %LogFile%
  383. set ThereWereErrors=yes
  384. goto :EndCopyFileAndDelete
  385. )
  386. del /q %1 >nul 2>nul
  387. if exist %1 (
  388. echo ERROR: %1 could not be deleted | tee -a %LogFile%
  389. set ThereWereErrors=yes
  390. goto :EndCopyFileAndDelete
  391. )
  392. :EndCopyFileAndDelete
  393. goto :EOF
  394. :end
  395. goto :EOF
  396. :errend
  397. goto :EOF