prepup.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {
  2. This file is part of the Free Pascal test suite.
  3. Copyright (c) 2006 by the Free Pascal development team.
  4. This program collects the results of a testsuite run
  5. and prepares things for an upload of the results to the
  6. database
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. program prepup;
  14. uses
  15. sysutils,libtar,zstream;
  16. const
  17. use_longlog : boolean = false;
  18. has_file_errors : boolean = false;
  19. MAX_RETRY = 5;
  20. RETRY_WAIT_TIME = 1000; { One second wait time before trying again }
  21. var
  22. tarwriter : ttarwriter;
  23. c : tgzfilestream;
  24. procedure dosearch(const dir : string);
  25. procedure domask(const s : string);
  26. Var
  27. Info : TSearchRec;
  28. hs : string;
  29. tries : longint;
  30. write_ok : boolean;
  31. begin
  32. If FindFirst (dir+DirectorySeparator+s,faAnyFile,Info)=0 then
  33. begin
  34. Repeat
  35. With Info do
  36. begin
  37. hs:=dir+DirectorySeparator+Name;
  38. { strip leading ./ }
  39. delete(hs,1,2);
  40. if not tarwriter.addfile(hs) then
  41. begin
  42. tries:=1;
  43. write_ok:=false;
  44. while tries<MAX_RETRY do
  45. begin
  46. sleep(RETRY_WAIT_TIME);
  47. inc(tries);
  48. if tarwriter.addfile(hs) then
  49. begin
  50. write_ok:=true;
  51. tries:=MAX_RETRY;
  52. end;
  53. end;
  54. has_file_errors:=(write_ok=false);
  55. if not write_ok then
  56. tarwriter.addstring('###File Open failed###',
  57. ConvertFileName(hs),Info.Time);
  58. end;
  59. end;
  60. Until FindNext(info)<>0;
  61. end;
  62. FindClose(Info);
  63. end;
  64. Var Info : TSearchRec;
  65. Begin
  66. If FindFirst (dir+DirectorySeparator+'*',faDirectory,Info)=0 then
  67. begin
  68. Repeat
  69. With Info do
  70. begin
  71. If ((Attr and faDirectory) = faDirectory) and (name<>'.') and (name<>'..') then
  72. dosearch(dir+DirectorySeparator+name);
  73. end;
  74. Until FindNext(info)<>0;
  75. end;
  76. FindClose(Info);
  77. domask('*.elg');
  78. domask('*.log');
  79. End;
  80. var
  81. index : longint;
  82. const
  83. has_errors : boolean = false;
  84. begin
  85. index:=1;
  86. if paramcount<>1 then
  87. begin
  88. if paramstr(1)='-ll' then
  89. begin
  90. use_longlog:=true;
  91. index:=2;
  92. end
  93. else
  94. begin
  95. writeln('Usage: prepup [-ll] <name of .tar.gz>');
  96. Writeln('Optional -ll parameter is used to specify use of longlog');
  97. halt(1);
  98. end
  99. end;
  100. C:=TGZFileStream.Create(paramstr(index),gzOpenWrite);
  101. TarWriter := TTarWriter.Create (C);
  102. if not use_longlog then
  103. dosearch('.');
  104. if not TarWriter.AddFile('dbdigest.cfg') then
  105. has_errors:=true;
  106. if not TarWriter.AddFile('log') then
  107. has_errors:=true;
  108. if use_longlog then
  109. if not TarWriter.AddFile('longlog') then
  110. has_errors:=true;
  111. TarWriter.free;
  112. c.free;
  113. if has_file_errors then
  114. writeln(stderr,'Prepup error: some files were not copied');
  115. if has_errors then
  116. halt(2);
  117. end.