File: 01_fsync.t

package info (click to toggle)
libfile-sync-perl 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 92 kB
  • sloc: perl: 118; makefile: 2
file content (35 lines) | stat: -rwxr-xr-x 965 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! ./perl

######################### We start with some black magic to print on failure.

BEGIN { $| = 1; print "1..5\n"; }
END {print "not ok 1\n" unless $loaded;}
use File::Sync qw(fsync);
use FileHandle;
$loaded = 1;
print "ok 1\n";

######################### End of black magic.

# Open a file for testing, unlink it in case we crash.
open TEST, "> /tmp/test.pl.$$" 
  or die "couldn't create temp. file - please try again";
unlink "/tmp/test.pl.$$";

# Try fsync, with glob ref then glob name.
fsync(\*TEST) || print 'not '; print "ok 2\n";
fsync(TEST) || print 'not '; print "ok 3\n";

# Try fsync_fd on fd of TEST.
$fd = fileno(TEST);
File::Sync::fsync_fd($fd) || print 'not '; print "ok 4\n";

close TEST;

# Open file as FileHandle and unlink it.
$fh = new FileHandle "> /tmp/test.pl.$$"
  or die "couldn't create temp. file - please try again";
unlink "/tmp/test.pl.$$";

# Try fsync as method of FileHandle.
$fh->fsync() || print 'not '; print "ok 5\n";