1 | #!./perl
|
---|
2 |
|
---|
3 | BEGIN {
|
---|
4 | chdir 't' if -d 't';
|
---|
5 | @INC = '../lib';
|
---|
6 | require "./test.pl";
|
---|
7 | }
|
---|
8 |
|
---|
9 | use Config;
|
---|
10 | use File::Spec::Functions;
|
---|
11 |
|
---|
12 | my $Is_MacOS = ($^O eq 'MacOS');
|
---|
13 | my $Is_VMSish = ($^O eq 'VMS');
|
---|
14 |
|
---|
15 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
|
---|
16 | $wd = `cd`;
|
---|
17 | } elsif ($^O eq 'VMS') {
|
---|
18 | $wd = `show default`;
|
---|
19 | } else {
|
---|
20 | $wd = `pwd`;
|
---|
21 | }
|
---|
22 | chomp($wd);
|
---|
23 |
|
---|
24 | my $has_link = $Config{d_link};
|
---|
25 |
|
---|
26 | my $accurate_timestamps =
|
---|
27 | !($^O eq 'MSWin32' || $^O eq 'NetWare' ||
|
---|
28 | $^O eq 'dos' || $^O eq 'os2' ||
|
---|
29 | $^O eq 'mint' || $^O eq 'cygwin' ||
|
---|
30 | $^O eq 'amigaos' || $wd =~ m#$Config{afsroot}/# ||
|
---|
31 | $Is_MacOS
|
---|
32 | );
|
---|
33 |
|
---|
34 | if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
|
---|
35 | if (Win32::FsType() eq 'NTFS') {
|
---|
36 | $has_link = 1;
|
---|
37 | $accurate_timestamps = 1;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | if ($^O eq 'os2') {
|
---|
42 | $has_link = 0;}
|
---|
43 |
|
---|
44 | my $needs_fh_reopen =
|
---|
45 | $^O eq 'dos'
|
---|
46 | # Not needed on HPFS, but needed on HPFS386 ?!
|
---|
47 | || $^O eq 'os2';
|
---|
48 |
|
---|
49 | $needs_fh_reopen = 1 if (defined &Win32::IsWin95 && Win32::IsWin95());
|
---|
50 |
|
---|
51 | my $skip_mode_checks =
|
---|
52 | $^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/;
|
---|
53 |
|
---|
54 | plan tests => 42;
|
---|
55 |
|
---|
56 |
|
---|
57 | if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
|
---|
58 | `rmdir /s /q tmp 2>nul`;
|
---|
59 | `mkdir tmp`;
|
---|
60 | }
|
---|
61 | elsif ($^O eq 'VMS') {
|
---|
62 | `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
|
---|
63 | `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
|
---|
64 | `create/directory [.tmp]`;
|
---|
65 | }
|
---|
66 | elsif ($Is_MacOS) {
|
---|
67 | rmdir "tmp"; mkdir "tmp";
|
---|
68 | }
|
---|
69 | else {
|
---|
70 | `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
|
---|
71 | }
|
---|
72 |
|
---|
73 | chdir catdir(curdir(), 'tmp');
|
---|
74 |
|
---|
75 | `/bin/rm -rf a b c x` if -x '/bin/rm';
|
---|
76 |
|
---|
77 | umask(022);
|
---|
78 |
|
---|
79 | SKIP: {
|
---|
80 | skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc') || $Is_MacOS;
|
---|
81 |
|
---|
82 | is((umask(0)&0777), 022, 'umask'),
|
---|
83 | }
|
---|
84 |
|
---|
85 | open(FH,'>x') || die "Can't create x";
|
---|
86 | close(FH);
|
---|
87 | open(FH,'>a') || die "Can't create a";
|
---|
88 | close(FH);
|
---|
89 |
|
---|
90 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
91 | $blksize,$blocks);
|
---|
92 |
|
---|
93 | SKIP: {
|
---|
94 | skip("no link", 4) unless $has_link;
|
---|
95 |
|
---|
96 | ok(link('a','b'), "link a b");
|
---|
97 | ok(link('b','c'), "link b c");
|
---|
98 |
|
---|
99 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
100 | $blksize,$blocks) = stat('c');
|
---|
101 |
|
---|
102 | SKIP: {
|
---|
103 | skip "no nlink", 1 if $Config{dont_use_nlink};
|
---|
104 |
|
---|
105 | is($nlink, 3, "link count of triply-linked file");
|
---|
106 | }
|
---|
107 |
|
---|
108 | SKIP: {
|
---|
109 | skip "hard links not that hard in $^O", 1 if $^O eq 'amigaos';
|
---|
110 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
111 |
|
---|
112 | # if ($^O eq 'cygwin') { # new files on cygwin get rwx instead of rw-
|
---|
113 | # is($mode & 0777, 0777, "mode of triply-linked file");
|
---|
114 | # } else {
|
---|
115 | is($mode & 0777, 0666, "mode of triply-linked file");
|
---|
116 | # }
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
|
---|
121 |
|
---|
122 | is(chmod($newmode,'a'), 1, "chmod succeeding");
|
---|
123 |
|
---|
124 | SKIP: {
|
---|
125 | skip("no link", 7) unless $has_link;
|
---|
126 |
|
---|
127 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
128 | $blksize,$blocks) = stat('c');
|
---|
129 |
|
---|
130 | SKIP: {
|
---|
131 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
132 |
|
---|
133 | is($mode & 0777, $newmode, "chmod going through");
|
---|
134 | }
|
---|
135 |
|
---|
136 | $newmode = 0700;
|
---|
137 | chmod 0444, 'x';
|
---|
138 | $newmode = 0666;
|
---|
139 |
|
---|
140 | is(chmod($newmode,'c','x'), 2, "chmod two files");
|
---|
141 |
|
---|
142 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
143 | $blksize,$blocks) = stat('c');
|
---|
144 |
|
---|
145 | SKIP: {
|
---|
146 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
147 |
|
---|
148 | is($mode & 0777, $newmode, "chmod going through to c");
|
---|
149 | }
|
---|
150 |
|
---|
151 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
152 | $blksize,$blocks) = stat('x');
|
---|
153 |
|
---|
154 | SKIP: {
|
---|
155 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
156 |
|
---|
157 | is($mode & 0777, $newmode, "chmod going through to x");
|
---|
158 | }
|
---|
159 |
|
---|
160 | is(unlink('b','x'), 2, "unlink two files");
|
---|
161 |
|
---|
162 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
163 | $blksize,$blocks) = stat('b');
|
---|
164 |
|
---|
165 | is($ino, undef, "ino of removed file b should be undef");
|
---|
166 |
|
---|
167 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
168 | $blksize,$blocks) = stat('x');
|
---|
169 |
|
---|
170 | is($ino, undef, "ino of removed file x should be undef");
|
---|
171 | }
|
---|
172 |
|
---|
173 | SKIP: {
|
---|
174 | skip "no fchmod", 5 unless ($Config{d_fchmod} || "") eq "define";
|
---|
175 | skip "doesn't work on OS/2", 5 if $^O eq 'os2';
|
---|
176 | ok(open(my $fh, "<", "a"), "open a");
|
---|
177 | is(chmod(0, $fh), 1, "fchmod");
|
---|
178 | $mode = (stat "a")[2];
|
---|
179 | SKIP: {
|
---|
180 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
181 | is($mode & 0777, 0, "perm reset");
|
---|
182 | }
|
---|
183 | is(chmod($newmode, "a"), 1, "fchmod");
|
---|
184 | $mode = (stat $fh)[2];
|
---|
185 | SKIP: {
|
---|
186 | skip "no mode checks", 1 if $skip_mode_checks;
|
---|
187 | is($mode & 0777, $newmode, "perm restored");
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | SKIP: {
|
---|
192 | skip "no fchown", 1 unless ($Config{d_fchown} || "") eq "define";
|
---|
193 | open(my $fh, "<", "a");
|
---|
194 | is(chown(-1, -1, $fh), 1, "fchown");
|
---|
195 | }
|
---|
196 |
|
---|
197 | SKIP: {
|
---|
198 | skip "has fchmod", 1 if ($Config{d_fchmod} || "") eq "define";
|
---|
199 | open(my $fh, "<", "a");
|
---|
200 | eval { chmod(0777, $fh); };
|
---|
201 | like($@, qr/^The fchmod function is unimplemented at/, "fchmod is unimplemented");
|
---|
202 | }
|
---|
203 |
|
---|
204 | SKIP: {
|
---|
205 | skip "has fchown", 1 if ($Config{d_fchown} || "") eq "define";
|
---|
206 | open(my $fh, "<", "a");
|
---|
207 | eval { chown(0, 0, $fh); };
|
---|
208 | like($@, qr/^The fchown function is unimplemented at/, "fchown is unimplemented");
|
---|
209 | }
|
---|
210 |
|
---|
211 | is(rename('a','b'), 1, "rename a b");
|
---|
212 |
|
---|
213 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
214 | $blksize,$blocks) = stat('a');
|
---|
215 |
|
---|
216 | is($ino, undef, "ino of renamed file a should be undef");
|
---|
217 |
|
---|
218 | $delta = $accurate_timestamps ? 1 : 2; # Granularity of time on the filesystem
|
---|
219 | chmod 0777, 'b';
|
---|
220 | $foo = (utime 500000000,500000000 + $delta,'b');
|
---|
221 |
|
---|
222 | is($foo, 1, "utime");
|
---|
223 |
|
---|
224 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
225 | $blksize,$blocks) = stat('b');
|
---|
226 |
|
---|
227 | SKIP: {
|
---|
228 | skip "bogus inode num", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare');
|
---|
229 |
|
---|
230 | ok($ino, 'non-zero inode num');
|
---|
231 | }
|
---|
232 |
|
---|
233 | SKIP: {
|
---|
234 | skip "filesystem atime/mtime granularity too low", 2
|
---|
235 | unless $accurate_timestamps;
|
---|
236 |
|
---|
237 | print "# atime - $atime mtime - $mtime delta - $delta\n";
|
---|
238 | if($atime == 500000000 && $mtime == 500000000 + $delta) {
|
---|
239 | pass('atime');
|
---|
240 | pass('mtime');
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | if ($^O =~ /\blinux\b/i) {
|
---|
244 | print "# Maybe stat() cannot get the correct atime, ".
|
---|
245 | "as happens via NFS on linux?\n";
|
---|
246 | $foo = (utime 400000000,500000000 + 2*$delta,'b');
|
---|
247 | my ($new_atime, $new_mtime) = (stat('b'))[8,9];
|
---|
248 | print "# newatime - $new_atime nemtime - $new_mtime\n";
|
---|
249 | if ($new_atime == $atime && $new_mtime - $mtime == $delta) {
|
---|
250 | pass("atime - accounted for possible NFS/glibc2.2 bug on linux");
|
---|
251 | pass("mtime - accounted for possible NFS/glibc2.2 bug on linux");
|
---|
252 | }
|
---|
253 | else {
|
---|
254 | fail("atime - $atime/$new_atime $mtime/$new_mtime");
|
---|
255 | fail("mtime - $atime/$new_atime $mtime/$new_mtime");
|
---|
256 | }
|
---|
257 | }
|
---|
258 | elsif ($^O eq 'VMS') {
|
---|
259 | # why is this 1 second off?
|
---|
260 | is( $atime, 500000001, 'atime' );
|
---|
261 | is( $mtime, 500000000 + $delta, 'mtime' );
|
---|
262 | }
|
---|
263 | elsif ($^O eq 'beos') {
|
---|
264 | SKIP: { skip "atime not updated", 1; }
|
---|
265 | is($mtime, 500000001, 'mtime');
|
---|
266 | }
|
---|
267 | else {
|
---|
268 | fail("atime");
|
---|
269 | fail("mtime");
|
---|
270 | }
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | is(unlink('b'), 1, "unlink b");
|
---|
275 |
|
---|
276 | ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
|
---|
277 | $blksize,$blocks) = stat('b');
|
---|
278 | is($ino, undef, "ino of unlinked file b should be undef");
|
---|
279 | unlink 'c';
|
---|
280 |
|
---|
281 | chdir $wd || die "Can't cd back to $wd";
|
---|
282 |
|
---|
283 | # Yet another way to look for links (perhaps those that cannot be
|
---|
284 | # created by perl?). Hopefully there is an ls utility in your
|
---|
285 | # %PATH%. N.B. that $^O is 'cygwin' on Cygwin.
|
---|
286 |
|
---|
287 | SKIP: {
|
---|
288 | skip "Win32/Netware specific test", 2
|
---|
289 | unless ($^O eq 'MSWin32') || ($^O eq 'NetWare');
|
---|
290 | skip "No symbolic links found to test with", 2
|
---|
291 | unless `ls -l perl 2>nul` =~ /^l.*->/;
|
---|
292 |
|
---|
293 | system("cp TEST TEST$$");
|
---|
294 | # we have to copy because e.g. GNU grep gets huffy if we have
|
---|
295 | # a symlink forest to another disk (it complains about too many
|
---|
296 | # levels of symbolic links, even if we have only two)
|
---|
297 | is(symlink("TEST$$","c"), 1, "symlink");
|
---|
298 | $foo = `grep perl c 2>&1`;
|
---|
299 | ok($foo, "found perl in c");
|
---|
300 | unlink 'c';
|
---|
301 | unlink("TEST$$");
|
---|
302 | }
|
---|
303 |
|
---|
304 | unlink "Iofs.tmp";
|
---|
305 | open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
|
---|
306 | print IOFSCOM 'helloworld';
|
---|
307 | close(IOFSCOM);
|
---|
308 |
|
---|
309 | # TODO: pp_truncate needs to be taught about F_CHSIZE and F_FREESP,
|
---|
310 | # as per UNIX FAQ.
|
---|
311 |
|
---|
312 | SKIP: {
|
---|
313 | # Check truncating a closed file.
|
---|
314 | eval { truncate "Iofs.tmp", 5; };
|
---|
315 |
|
---|
316 | skip("no truncate - $@", 8) if $@;
|
---|
317 |
|
---|
318 | is(-s "Iofs.tmp", 5, "truncation to five bytes");
|
---|
319 |
|
---|
320 | truncate "Iofs.tmp", 0;
|
---|
321 |
|
---|
322 | ok(-z "Iofs.tmp", "truncation to zero bytes");
|
---|
323 |
|
---|
324 | #these steps are necessary to check if file is really truncated
|
---|
325 | #On Win95, FH is updated, but file properties aren't
|
---|
326 | open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
|
---|
327 | print FH "x\n" x 200;
|
---|
328 | close FH;
|
---|
329 |
|
---|
330 | # Check truncating an open file.
|
---|
331 | open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
|
---|
332 |
|
---|
333 | binmode FH;
|
---|
334 | select FH;
|
---|
335 | $| = 1;
|
---|
336 | select STDOUT;
|
---|
337 |
|
---|
338 | {
|
---|
339 | use strict;
|
---|
340 | print FH "x\n" x 200;
|
---|
341 | ok(truncate(FH, 200), "fh resize to 200");
|
---|
342 | }
|
---|
343 |
|
---|
344 | if ($needs_fh_reopen) {
|
---|
345 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
|
---|
346 | }
|
---|
347 |
|
---|
348 | SKIP: {
|
---|
349 | if ($^O eq 'vos') {
|
---|
350 | skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 5);
|
---|
351 | }
|
---|
352 |
|
---|
353 | is(-s "Iofs.tmp", 200, "fh resize to 200 working (filename check)");
|
---|
354 |
|
---|
355 | ok(truncate(FH, 0), "fh resize to zero");
|
---|
356 |
|
---|
357 | if ($needs_fh_reopen) {
|
---|
358 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
|
---|
359 | }
|
---|
360 |
|
---|
361 | ok(-z "Iofs.tmp", "fh resize to zero working (filename check)");
|
---|
362 |
|
---|
363 | close FH;
|
---|
364 |
|
---|
365 | open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
|
---|
366 |
|
---|
367 | binmode FH;
|
---|
368 | select FH;
|
---|
369 | $| = 1;
|
---|
370 | select STDOUT;
|
---|
371 |
|
---|
372 | {
|
---|
373 | use strict;
|
---|
374 | print FH "x\n" x 200;
|
---|
375 | ok(truncate(*FH{IO}, 100), "fh resize by IO slot");
|
---|
376 | }
|
---|
377 |
|
---|
378 | if ($needs_fh_reopen) {
|
---|
379 | close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
|
---|
380 | }
|
---|
381 |
|
---|
382 | is(-s "Iofs.tmp", 100, "fh resize by IO slot working");
|
---|
383 |
|
---|
384 | close FH;
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | # check if rename() can be used to just change case of filename
|
---|
389 | SKIP: {
|
---|
390 | skip "Works in Cygwin only if check_case is set to relaxed", 1
|
---|
391 | if $^O eq 'cygwin';
|
---|
392 |
|
---|
393 | chdir './tmp';
|
---|
394 | open(FH,'>x') || die "Can't create x";
|
---|
395 | close(FH);
|
---|
396 | rename('x', 'X');
|
---|
397 |
|
---|
398 | # this works on win32 only, because fs isn't casesensitive
|
---|
399 | ok(-e 'X', "rename working");
|
---|
400 |
|
---|
401 | 1 while unlink 'X';
|
---|
402 | chdir $wd || die "Can't cd back to $wd";
|
---|
403 | }
|
---|
404 |
|
---|
405 | # check if rename() works on directories
|
---|
406 | if ($^O eq 'VMS') {
|
---|
407 | # must have delete access to rename a directory
|
---|
408 | `set file tmp.dir/protection=o:d`;
|
---|
409 | ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories") ||
|
---|
410 | print "# errno: $!\n";
|
---|
411 | } else {
|
---|
412 | ok(rename('tmp', 'tmp1'), "rename on directories");
|
---|
413 | }
|
---|
414 |
|
---|
415 | ok(-d 'tmp1', "rename on directories working");
|
---|
416 |
|
---|
417 | # FIXME - for some reason change 26009/26011 merged as 26627 still segfaults
|
---|
418 | # after all the tests have completed:
|
---|
419 | # #0 0x08124dd0 in Perl_pop_scope (my_perl=0x81b5ec8) at scope.c:143
|
---|
420 | # #1 0x080e88d8 in Perl_pp_leave (my_perl=0x81b5ec8) at pp_hot.c:1843
|
---|
421 | # #2 0x080c7dc1 in Perl_runops_debug (my_perl=0x81b5ec8) at dump.c:1459
|
---|
422 | # #3 0x080660af in S_run_body (my_perl=0x81b5ec8, oldscope=1) at perl.c:2369
|
---|
423 | # #4 0x08065ab1 in perl_run (my_perl=0x81b5ec8) at perl.c:2286
|
---|
424 | # #5 0x080604c3 in main (argc=2, argv=0xbffffc64, env=0xbffffc70)
|
---|
425 | # at perlmain.c:99
|
---|
426 | #
|
---|
427 | # 143 const I32 oldsave = PL_scopestack[--PL_scopestack_ix];
|
---|
428 | # (gdb) p my_perl->Tscopestack_ix
|
---|
429 | # $1 = 136787683
|
---|
430 | #
|
---|
431 |
|
---|
432 | if (0) {
|
---|
433 | # Change 26011: Re: A surprising segfault
|
---|
434 | # to make sure only that these obfuscated sentences will not crash.
|
---|
435 |
|
---|
436 | map chmod(+()), ('')x68;
|
---|
437 | ok(1, "extend sp in pp_chmod");
|
---|
438 |
|
---|
439 | map chown(+()), ('')x68;
|
---|
440 | ok(1, "extend sp in pp_chown");
|
---|
441 | }
|
---|
442 |
|
---|
443 | # need to remove 'tmp' if rename() in test 28 failed!
|
---|
444 | END { rmdir 'tmp1'; rmdir 'tmp'; 1 while unlink "Iofs.tmp"; }
|
---|