File: FileMember.pm

package info (click to toggle)
backuppc 2.1.1-2sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,836 kB
  • ctags: 761
  • sloc: perl: 18,966; sh: 309; makefile: 74
file content (135 lines) | stat: -rw-r--r-- 4,255 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#============================================================= -*-perl-*-
#
# BackupPC::Zip::FileMember
#
# DESCRIPTION
#
#   This library defines a BackupPC::Zip::FileMember class that subclass
#   the Archive::Zip::FileMember class.  This allows BackupPC_zipCreate
#   to create zip files by reading and uncomressing BackupPC's pool
#   files on the fly.  This avoids the need to uncompress the files
#   ahead of time and either store them in memory or on disk.
#
# AUTHOR
#   Craig Barratt  <cbarratt@users.sourceforge.net>
#   Based on Archive::Zip::FileMember, Copyright (c) 2000 Ned Konz.
#
# COPYRIGHT
#   Copyright (C) 2002-2003  Craig Barratt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#========================================================================
#
# Version 2.1.1, released 13 Mar 2005.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================

package BackupPC::Zip::FileMember;
use vars qw( @ISA );
@ISA = qw ( Archive::Zip::FileMember );

BEGIN { use Archive::Zip qw( :CONSTANTS :ERROR_CODES :UTILITY_METHODS ) }

# Given a file name, set up for eventual writing.
sub newFromFileNamed    # BackupPC::Zip::FileMember
{
    my $class    = shift;
    my $fileName = shift;
    my $newName  = shift || $fileName;
    my $size     = shift;
    my $compress = shift;
    return undef unless ( stat($fileName) && -r _ && !-d _ );
    my $self = $class->new(@_);
    $self->fileName($newName);
    $self->{'externalFileName'}  = $fileName;
    $self->{'compressionMethod'} = COMPRESSION_STORED;
    $self->{'compressedSize'} = $self->{'uncompressedSize'} = $size;
    $self->{'fileCompressLevel'} = $compress;
    $self->desiredCompressionMethod( ( $self->compressedSize() > 0 ) 
	    ? COMPRESSION_DEFLATED
	    : COMPRESSION_STORED );
    $self->isTextFile( -T _ );
    return $self;
}

sub rewindData		# BackupPC::Zip::FileMember
{
    my $self = shift;

    my $status = $self->SUPER::rewindData(@_);
    return $status unless $status == AZ_OK;

    return AZ_IO_ERROR unless $self->fh();
    $self->fh()->rewind();
    return AZ_OK;
}

sub fh			# BackupPC::Zip::FileMember
{
    my $self = shift;
    $self->_openFile() if !defined( $self->{'bpcfh'} );
    return $self->{'bpcfh'};
}

# opens my file handle from my file name
sub _openFile		# BackupPC::Zip::FileMember
{
    my $self = shift;
    my ( $fh ) = BackupPC::FileZIO->open($self->externalFileName(), 0,
					 $self->{'fileCompressLevel'});
    if ( !defined($fh) )
    {
        _ioError( "Can't open", $self->externalFileName() );
        return undef;
    }
    $self->{'bpcfh'} = $fh;
    return $fh;
}

# Closes my file handle
sub _closeFile		# BackupPC::Zip::FileMember
{
    my $self = shift;
    $self->{'bpcfh'}->close() if ( defined($self->{'bpcfh'}) );
    $self->{'bpcfh'} = undef;
}

# Make sure I close my file handle
sub endRead		# BackupPC::Zip::FileMember
{
    my $self = shift;
    $self->_closeFile();
    return $self->SUPER::endRead(@_);
}

# Return bytes read. Note that first parameter is a ref to a buffer.
# my $data;
# my ($bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
sub _readRawChunk	# BackupPC::Zip::FileMember
{
    my ( $self, $dataRef, $chunkSize ) = @_;
    return ( 0, AZ_OK ) unless $chunkSize;
    my $bytesRead = $self->fh()->read( $dataRef, $chunkSize )
	    or return ( 0, _ioError("reading data") );
    return ( $bytesRead, AZ_OK );
}

sub extractToFileNamed	# BackupPC::Zip::FileMember
{
    die("BackupPC::Zip::FileMember::extractToFileNamed not supported\n");
}