test613.pl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. # Prepare a directory with known files and clean up afterwards
  26. use Time::Local;
  27. if ( $#ARGV < 1 )
  28. {
  29. print "Usage: $0 prepare|postprocess dir [logfile]\n";
  30. exit 1;
  31. }
  32. # <precheck> expects an error message on stdout
  33. sub errout {
  34. print $_[0] . "\n";
  35. exit 1;
  36. }
  37. if ($ARGV[0] eq "prepare")
  38. {
  39. my $dirname = $ARGV[1];
  40. mkdir $dirname || errout "$!";
  41. chdir $dirname;
  42. # Create the files in alphabetical order, to increase the chances
  43. # of receiving a consistent set of directory contents regardless
  44. # of whether the server alphabetizes the results or not.
  45. mkdir "asubdir" || errout "$!";
  46. chmod 0777, "asubdir";
  47. open(FILE, ">plainfile.txt") || errout "$!";
  48. binmode FILE;
  49. print FILE "Test file to support curl test suite\n";
  50. close(FILE);
  51. # The mtime is specifically chosen to be an even number so that it can be
  52. # represented exactly on a FAT filesystem.
  53. utime time, timegm(0,0,12,1,0,100), "plainfile.txt";
  54. chmod 0666, "plainfile.txt";
  55. open(FILE, ">rofile.txt") || errout "$!";
  56. binmode FILE;
  57. print FILE "Read-only test file to support curl test suite\n";
  58. close(FILE);
  59. # The mtime is specifically chosen to be an even number so that it can be
  60. # represented exactly on a FAT filesystem.
  61. utime time, timegm(0,0,12,31,11,100), "rofile.txt";
  62. chmod 0444, "rofile.txt";
  63. exit 0;
  64. }
  65. elsif ($ARGV[0] eq "postprocess")
  66. {
  67. my $dirname = $ARGV[1];
  68. my $logfile = $ARGV[2];
  69. # Clean up the test directory
  70. unlink "$dirname/rofile.txt";
  71. unlink "$dirname/plainfile.txt";
  72. rmdir "$dirname/asubdir";
  73. rmdir $dirname || die "$!";
  74. if ($logfile && -s $logfile) {
  75. # Process the directory file to remove all information that
  76. # could be inconsistent from one test run to the next (e.g.
  77. # file date) or may be unsupported on some platforms (e.g.
  78. # Windows). Also, since 7.17.0, the sftp directory listing
  79. # format can be dependent on the server (with a recent
  80. # enough version of libssh2) so this script must also
  81. # canonicalize the format. Here are examples of the general
  82. # format supported:
  83. # -r--r--r-- 12 ausername grp 47 Dec 31 2000 rofile.txt
  84. # -r--r--r-- 1 1234 4321 47 Dec 31 2000 rofile.txt
  85. # The "canonical" format is similar to the first (which is
  86. # the one generated on a typical Linux installation):
  87. # -r-?r-?r-? 12 U U 47 Dec 31 2000 rofile.txt
  88. my @canondir;
  89. open(IN, "<$logfile") || die "$!";
  90. while (<IN>) {
  91. /^(.)(..).(..).(..).\s*(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+\s+\S+\s+\S+)\s+(.*)$/;
  92. if ($1 eq "d") {
  93. # Skip current and parent directory listing, because some SSH
  94. # servers (eg. OpenSSH for Windows) are not listing those
  95. if ($8 eq "." || $8 eq "..") {
  96. next;
  97. }
  98. # Erase all directory metadata except for the name, as it is not
  99. # consistent for across all test systems and filesystems
  100. push @canondir, "d????????? N U U N ??? N NN:NN $8\n";
  101. } elsif ($1 eq "-") {
  102. # Replace missing group and other permissions with user
  103. # permissions (eg. on Windows) due to them being shown as *
  104. my ($u, $g, $o) = ($2, $3, $4);
  105. if($g eq "**") {
  106. $g = $u;
  107. }
  108. if($o eq "**") {
  109. $o = $u;
  110. }
  111. # Erase user and group names, as they are not consistent across
  112. # all test systems
  113. my $line = sprintf("%s%s?%s?%s?%5d U U %15d %s %s\n", $1,$u,$g,$o,$5,$6,$7,$8);
  114. push @canondir, $line;
  115. } else {
  116. # Unexpected format; just pass it through and let the test fail
  117. push @canondir, $_;
  118. }
  119. }
  120. close(IN);
  121. @canondir = sort {substr($a,57) cmp substr($b,57)} @canondir;
  122. my $newfile = $logfile . ".new";
  123. open(OUT, ">$newfile") || die "$!";
  124. print OUT join('', @canondir);
  125. close(OUT);
  126. unlink $logfile;
  127. rename $newfile, $logfile;
  128. }
  129. exit 0;
  130. }
  131. print "Unsupported command $ARGV[0]\n";
  132. exit 1;