10 use File::Spec::Functions;
12 my $Is_MacOS = ($^O eq 'MacOS');
13 my $Is_VMSish = ($^O eq 'VMS');
15 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
17 } elsif ($^O eq 'VMS') {
24 my $has_link = $Config{d_link};
25 my $accurate_timestamps =
26 !($^O eq 'MSWin32' || $^O eq 'NetWare' ||
27 $^O eq 'dos' || $^O eq 'os2' ||
28 $^O eq 'mint' || $^O eq 'cygwin' ||
29 $^O eq 'amigaos' || $wd =~ m#$Config{afsroot}/# ||
33 if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
34 if (Win32::FsType() eq 'NTFS') {
36 $accurate_timestamps = 1;
42 # Not needed on HPFS, but needed on HPFS386 ?!
45 $needs_fh_reopen = 1 if (defined &Win32::IsWin95 && Win32::IsWin95());
47 my $skip_mode_checks =
48 $^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/;
53 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
54 `rmdir /s /q tmp 2>nul`;
57 elsif ($^O eq 'VMS') {
58 `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
59 `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
60 `create/directory [.tmp]`;
63 rmdir "tmp"; mkdir "tmp";
66 `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
69 chdir catdir(curdir(), 'tmp');
71 `/bin/rm -rf a b c x` if -x '/bin/rm';
76 skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc') || $Is_MacOS;
78 is((umask(0)&0777), 022, 'umask'),
81 open(fh,'>x') || die "Can't create x";
83 open(fh,'>a') || die "Can't create a";
86 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
90 skip("no link", 4) unless $has_link;
92 ok(link('a','b'), "link a b");
93 ok(link('b','c'), "link b c");
95 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
96 $blksize,$blocks) = stat('c');
99 skip "no nlink", 1 if $Config{dont_use_nlink};
101 is($nlink, 3, "link count of triply-linked file");
105 skip "hard links not that hard in $^O", 1 if $^O eq 'amigaos';
106 skip "no mode checks", 1 if $skip_mode_checks;
108 # if ($^O eq 'cygwin') { # new files on cygwin get rwx instead of rw-
109 # is($mode & 0777, 0777, "mode of triply-linked file");
111 is($mode & 0777, 0666, "mode of triply-linked file");
116 $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
118 is(chmod($newmode,'a'), 1, "chmod succeeding");
121 skip("no link", 7) unless $has_link;
123 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
124 $blksize,$blocks) = stat('c');
127 skip "no mode checks", 1 if $skip_mode_checks;
129 is($mode & 0777, $newmode, "chmod going through");
136 is(chmod($newmode,'c','x'), 2, "chmod two files");
138 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
139 $blksize,$blocks) = stat('c');
142 skip "no mode checks", 1 if $skip_mode_checks;
144 is($mode & 0777, $newmode, "chmod going through to c");
147 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
148 $blksize,$blocks) = stat('x');
151 skip "no mode checks", 1 if $skip_mode_checks;
153 is($mode & 0777, $newmode, "chmod going through to x");
156 is(unlink('b','x'), 2, "unlink two files");
158 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
159 $blksize,$blocks) = stat('b');
161 is($ino, undef, "ino of removed file b should be undef");
163 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
164 $blksize,$blocks) = stat('x');
166 is($ino, undef, "ino of removed file x should be undef");
169 is(rename('a','b'), 1, "rename a b");
171 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
172 $blksize,$blocks) = stat('a');
174 is($ino, undef, "ino of renamed file a should be undef");
176 $delta = $accurate_timestamps ? 1 : 2; # Granularity of time on the filesystem
178 $foo = (utime 500000000,500000000 + $delta,'b');
180 is($foo, 1, "utime");
182 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
183 $blksize,$blocks) = stat('b');
186 skip "bogus inode num", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare');
188 ok($ino, 'non-zero inode num');
192 skip "filesystem atime/mtime granularity too low", 2
193 unless $accurate_timestamps;
195 print "# atime - $atime mtime - $mtime delta - $delta\n";
196 if($atime == 500000000 && $mtime == 500000000 + $delta) {
201 if ($^O =~ /\blinux\b/i) {
202 print "# Maybe stat() cannot get the correct atime, ".
203 "as happens via NFS on linux?\n";
204 $foo = (utime 400000000,500000000 + 2*$delta,'b');
205 my ($new_atime, $new_mtime) = (stat('b'))[8,9];
206 print "# newatime - $new_atime nemtime - $new_mtime\n";
207 if ($new_atime == $atime && $new_mtime - $mtime == $delta) {
208 pass("atime - accounted for possible NFS/glibc2.2 bug on linux");
209 pass("mtime - accounted for possible NFS/glibc2.2 bug on linux");
212 fail("atime - $atime/$new_atime $mtime/$new_mtime");
213 fail("mtime - $atime/$new_atime $mtime/$new_mtime");
216 elsif ($^O eq 'VMS') {
217 # why is this 1 second off?
218 is( $atime, 500000001, 'atime' );
219 is( $mtime, 500000000 + $delta, 'mtime' );
221 elsif ($^O eq 'beos') {
222 SKIP: { skip "atime not updated", 1; }
223 is($mtime, 500000001, 'mtime');
232 is(unlink('b'), 1, "unlink b");
234 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
235 $blksize,$blocks) = stat('b');
236 is($ino, undef, "ino of unlinked file b should be undef");
239 chdir $wd || die "Can't cd back to $wd";
241 # Yet another way to look for links (perhaps those that cannot be
242 # created by perl?). Hopefully there is an ls utility in your
243 # %PATH%. N.B. that $^O is 'cygwin' on Cygwin.
246 skip "Win32/Netware specific test", 2
247 unless ($^O eq 'MSWin32') || ($^O eq 'NetWare');
248 skip "No symbolic links found to test with", 2
249 unless `ls -l perl 2>nul` =~ /^l.*->/;
251 system("cp TEST TEST$$");
252 # we have to copy because e.g. GNU grep gets huffy if we have
253 # a symlink forest to another disk (it complains about too many
254 # levels of symbolic links, even if we have only two)
255 is(symlink("TEST$$","c"), 1, "symlink");
256 $foo = `grep perl c 2>&1`;
257 ok($foo, "found perl in c");
263 open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
264 print IOFSCOM 'helloworld';
267 # TODO: pp_truncate needs to be taught about F_CHSIZE and F_FREESP,
271 # Check truncating a closed file.
272 eval { truncate "Iofs.tmp", 5; };
274 skip("no truncate - $@", 8) if $@;
276 is(-s "Iofs.tmp", 5, "truncation to five bytes");
278 truncate "Iofs.tmp", 0;
280 ok(-z "Iofs.tmp", "truncation to zero bytes");
282 #these steps are necessary to check if file is really truncated
283 #On Win95, FH is updated, but file properties aren't
284 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
285 print FH "x\n" x 200;
288 # Check truncating an open file.
289 open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
298 print FH "x\n" x 200;
299 ok(truncate(FH, 200), "fh resize to 200");
302 if ($needs_fh_reopen) {
303 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
308 skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 5);
311 is(-s "Iofs.tmp", 200, "fh resize to 200 working (filename check)");
313 ok(truncate(FH, 0), "fh resize to zero");
315 if ($needs_fh_reopen) {
316 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
319 ok(-z "Iofs.tmp", "fh resize to zero working (filename check)");
323 open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
332 print FH "x\n" x 200;
333 ok(truncate(*FH{IO}, 100), "fh resize by IO slot");
336 if ($needs_fh_reopen) {
337 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
340 is(-s "Iofs.tmp", 100, "fh resize by IO slot working");
346 # check if rename() can be used to just change case of filename
348 skip "Works in Cygwin only if check_case is set to relaxed", 1
352 open(fh,'>x') || die "Can't create x";
356 # this works on win32 only, because fs isn't casesensitive
357 ok(-e 'X', "rename working");
360 chdir $wd || die "Can't cd back to $wd";
363 # check if rename() works on directories
365 # must have delete access to rename a directory
366 `set file tmp.dir/protection=o:d`;
367 ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories") ||
368 print "# errno: $!\n";
370 ok(rename('tmp', 'tmp1'), "rename on directories");
373 ok(-d 'tmp1', "rename on directories working");
375 # need to remove 'tmp' if rename() in test 28 failed!
376 END { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; }