1 | #!/usr/bin/perl -w
|
---|
2 | use File::Temp qw/ tempdir /;
|
---|
3 | use File::Copy;
|
---|
4 | use MondoRescue::File;
|
---|
5 | use strict;
|
---|
6 |
|
---|
7 | # Create the structure for the tests
|
---|
8 | my $bd = tempdir(
|
---|
9 | CLEANUP => 1
|
---|
10 | );
|
---|
11 |
|
---|
12 | # Create directory structure
|
---|
13 | chdir $bd || die "Unable to chdir to $bd";
|
---|
14 | mkdir "usr",0755 || die "$!";
|
---|
15 | mkdir "usr/bin",0755 || die "$!";
|
---|
16 | mkdir "usr/lib",0755 || die "$!";
|
---|
17 | mkdir "var",0755 || die "$!";
|
---|
18 | mkdir "var/spool",0755 || die "$!";
|
---|
19 | mkdir "var/spool/mail",0755 || die "$!";
|
---|
20 | mkdir "var/lib",0755 || die "$!";
|
---|
21 |
|
---|
22 | # Copy some files in it
|
---|
23 | copy "/usr/bin/perl","usr/bin" || die "$!";
|
---|
24 | chmod 0755,"usr/bin/perl";
|
---|
25 | my $libc;
|
---|
26 | foreach my $f (<"/lib/libc.so.[0-9]*">) {
|
---|
27 | copy "$f","usr/lib" || die "$!";
|
---|
28 | $libc = $f;
|
---|
29 | }
|
---|
30 |
|
---|
31 | # Create links on files
|
---|
32 | chdir "$bd/usr/bin" || die "$!";
|
---|
33 | symlink "perl","toto" || die "$!"; # in same dir
|
---|
34 | chdir "$bd/var/spool/" || die "$!";
|
---|
35 | symlink "../../usr/bin/perl","toto" || die "$!"; # in another dir relatively
|
---|
36 | chdir "$bd/var" || die "$!";
|
---|
37 | symlink "$bd/usr/bin/perl","truc" || die "$!"; # in another dir absolutely
|
---|
38 |
|
---|
39 | # Create links on dirs
|
---|
40 | chdir "$bd/var/spool" || die "$!";
|
---|
41 | symlink "mail","titi" || die "$!"; # in same dir
|
---|
42 | chdir "$bd/var/lib" || die "$!";
|
---|
43 | symlink "../spool/mail","titi" || die "$!"; # in another dir relatively
|
---|
44 | chdir "$bd/var" || die "$!";
|
---|
45 | symlink "$bd/var/spool/mail","tutu" || die "$!"; # in another dir absolutely
|
---|
46 |
|
---|
47 | print "Temporary dir: $bd\n";
|
---|
48 |
|
---|
49 | # Now try to see if we get the right links
|
---|
50 | my $h = mr_file_read_all_link(
|
---|
51 | "$bd/usr/bin/toto",
|
---|
52 | "$bd/var/spool/toto",
|
---|
53 | "$bd/var/truc",
|
---|
54 | "$bd/var/spool/titi",
|
---|
55 | "$bd/var/lib/titi",
|
---|
56 | "$bd/var/tutu"
|
---|
57 | );
|
---|
58 |
|
---|
59 | my $more = 1;
|
---|
60 |
|
---|
61 | eval
|
---|
62 | {
|
---|
63 | require Test::More;
|
---|
64 | Test::More->import();
|
---|
65 | no_plan();
|
---|
66 | };
|
---|
67 | # Test::More not found so simpler test
|
---|
68 | if ($@) {
|
---|
69 | require Test;
|
---|
70 | Test->import();
|
---|
71 | $more = 0;
|
---|
72 | plan(tests => 12);
|
---|
73 | }
|
---|
74 | # Got, expected, comment
|
---|
75 | myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/toto"}, 1, "File link in same dir to itself");
|
---|
76 | myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in same dir to link");
|
---|
77 | myis($h->{"$bd/var/truc"}->{"$bd/var/truc"}, 1, "File link in another absolute dir to itself");
|
---|
78 | myis($h->{"$bd/var/truc"}->{"$bd/usr/bin/perl"}, 1, "File link in another absolute dir to link");
|
---|
79 | myis($h->{"$bd/var/spool/toto"}->{"$bd/var/spool/toto"}, 1, "File link in another relative dir to itself");
|
---|
80 | myis($h->{"$bd/var/spool/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in another relative dir to link");
|
---|
81 | myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/titi"}, 1, "Directory link in same dir to itself");
|
---|
82 | myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in same dir to link");
|
---|
83 | myis($h->{"$bd/var/lib/titi"}->{"$bd/var/lib/titi"}, 1, "Directory link in another relative dir to itself");
|
---|
84 | myis($h->{"$bd/var/lib/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in another relative dir to link");
|
---|
85 | myis($h->{"$bd/var/tutu"}->{"$bd/var/tutu"}, 1, "Directory link in another absolute dir to itself");
|
---|
86 | myis($h->{"$bd/var/tutu"}->{"$bd/var/spool/mail"}, 1, "Directory link in another absolute dir to link");
|
---|
87 | chdir "/tmp";
|
---|
88 | exit(0);
|
---|
89 |
|
---|
90 | sub myis {
|
---|
91 |
|
---|
92 | if ($more eq 1) {
|
---|
93 | return(is(@_));
|
---|
94 | } else {
|
---|
95 | my $p1 = shift;
|
---|
96 | my $p2 = shift;
|
---|
97 | my $p3 = shift;
|
---|
98 | print "# test $p3\n";
|
---|
99 | return(ok($p1,$p2));
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|