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.

91 lines
2.0 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM hashrep.cmd
  5. REM update a filename to hash mapping with new hashes
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. use Logmsg;
  19. sub Usage { print<<USAGE; exit(1) }
  20. hashrep <new_hash_file> <hash_file>
  21. new_hash_file a file with the filenames and new hashes to be stored
  22. in hash_file
  23. hash_file a file with filenames and hashes to be updated
  24. The format for both files is:
  25. filename1 - hash1
  26. filename2 - hash2
  27. USAGE
  28. my ($new_hash_file, $hash_file);
  29. parseargs('?' => \&Usage,
  30. \$new_hash_file,
  31. \$hash_file);
  32. if (!$new_hash_file or !$hash_file) {
  33. errmsg("missing argument");
  34. Usage;
  35. }
  36. if (!-e $new_hash_file) {
  37. errmsg("file $new_hash_file does not exist");
  38. exit;
  39. }
  40. if (!-e $hash_file) {
  41. errmsg("file $hash_file does not exist");
  42. exit;
  43. }
  44. if (!open HASH_NEW, $new_hash_file) {
  45. errmsg("failed to open $new_hash_file: $!");
  46. exit 1;
  47. }
  48. my %hashes; # new hashes to insert
  49. while (<HASH_NEW>) {
  50. chomp;
  51. my ($name, $hash) = split / - /;
  52. $hashes{lc $name} = $hash;
  53. }
  54. close HASH_NEW;
  55. if (!rename $hash_file, "$hash_file.tmp") {
  56. errmsg("failed to rename $hash_file to $hash_file.tmp: $!");
  57. exit 1;
  58. }
  59. if (!open HASH_READ, "$hash_file.tmp") {
  60. errmsg("failed to open $hash_file.tmp: $!");
  61. }
  62. if (!open HASH_WRITE, ">$hash_file") {
  63. errmsg("failed to open $hash_file: $!");
  64. }
  65. while (<HASH_READ>) {
  66. chomp;
  67. my ($name, $hash) = split / - /;
  68. if (exists $hashes{lc $name}) {
  69. dbgmsg("replacing hash in $hash_file: $name ($hash) => ($hashes{lc $name})");
  70. $hash = $hashes{lc $name};
  71. }
  72. print HASH_WRITE "$name - $hash\n";
  73. }
  74. close HASH_READ;
  75. close HASH_WRITE;