line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Attributes.pm,v 1.5 2001/05/16 01:38:01 btrott Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::SFTP::Attributes; |
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Net::SFTP::Constants qw( :att ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
7
|
2
|
|
|
2
|
|
1923
|
use Net::SFTP::Buffer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use vars qw( @FIELDS ); |
10
|
|
|
|
|
|
|
@FIELDS = qw( flags size uid gid perm atime mtime ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
for my $f (@FIELDS) { |
13
|
|
|
|
|
|
|
no strict 'refs'; |
14
|
|
|
|
|
|
|
*$f = sub { |
15
|
|
|
|
|
|
|
my $a = shift; |
16
|
|
|
|
|
|
|
$a->{$f} = shift if @_; |
17
|
|
|
|
|
|
|
$a->{$f}; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
my $class = shift; |
23
|
|
|
|
|
|
|
my $a = bless { }, $class; |
24
|
|
|
|
|
|
|
$a->init(@_); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init { |
28
|
|
|
|
|
|
|
my $a = shift; |
29
|
|
|
|
|
|
|
my %param = @_; |
30
|
|
|
|
|
|
|
for my $f (@FIELDS) { |
31
|
|
|
|
|
|
|
$a->{$f} = 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
if (my $stat = $param{Stat}) { |
34
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_SIZE; |
35
|
|
|
|
|
|
|
$a->{size} = $stat->[7]; |
36
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_UIDGID; |
37
|
|
|
|
|
|
|
$a->{uid} = $stat->[4]; |
38
|
|
|
|
|
|
|
$a->{gid} = $stat->[5]; |
39
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
40
|
|
|
|
|
|
|
$a->{perm} = $stat->[2]; |
41
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_ACMODTIME; |
42
|
|
|
|
|
|
|
$a->{atime} = $stat->[8]; |
43
|
|
|
|
|
|
|
$a->{mtime} = $stat->[9]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (my $buf = $param{Buffer}) { |
46
|
|
|
|
|
|
|
$a->{flags} = $buf->get_int32; |
47
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) { |
48
|
|
|
|
|
|
|
$a->{size} = $buf->get_int64; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) { |
51
|
|
|
|
|
|
|
$a->{uid} = $buf->get_int32; |
52
|
|
|
|
|
|
|
$a->{gid} = $buf->get_int32; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
55
|
|
|
|
|
|
|
$a->{perm} = $buf->get_int32; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) { |
58
|
|
|
|
|
|
|
$a->{atime} = $buf->get_int32; |
59
|
|
|
|
|
|
|
$a->{mtime} = $buf->get_int32; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
$a; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub as_buffer { |
66
|
|
|
|
|
|
|
my $a = shift; |
67
|
|
|
|
|
|
|
my $buf = Net::SFTP::Buffer->new; |
68
|
|
|
|
|
|
|
$buf->put_int32($a->{flags}); |
69
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) { |
70
|
|
|
|
|
|
|
$buf->put_int64(int $a->{size}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) { |
73
|
|
|
|
|
|
|
$buf->put_int32($a->{uid}); |
74
|
|
|
|
|
|
|
$buf->put_int32($a->{gid}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
77
|
|
|
|
|
|
|
$buf->put_int32($a->{perm}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) { |
80
|
|
|
|
|
|
|
$buf->put_int32($a->{atime}); |
81
|
|
|
|
|
|
|
$buf->put_int32($a->{mtime}); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
$buf; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |