summaryrefslogtreecommitdiff
path: root/fml/lib/IO/t/file_map_getpos.pl
blob: e39b57575fc360a8353804615571e94258ff67f9 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#-*- perl -*-
#
#  Copyright (C) 2001 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself. 
#
# $FML: file_map_getpos.pl,v 1.5 2001/05/04 14:32:34 fukachan Exp $
#

use strict;
use Carp;

my $debug = 0;
my $file  = "/etc/passwd";
my $map   = "file:". $file;

print STDERR "roll back test\n" if $debug;

use IO::Adapter;
my $obj = new IO::Adapter $map;
$obj->open || croak("cannot open $map");
if ($obj->error) { croak( $obj->error );}

my $pobot = 0;
my $done  = 0;
my $i     = 0;
my $pebot = 0;
my ($x, $prev_buf, $buf);

while ($x = $obj->getline) {
    $i++;
    if ($i == 4 || $i == 7) {
	print STDERR "      > ", $x if $debug;
	unless ($prev_buf) {
	    $prev_buf = $x;
	}
	$buf = $x;
    }

    if ($i == 3) {
	$pebot = $obj->getpos;
	print STDERR "     * roll back here\n" if $debug;
    }

    my $pos = $obj->getpos;
    unless ($done) {
	if ($i == 6) {
	    print STDERR "   now> ", $x if $debug;;
	    print STDERR "     * try to roll back ... \n" if $debug;;
	    $obj->setpos( $pebot );
	    $done = 1;
	} 
    }
}
$obj->close;


if ($prev_buf eq $buf) {
    print STDERR "$map roll back test ... ok\n";
    exit 0;
}
else {
    exit 1;
}

exit 0;