2 # Prepare a directory with known files and clean up afterwards
7 print "Usage: $0 prepare|postprocess dir [logfile]\n";
11 # <precheck> expects an error message on stdout
17 if ($ARGV[0] eq "prepare")
19 my $dirname = $ARGV[1];
20 mkdir $dirname || errout
"$!";
23 # Create the files in alphabetical order, to increase the chances
24 # of receiving a consistent set of directory contents regardless
25 # of whether the server alphabetizes the results or not.
26 mkdir "asubdir" || errout
"$!";
27 chmod 0777, "asubdir";
29 open(FILE
, ">plainfile.txt") || errout
"$!";
31 print FILE
"Test file to support curl test suite\n";
33 utime time, timegm
(0,0,12,1,0,100), "plainfile.txt";
34 chmod 0666, "plainfile.txt";
36 open(FILE
, ">rofile.txt") || errout
"$!";
38 print FILE
"Read-only test file to support curl test suite\n";
40 utime time, timegm
(0,0,12,31,11,100), "rofile.txt";
41 chmod 0444, "rofile.txt";
45 elsif ($ARGV[0] eq "postprocess")
47 my $dirname = $ARGV[1];
48 my $logfile = $ARGV[2];
50 # Clean up the test directory
51 unlink "$dirname/rofile.txt";
52 unlink "$dirname/plainfile.txt";
53 rmdir "$dirname/asubdir";
55 rmdir $dirname || die "$!";
58 # Process the directory file to remove all information that
59 # could be inconsistent from one test run to the next (e.g.
60 # file date) or may be unsupported on some platforms (e.g.
61 # Windows). Also, since 7.17.0, the sftp directory listing
62 # format can be dependent on the server (with a recent
63 # enough version of libssh2) so this script must also
64 # canonicalize the format. Here are examples of the general
66 # -r--r--r-- 12 ausername grp 47 Dec 31 2000 rofile.txt
67 # -r--r--r-- 1 1234 4321 47 Dec 31 2000 rofile.txt
68 # The "canonical" format is similar to the first (which is
69 # the one generated on a typical Linux installation):
70 # -r-?r-?r-? 12 U U 47 Dec 31 2000 rofile.txt
73 open(IN
, "<$logfile") || die "$!";
75 /^(.)(..).(..).(..).\s*(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+\s+\S+\s+\S+)(.*)$/;
77 # Erase all directory metadata except for the name, as it is not
78 # consistent for across all test systems and filesystems
79 push @canondir, "d????????? N U U N ??? N NN:NN$8\n";
81 # Erase user and group names, as they are not consistent across
83 my $line = sprintf("%s%s?%s?%s?%5d U U %15d %s%s\n", $1,$2,$3,$4,$5,$6,$7,$8);
84 push @canondir, $line;
86 # Unexpected format; just pass it through and let the test fail
92 @canondir = sort {substr($a,57) cmp substr($b,57)} @canondir;
93 my $newfile = $logfile . ".new";
94 open(OUT
, ">$newfile") || die "$!";
95 print OUT
join('', @canondir);
99 rename $newfile, $logfile;
104 print "Unsupported command $ARGV[0]\n";