line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DataStore::CAS::FS::Importer; |
2
|
2
|
|
|
2
|
|
5843
|
use 5.008; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
84
|
|
3
|
2
|
|
|
2
|
|
1056
|
use Moo; |
|
2
|
|
|
|
|
25620
|
|
|
2
|
|
|
|
|
16
|
|
4
|
2
|
|
|
2
|
|
2238
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
150
|
|
5
|
2
|
|
|
2
|
|
855
|
use Try::Tiny; |
|
2
|
|
|
|
|
1955
|
|
|
2
|
|
|
|
|
169
|
|
6
|
2
|
|
|
2
|
|
2017
|
use File::Spec::Functions 'catfile', 'catdir', 'splitpath', 'catpath'; |
|
2
|
|
|
|
|
1704
|
|
|
2
|
|
|
|
|
265
|
|
7
|
2
|
|
|
2
|
|
12
|
use Fcntl; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
801
|
|
8
|
2
|
|
|
2
|
|
742
|
use DataStore::CAS::FS::InvalidUTF8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
52
|
|
9
|
2
|
|
|
2
|
|
634
|
use DataStore::CAS::FS::DirCodec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
257
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION= '0.011000'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Copy files from filesystem into DataStore::CAS::FS. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our %_flag_defaults; |
17
|
|
|
|
|
|
|
BEGIN { |
18
|
2
|
|
|
2
|
|
49
|
%_flag_defaults= ( |
19
|
|
|
|
|
|
|
die_on_dir_error => 1, |
20
|
|
|
|
|
|
|
die_on_file_error => 1, |
21
|
|
|
|
|
|
|
die_on_hint_error => 0, |
22
|
|
|
|
|
|
|
die_on_metadata_error => 0, |
23
|
|
|
|
|
|
|
collect_metadata_ts => 1, |
24
|
|
|
|
|
|
|
collect_access_ts => 0, |
25
|
|
|
|
|
|
|
collect_unix_perm => 1, |
26
|
|
|
|
|
|
|
collect_unix_misc => 0, |
27
|
|
|
|
|
|
|
collect_acl => 0, |
28
|
|
|
|
|
|
|
collect_ext_attr => 0, |
29
|
|
|
|
|
|
|
follow_symlink => 0, |
30
|
|
|
|
|
|
|
cross_mountpoints => 0, |
31
|
|
|
|
|
|
|
reuse_digests => 1, |
32
|
|
|
|
|
|
|
utf8_filenames => 1, |
33
|
|
|
|
|
|
|
); |
34
|
2
|
|
|
|
|
11
|
for (keys %_flag_defaults) { |
35
|
28
|
50
|
|
0
|
1
|
2747
|
eval "sub $_ { \$_[0]{flags}{$_}= \$_[1] if \@_ > 1; \$_[0]{flags}{$_} }; 1" or die $@ |
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
3
|
1
|
0
|
|
|
0
|
50
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
1
|
0
|
|
|
0
|
0
|
|
0
|
0
|
0
|
|
|
0
|
0
|
|
8
|
1
|
0
|
|
|
0
|
50
|
|
3
|
1
|
0
|
|
|
3
|
50
|
|
9
|
1
|
11
|
|
|
3
|
50
|
|
|
|
91
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
134
|
|
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
11
|
|
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
46
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
sub _flag_defaults { |
39
|
2
|
|
|
2
|
|
7
|
\%_flag_defaults; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has dir_format => ( is => 'rw', default => sub { 'universal' } ); |
43
|
|
|
|
|
|
|
has filter => ( is => 'rw' ); |
44
|
|
|
|
|
|
|
has flags => ( is => 'rw', default => sub { { } } ); |
45
|
|
|
|
|
|
|
has unix_uid_cache => ( is => 'rw', default => sub { {} } ); |
46
|
|
|
|
|
|
|
has unix_gid_cache => ( is => 'rw', default => sub { {} } ); |
47
|
|
|
|
|
|
|
has _hint_check_fn => ( is => 'rwp' ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _handle_hint_error { |
50
|
0
|
0
|
|
0
|
|
0
|
croak $_[1] if $_[0]->die_on_hint_error; |
51
|
0
|
|
|
|
|
0
|
warn "$_[1]\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _handle_file_error { |
55
|
0
|
0
|
|
0
|
|
0
|
croak $_[1] if $_[0]->die_on_file_error; |
56
|
0
|
|
|
|
|
0
|
warn "$_[1]\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _handle_dir_error { |
60
|
0
|
0
|
|
0
|
|
0
|
croak $_[1] if $_[0]->die_on_dir_error; |
61
|
0
|
|
|
|
|
0
|
warn "$_[1]\n"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _handle_metadata_error { |
65
|
0
|
0
|
|
0
|
|
0
|
croak $_[1] if $_[0]->die_on_metadata_error; |
66
|
0
|
|
|
|
|
0
|
warn "$_[1]\n"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub BUILD { |
71
|
2
|
|
|
2
|
0
|
18
|
my ($self, $args)= @_; |
72
|
2
|
|
|
|
|
19
|
my $flags= $self->flags; |
73
|
2
|
|
|
|
|
10
|
my $defaults= $self->_flag_defaults; |
74
|
2
|
|
|
|
|
15
|
for (keys %$defaults) { |
75
|
28
|
50
|
|
|
|
64
|
$flags->{$_}= delete $args->{$_} |
76
|
|
|
|
|
|
|
if exists $args->{$_}; |
77
|
28
|
50
|
|
|
|
124
|
$flags->{$_}= $_flag_defaults{$_} |
78
|
|
|
|
|
|
|
unless defined $flags->{$_}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
defined $defaults->{$_} || croak "Unknown flag: '$_'" |
81
|
2
|
|
33
|
|
|
54
|
for keys %$flags; |
82
|
|
|
|
|
|
|
$self->can($_) || croak "Unknown attribute: '$_'" |
83
|
2
|
|
0
|
|
|
63
|
for keys %$args; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# locally-scoped to the device number which we should stay on |
87
|
|
|
|
|
|
|
our $_DEVICE_CONSTRAINT; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub import_tree { |
91
|
1
|
|
|
1
|
1
|
3
|
my ($self, $src, $dest)= @_; |
92
|
|
|
|
|
|
|
|
93
|
1
|
50
|
|
|
|
3
|
my $stat= $self->_stat($src) |
94
|
|
|
|
|
|
|
or croak "Source does not exist"; |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
33
|
|
|
41
|
local $_DEVICE_CONSTRAINT= $stat->dev |
97
|
|
|
|
|
|
|
unless defined $_DEVICE_CONSTRAINT or $self->cross_mountpoints; |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
5
|
$self->_build__hint_check_fn; |
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
6
|
my $ent_name= $self->_entname_from_path($src); |
102
|
1
|
|
|
|
|
7
|
my $ent= $self->_import_directory_entry($dest->filesystem->store, $src, $ent_name, $stat, $dest); |
103
|
1
|
|
|
|
|
5
|
$dest->filesystem->set_path($dest->path_names, $ent); |
104
|
1
|
|
|
|
|
11
|
1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub import_directory { |
109
|
1
|
|
|
1
|
1
|
1021
|
my ($self, $cas, $path, $hint)= @_; |
110
|
|
|
|
|
|
|
|
111
|
1
|
50
|
|
|
|
5
|
my $stat= $self->_stat($path) |
112
|
|
|
|
|
|
|
or croak "Source does not exist"; |
113
|
|
|
|
|
|
|
|
114
|
1
|
50
|
33
|
|
|
39
|
local $_DEVICE_CONSTRAINT= $stat->dev |
115
|
|
|
|
|
|
|
unless defined $_DEVICE_CONSTRAINT or $self->cross_mountpoints; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
4
|
$self->_build__hint_check_fn; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
6
|
$self->_import_directory($cas, $path, $hint); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _import_directory { |
123
|
2
|
|
|
2
|
|
6
|
my ($self, $cas, $path, $hint)= @_; |
124
|
2
|
50
|
|
|
|
5
|
my $names= $self->_readdir($path) |
125
|
|
|
|
|
|
|
or return undef; |
126
|
2
|
|
|
|
|
5
|
my @entries; |
127
|
2
|
|
|
|
|
7
|
my $filter= $self->filter; |
128
|
2
|
|
|
|
|
5
|
for my $ent_name (@$names) { |
129
|
4
|
|
|
|
|
33
|
my $ent_path= catfile($path, $ent_name); |
130
|
4
|
|
|
|
|
105
|
my $stat= $self->_stat($ent_path); |
131
|
|
|
|
|
|
|
|
132
|
4
|
50
|
|
|
|
138
|
if ($self->utf8_filenames) { |
133
|
4
|
|
|
|
|
35
|
$ent_name= DataStore::CAS::FS::InvalidUTF8->decode_utf8($ent_name); |
134
|
|
|
|
|
|
|
} else { |
135
|
0
|
|
|
|
|
0
|
utf8::upgrade($ent_name); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
4
|
50
|
|
|
|
13
|
my $keep= $filter? $filter->($ent_name, $ent_path, $stat) : 1; |
139
|
4
|
50
|
|
|
|
13
|
next unless $keep; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Check for crossing mount point. |
142
|
4
|
50
|
33
|
|
|
19
|
if (defined $_DEVICE_CONSTRAINT && $stat->dev ne $_DEVICE_CONSTRAINT) { |
|
|
50
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# TODO: log skipped mount points |
144
|
|
|
|
|
|
|
# Metadata comes from mounted filesystem, so ignore it |
145
|
0
|
|
|
|
|
0
|
push @entries, { type => 'dir', name => $ent_name }; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
# If keep is < 0, store the metadata but not the file/dir |
148
|
|
|
|
|
|
|
elsif ($keep < 0) { |
149
|
0
|
|
|
|
|
0
|
push @entries, $self->collect_dirent_metadata($ent_path, $ent_name, $stat); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
# Else recursively store the whole thing |
152
|
|
|
|
|
|
|
else { |
153
|
4
|
|
|
|
|
19
|
push @entries, $self->_import_directory_entry($cas, $ent_path, $ent_name, $stat, $hint); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
2
|
|
|
|
|
26
|
return DataStore::CAS::FS::DirCodec->put($cas, $self->dir_format, \@entries, {} ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub import_directory_entry { |
161
|
1
|
|
|
1
|
1
|
129
|
my ($self, $cas, $path, $ent_name, $stat, $hint)= @_; |
162
|
|
|
|
|
|
|
|
163
|
1
|
50
|
33
|
|
|
8
|
$stat||= $self->_stat($path) |
164
|
|
|
|
|
|
|
or croak "Source does not exist"; |
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
6
|
$self->_build__hint_check_fn; |
167
|
|
|
|
|
|
|
|
168
|
1
|
50
|
33
|
|
|
38
|
local $_DEVICE_CONSTRAINT= $stat->dev |
169
|
|
|
|
|
|
|
unless defined $_DEVICE_CONSTRAINT or $self->cross_mountpoints; |
170
|
|
|
|
|
|
|
|
171
|
1
|
50
|
|
|
|
8
|
$ent_name= $self->_entname_from_path($path) |
172
|
|
|
|
|
|
|
unless defined $ent_name; |
173
|
1
|
|
|
|
|
6
|
return DataStore::CAS::FS::DirEnt->new( |
174
|
|
|
|
|
|
|
$self->_import_directory_entry($cas, $path, $ent_name, $stat, $hint) |
175
|
|
|
|
|
|
|
); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _import_directory_entry { |
179
|
6
|
|
|
6
|
|
17
|
my ($self, $cas, $ent_path, $ent_name, $stat, $hint)= @_; |
180
|
6
|
50
|
|
|
|
21
|
my $attrs= $self->collect_dirent_metadata($ent_path, $ent_name, $stat) |
181
|
|
|
|
|
|
|
or croak "Path does not exist: '$ent_path'"; |
182
|
6
|
100
|
|
|
|
29
|
if ($attrs->{type} eq 'file') { |
|
|
50
|
|
|
|
|
|
183
|
5
|
50
|
33
|
|
|
19
|
if ($hint && $self->_can_reuse_hash($attrs, $hint)) { |
184
|
0
|
|
|
|
|
0
|
$attrs->{ref}= $hint->ref; |
185
|
|
|
|
|
|
|
} else { |
186
|
5
|
|
|
|
|
9
|
my $err; |
187
|
5
|
|
|
5
|
|
45
|
$attrs->{ref}= try { $cas->put_file($ent_path); } catch { $err= $_; undef; }; |
|
5
|
|
|
|
|
210
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
188
|
5
|
50
|
|
|
|
1567
|
$self->_handle_file_error("Error while importing file '$ent_path': $err") |
189
|
|
|
|
|
|
|
if defined $err; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
elsif ($attrs->{type} eq 'dir') { |
193
|
1
|
50
|
33
|
|
|
8
|
if (defined $_DEVICE_CONSTRAINT && $stat->dev ne $_DEVICE_CONSTRAINT) { |
194
|
|
|
|
|
|
|
# TODO: log skipped mount points |
195
|
|
|
|
|
|
|
} else { |
196
|
1
|
50
|
33
|
|
|
11
|
local $_DEVICE_CONSTRAINT= $stat->dev |
197
|
|
|
|
|
|
|
unless defined $_DEVICE_CONSTRAINT || $self->cross_mountpoints; |
198
|
|
|
|
|
|
|
|
199
|
1
|
|
|
|
|
9
|
my $subdir_hint; |
200
|
1
|
50
|
|
|
|
4
|
if (defined $hint) { |
201
|
1
|
|
|
|
|
3
|
my $err; |
202
|
|
|
|
|
|
|
try { |
203
|
1
|
|
|
1
|
|
39
|
$subdir_hint= $hint->path_if_exists($attrs->{name}); |
204
|
1
|
50
|
|
|
|
7
|
$subdir_hint->resolve |
205
|
|
|
|
|
|
|
if $subdir_hint; |
206
|
|
|
|
|
|
|
} catch { |
207
|
0
|
|
|
0
|
|
0
|
$err= $_; |
208
|
1
|
|
|
|
|
10
|
}; |
209
|
1
|
50
|
|
|
|
19
|
$self->_handle_hint_error("Error while loading virtual path '".$hint->resolved_canonical_path.'/'.$attrs->{name}."': $err") |
210
|
|
|
|
|
|
|
if defined $err; |
211
|
|
|
|
|
|
|
} |
212
|
1
|
|
|
|
|
5
|
$attrs->{ref}= $self->_import_directory($cas, $ent_path, $subdir_hint); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
6
|
|
|
|
|
116
|
return $attrs; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
our %_ModeToType; |
220
|
|
|
|
|
|
|
# Making this a function allows other code to call it in a BEGIN block if needed |
221
|
|
|
|
|
|
|
sub _build_ModeToType { |
222
|
2
|
|
|
2
|
|
4
|
local $@; |
223
|
2
|
|
|
|
|
5
|
eval { $_ModeToType{Fcntl::S_IFREG()}= 'file' }; |
|
2
|
|
|
|
|
7
|
|
224
|
2
|
|
|
|
|
5
|
eval { $_ModeToType{Fcntl::S_IFDIR()}= 'dir' }; |
|
2
|
|
|
|
|
6
|
|
225
|
2
|
|
|
|
|
4
|
eval { $_ModeToType{Fcntl::S_IFLNK()}= 'symlink' }; |
|
2
|
|
|
|
|
5
|
|
226
|
2
|
|
|
|
|
3
|
eval { $_ModeToType{Fcntl::S_IFBLK()}= 'blockdev' }; |
|
2
|
|
|
|
|
6
|
|
227
|
2
|
|
|
|
|
3
|
eval { $_ModeToType{Fcntl::S_IFCHR()}= 'chardev' }; |
|
2
|
|
|
|
|
25
|
|
228
|
2
|
|
|
|
|
5
|
eval { $_ModeToType{Fcntl::S_IFIFO()}= 'pipe' }; |
|
2
|
|
|
|
|
5
|
|
229
|
2
|
|
|
|
|
3
|
eval { $_ModeToType{Fcntl::S_IFWHT()}= 'whiteout' }; |
|
2
|
|
|
|
|
49
|
|
230
|
2
|
|
|
|
|
7
|
eval { $_ModeToType{Fcntl::S_IFSOCK()}= 'socket' }; |
|
2
|
|
|
|
|
7
|
|
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
_build_ModeToType(); |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub collect_dirent_metadata { |
236
|
7
|
|
|
7
|
1
|
184
|
my ($self, $path, $ent_name, $stat)= @_; |
237
|
|
|
|
|
|
|
|
238
|
7
|
50
|
66
|
|
|
33
|
$stat ||= $self->_stat($path) |
239
|
|
|
|
|
|
|
or return undef; |
240
|
|
|
|
|
|
|
|
241
|
7
|
100
|
|
|
|
26
|
$ent_name= $self->_entname_from_path($path) |
242
|
|
|
|
|
|
|
unless defined $ent_name; |
243
|
|
|
|
|
|
|
|
244
|
7
|
|
|
|
|
66
|
my %attrs= ( |
245
|
|
|
|
|
|
|
type => ($_ModeToType{$stat->[2] & Fcntl::S_IFMT()}), |
246
|
|
|
|
|
|
|
name => $ent_name, |
247
|
|
|
|
|
|
|
size => $stat->[7], |
248
|
|
|
|
|
|
|
modify_ts => $stat->[9], |
249
|
|
|
|
|
|
|
); |
250
|
7
|
50
|
|
|
|
29
|
if (!defined $attrs{type}) { |
251
|
0
|
|
|
|
|
0
|
$self->_handle_dir_error("Type of dirent is unknown: ".($stat->[2] & Fcntl::S_IFMT())); |
252
|
0
|
|
|
|
|
0
|
$attrs{type}= 'file'; |
253
|
|
|
|
|
|
|
} |
254
|
7
|
50
|
|
|
|
24
|
if ($self->{flags}{collect_unix_perm}) { |
255
|
7
|
|
|
|
|
26
|
$attrs{unix_mode}= ($stat->[2] & ~Fcntl::S_IFMT()); |
256
|
7
|
|
|
|
|
19
|
my $uid= $attrs{unix_uid}= $stat->[4]; |
257
|
7
|
50
|
|
|
|
30
|
if (my $cache= $self->unix_uid_cache) { |
258
|
7
|
100
|
|
|
|
30
|
if (!exists $cache->{$uid}) { |
259
|
1
|
|
|
|
|
996
|
my $name= getpwuid($uid); |
260
|
1
|
50
|
|
|
|
52
|
if (!defined $name) { |
|
|
50
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
$self->_handle_metadata_error("No username for UID $uid"); |
262
|
|
|
|
|
|
|
} elsif ($self->utf8_filenames) { |
263
|
1
|
|
|
|
|
6
|
$name= DataStore::CAS::FS::InvalidUTF8->decode_utf8($name); |
264
|
|
|
|
|
|
|
} else { |
265
|
0
|
|
|
|
|
0
|
utf8::upgrade($name); |
266
|
|
|
|
|
|
|
} |
267
|
1
|
|
|
|
|
4
|
$cache->{$uid}= $name; |
268
|
|
|
|
|
|
|
} |
269
|
7
|
50
|
|
|
|
32
|
$attrs{unix_user}= $cache->{$uid} |
270
|
|
|
|
|
|
|
if defined $cache->{$uid}; |
271
|
|
|
|
|
|
|
} |
272
|
7
|
|
|
|
|
23
|
my $gid= $attrs{unix_gid}= $stat->[5]; |
273
|
7
|
50
|
|
|
|
30
|
if (my $cache= $self->unix_gid_cache) { |
274
|
7
|
100
|
|
|
|
22
|
if (!exists $cache->{$gid}) { |
275
|
1
|
|
|
|
|
210
|
my $name= getgrgid($gid); |
276
|
1
|
50
|
|
|
|
50
|
if (!defined $name) { |
|
|
50
|
|
|
|
|
|
277
|
0
|
|
|
|
|
0
|
$self->_handle_metadata_error("No groupname for GID $gid"); |
278
|
|
|
|
|
|
|
} elsif ($self->utf8_filenames) { |
279
|
1
|
|
|
|
|
7
|
$name= DataStore::CAS::FS::InvalidUTF8->decode_utf8($name); |
280
|
|
|
|
|
|
|
} else { |
281
|
0
|
|
|
|
|
0
|
utf8::upgrade($name); |
282
|
|
|
|
|
|
|
} |
283
|
1
|
|
|
|
|
5
|
$cache->{$gid}= $name; |
284
|
|
|
|
|
|
|
} |
285
|
7
|
50
|
|
|
|
37
|
$attrs{unix_group}= $cache->{$gid} |
286
|
|
|
|
|
|
|
if defined $cache->{$gid}; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
} |
289
|
7
|
50
|
|
|
|
23
|
if ($self->{flags}{collect_metadata_ts}) { |
290
|
7
|
|
|
|
|
18
|
$attrs{metadata_ts}= $stat->[10]; |
291
|
|
|
|
|
|
|
} |
292
|
7
|
50
|
|
|
|
40
|
if ($self->{flags}{collect_access_ts}) { |
293
|
0
|
|
|
|
|
0
|
$attrs{access_ts}= $stat->[8]; |
294
|
|
|
|
|
|
|
} |
295
|
7
|
50
|
|
|
|
21
|
if ($self->{flags}{collect_unix_misc}) { |
296
|
0
|
|
|
|
|
0
|
$attrs{unix_dev}= $stat->[0]; |
297
|
0
|
|
|
|
|
0
|
$attrs{unix_inode}= $stat->[1]; |
298
|
0
|
|
|
|
|
0
|
$attrs{unix_nlink}= $stat->[3]; |
299
|
0
|
|
|
|
|
0
|
$attrs{unix_blocksize}= $stat->[11]; |
300
|
0
|
|
|
|
|
0
|
$attrs{unix_blockcount}= $stat->[12]; |
301
|
|
|
|
|
|
|
} |
302
|
7
|
50
|
|
|
|
23
|
if ($self->{flags}{collect_acl}) { |
303
|
|
|
|
|
|
|
# TODO |
304
|
|
|
|
|
|
|
} |
305
|
7
|
50
|
|
|
|
17
|
if ($self->{flags}{collect_ext_attr}) { |
306
|
|
|
|
|
|
|
# TODO |
307
|
|
|
|
|
|
|
} |
308
|
7
|
100
|
33
|
|
|
61
|
if ($attrs{type} eq 'dir') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
309
|
1
|
|
|
|
|
3
|
delete $attrs{size}; |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
elsif ($attrs{type} eq 'symlink') { |
312
|
0
|
|
|
|
|
0
|
$attrs{ref}= readlink $path; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
elsif ($attrs{type} eq 'blockdev' or $attrs{type} eq 'chardev') { |
315
|
0
|
|
|
|
|
0
|
$attrs{ref}= $self->_split_dev_node($stat->[6]); |
316
|
|
|
|
|
|
|
} |
317
|
7
|
|
|
|
|
53
|
\%attrs; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub _build__hint_check_fn { |
321
|
3
|
|
|
3
|
|
6
|
my $self= shift; |
322
|
3
|
|
|
|
|
103
|
my $reuse= $self->reuse_digests; |
323
|
3
|
0
|
|
|
|
19
|
return $self->{_hint_check_fn}= $reuse > 1? |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
324
|
|
|
|
|
|
|
($reuse > 2? \&_hint_check_ctime : \&_hint_check_mtime) |
325
|
|
|
|
|
|
|
: ($reuse > 0? \&_hint_check_size : \&_hint_check_none); |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub _hint_check_none { |
329
|
0
|
|
|
0
|
|
0
|
return undef; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
sub _hint_check_size { |
332
|
0
|
|
|
0
|
|
0
|
my ($self, $attrs, $hint)= @_; |
333
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $hint && defined $hint->ref; |
334
|
0
|
|
|
|
|
0
|
my ($size, $h_size)= ($attrs->{size}, $hint->size); |
335
|
0
|
|
0
|
|
|
0
|
return defined $size && defined $h_size && $size eq $h_size; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
sub _hint_check_mtime { |
338
|
0
|
|
|
0
|
|
0
|
my ($self, $attrs, $hint)= @_; |
339
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $hint && defined $hint->ref; |
340
|
0
|
|
|
|
|
0
|
my ($size, $h_size)= ($attrs->{size}, $hint->size); |
341
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $size && defined $h_size && $size eq $h_size; |
|
|
|
0
|
|
|
|
|
342
|
0
|
|
|
|
|
0
|
my ($modify_ts, $h_modify_ts)= ($attrs->{modify_ts}, $hint->modify_ts); |
343
|
0
|
|
0
|
|
|
0
|
return defined $modify_ts && defined $h_modify_ts && $modify_ts eq $h_modify_ts; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
sub _hint_check_ctime { |
346
|
0
|
|
|
0
|
|
0
|
my ($self, $attrs, $hint)= @_; |
347
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $hint && defined $hint->ref; |
348
|
0
|
|
|
|
|
0
|
my ($size, $h_size)= ($attrs->{size}, $hint->size); |
349
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $size && defined $h_size && $size eq $h_size; |
|
|
|
0
|
|
|
|
|
350
|
0
|
|
|
|
|
0
|
my ($modify_ts, $h_modify_ts)= ($attrs->{metadata_ts}, $hint->metadata_ts); |
351
|
0
|
|
0
|
|
|
0
|
return defined $modify_ts && defined $h_modify_ts && $modify_ts eq $h_modify_ts; |
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
sub _entname_from_path { |
355
|
3
|
|
|
3
|
|
6
|
my ($self, $path)= @_; |
356
|
3
|
|
|
|
|
16
|
my (undef, undef, $ent_name)= splitpath($path); |
357
|
3
|
50
|
|
|
|
230
|
if ($self->utf8_filenames) { |
358
|
3
|
|
|
|
|
29
|
$ent_name= DataStore::CAS::FS::InvalidUTF8->decode_utf8($ent_name); |
359
|
|
|
|
|
|
|
} else { |
360
|
0
|
|
|
|
|
0
|
utf8::upgrade($ent_name); |
361
|
|
|
|
|
|
|
} |
362
|
3
|
|
|
|
|
7
|
$ent_name; |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub _split_dev_node { |
366
|
0
|
|
|
0
|
|
0
|
($_[1] >> 8).','.($_[1] & 0xFF); |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
sub _stat { |
370
|
0
|
|
|
0
|
|
0
|
my $fn= \&_stat_unix; |
371
|
2
|
|
|
2
|
|
17
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
397
|
|
372
|
0
|
|
|
|
|
0
|
*_stat= $fn; |
373
|
0
|
|
|
|
|
0
|
goto $fn; |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
sub _stat_unix { |
377
|
8
|
|
|
8
|
|
15
|
my ($self, $path)= @_; |
378
|
8
|
50
|
|
|
|
441
|
my @stat= $self->follow_symlink? stat($path) : lstat($path); |
379
|
8
|
50
|
|
|
|
227
|
unless (@stat) { |
380
|
0
|
|
|
|
|
0
|
$self->_handle_dir_error("Can't stat '$path': $!"); |
381
|
0
|
|
|
|
|
0
|
return undef; |
382
|
|
|
|
|
|
|
} |
383
|
8
|
|
|
|
|
60
|
bless \@stat, 'DataStore::CAS::FS::Importer::FastStat'; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
sub _readdir { |
387
|
0
|
|
|
0
|
|
0
|
my $fn= \&_readdir_unix; |
388
|
2
|
|
|
2
|
|
12
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
460
|
|
389
|
0
|
|
|
|
|
0
|
*_readdir= $fn; |
390
|
0
|
|
|
|
|
0
|
goto $fn; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
sub _readdir_unix { |
394
|
2
|
|
|
2
|
|
5
|
my ($self, $path)= @_; |
395
|
2
|
|
|
|
|
4
|
my $dh; |
396
|
2
|
50
|
|
|
|
12
|
if (!opendir($dh, $path)) { |
397
|
0
|
|
|
|
|
0
|
$self->_handle_dir_error("opendir($path): $!"); |
398
|
0
|
|
|
|
|
0
|
return undef; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
2
|
100
|
|
|
|
157
|
my @names= grep { $_ ne '.' && $_ ne '..' } readdir($dh); |
|
8
|
|
|
|
|
65
|
|
402
|
|
|
|
|
|
|
|
403
|
2
|
50
|
|
|
|
32
|
if (!closedir $dh) { |
404
|
0
|
|
|
|
|
0
|
$self->_handle_dir_error("closedir($path): $!"); |
405
|
0
|
|
|
|
|
0
|
return undef; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
|
408
|
2
|
|
|
|
|
13
|
\@names; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
package DataStore::CAS::FS::Importer::FastStat; |
412
|
2
|
|
|
2
|
|
21
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
413
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
599
|
|
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
|
416
|
8
|
|
|
8
|
|
39
|
sub dev { $_[0][0] } |
417
|
0
|
|
|
0
|
|
|
sub ino { $_[0][1] } |
418
|
0
|
|
|
0
|
|
|
sub mode { $_[0][2] } |
419
|
0
|
|
|
0
|
|
|
sub nlink { $_[0][3] } |
420
|
0
|
|
|
0
|
|
|
sub uid { $_[0][4] } |
421
|
0
|
|
|
0
|
|
|
sub gid { $_[0][5] } |
422
|
0
|
|
|
0
|
|
|
sub rdev { $_[0][6] } |
423
|
0
|
|
|
0
|
|
|
sub size { $_[0][7] } |
424
|
0
|
|
|
0
|
|
|
sub atime { $_[0][8] } |
425
|
0
|
|
|
0
|
|
|
sub mtime { $_[0][9] } |
426
|
0
|
|
|
0
|
|
|
sub ctime { $_[0][10] } |
427
|
0
|
|
|
0
|
|
|
sub blksize { $_[0][11] } |
428
|
0
|
|
|
0
|
|
|
sub blocks { $_[0][12] } |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
1; |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
__END__ |