#!/depot/perl-5.003/bin/perl

#
#  mkregression - Regression test builder for cvsmapfs.
#  Copyright (C) 1995 Brian Bartholomew <bb@wv.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  Please contact Working Version at http://www.wv.com for up-to-date
#  information on this code.
#

system ("rm -rf regressiondir");
mkdir ("regressiondir", 0755) || die;
chdir ("regressiondir") || die;
mkdir ("arena", 0755) || die;
chdir ("arena") || die;

#  patterns

!(system ("mknod blkdev b 1 1") / 256) || die;
chown (1, 1, "blkdev") || die;
chmod (0600, "blkdev") || die;
utime (800000000, 800000000, "blkdev") || die;

!(system ("mknod chardev c 2 2") / 256) || die;
chown (2, 2, "chardev") || die;
chmod (0600, "chardev") || die;
utime (800000001, 800000001, "chardev") || die;

mkdir ("dir", 0755) || die;
chown (3, 3, "dir") || die;
chmod (0755, "dir") || die;
utime (800000002, 800000002, "dir") || die;

&touch ("file") || die;
chown (4, 4, "file") || die;
chmod (0644, "file") || die;
utime (800000003, 800000003, "file") || die;

!(system ("mkfifo pipe") / 256) || die;
chown (5, 5, "pipe") || die;
chmod (0644, "pipe") || die;
utime (800000004, 800000004, "pipe") || die;

#socket
#chown
#chmod
#utime

symlink ("file", "symlink") || die;
#chown
#chmod
#utime

#  excluded names

mkdir ("CVS", 0755) || die;
&touch ("CVS/foo") || die;

mkdir ("notCVS", 0755) || die;
&touch ("notCVS/bar") || die;

mkdir ("CVSnot", 0755) || die;
&touch ("CVSnot/baz") || die;

chown (8, 8, "CVS", "notCVS", "CVSnot") || die;
chmod (0755, "CVS", "notCVS", "CVSnot") || die;
utime (800000008, 800000008, "CVS", "notCVS", "CVSnot") || die;

#  permission denied

mkdir ("closeddir", 0) || die;
chown (7, 7, "closeddir") || die;
utime (800000007, 800000007, "closeddir") || die;

#  funny chars in filenames

&touch (" ") || die;
&touch ("space here") || die;
&touch ("new\nline") || die;
&touch ("tab\there") || die;
&touch ('` ~ ! @ # $ % ^ & * ( ) - _ = + [ { ] } \\ | ; : \' " , < . > ?') || die;
&touch ("\001\002\003") || die;
&touch ("\201\202\203") || die;

#  links

mkdir ("links", 0755) || die;
&touch ("links/link1") || die;
link ("links/link1", "links/link2") || die;
link ("links/link1", "../link3") || die;

chown (0, 0, "links", "links/link1") || die;
chmod (0755, "links", "links/link1") || die;
utime (800000010, 800000010, "links/link1") || die;
utime (800000010, 800000010, "links") || die;

#dir contains multiple filesystems and links kept seperate (too hard to
#make identical inode #'s?)

#running twice without errors.

#run not as root and check for errors.

chdir ("../..") || die;
chown (0, 0, "regressiondir/arena", "regressiondir") || die;
chmod (0755, "regressiondir/arena", "regressiondir") || die;
utime (800000010, 800000010, "regressiondir/arena", "regressiondir") || die;

sub touch {
	local ($file, $junk) = @_;
	$file =~ s#^(\s)#./$1#;
	open (TOUCH, "> $file\0") || die "file $file";
	close (TOUCH) || die;
	chown (0, 0, $file) || die;
	chmod (0644, $file) || die;
	utime (800000009, 800000009, $file) || die;
}
