@@ -94,70 +94,54 @@ sub sync_up {
94
94
$source = get_file_path( $source , caller );
95
95
96
96
#
97
- # first, get all files on source side
97
+ # first, build excludes list
98
98
#
99
- my @local_files = _get_local_files($source );
100
99
101
- # print Dumper(\@local_files);
100
+ my $excludes = $options -> {exclude } ||= [];
101
+ $excludes = [$excludes ] unless ref ($excludes ) eq ' ARRAY' ;
102
102
103
- #
104
- # second, get all files from destination side
105
- #
103
+ my @excluded_files = @{$excludes };
106
104
107
- my @remote_files = _get_remote_files($dest );
105
+ my $check_exclude_file = sub {
106
+ my ($file ) = @_ ;
107
+ $file =~ s { ^/} {} ;
108
108
109
- # print Dumper(\@remote_files);
109
+ for my $cmp (@excluded_files ) {
110
+ return 1 if match_glob( $cmp , $file );
111
+ }
112
+
113
+ return 0;
114
+ };
110
115
111
116
#
112
- # third , get the difference
117
+ # second , get all files on source side (minus excludes)
113
118
#
119
+ my @local_files = _get_local_files( $source , $check_exclude_file );
114
120
115
- my @diff = _diff_files( \@local_files , \@remote_files );
116
-
117
- # print Dumper(\@diff);
121
+ # print Dumper(\@local_files);
118
122
119
123
#
120
- # fourth, build excludes list
124
+ # third, get all files from destination side (minus excludes)
121
125
#
122
126
123
- my $excludes = $options -> {exclude } ||= [];
124
- $excludes = [$excludes ] unless ref ($excludes ) eq ' ARRAY' ;
127
+ my @remote_files = _get_remote_files( $dest , $check_exclude_file );
125
128
126
- my @excluded_files = @{ $excludes } ;
129
+ # print Dumper(\@remote_files) ;
127
130
128
131
#
129
- # fifth, upload the different files
132
+ # fourth, get the difference
130
133
#
131
134
132
- my $check_exclude_file = sub {
133
- my ( $file , $cmp ) = @_ ;
134
- if ( $cmp =~ m /\/ / ) {
135
-
136
- # this is a directory exclude
137
- if ( match_glob( $cmp , $file ) || match_glob( $cmp , substr ( $file , 1 ) ) )
138
- {
139
- return 1;
140
- }
141
-
142
- return 0;
143
- }
135
+ my @diff = _diff_files( \@local_files , \@remote_files );
144
136
145
- if ( match_glob( $cmp , basename($file ) ) ) {
146
- return 1;
147
- }
137
+ # print Dumper(\@diff);
148
138
149
- return 0;
150
- };
139
+ #
140
+ # fifth, upload the different files
141
+ #
151
142
152
143
my @uploaded_files ;
153
144
for my $file (@diff ) {
154
- next
155
- if (
156
- scalar (
157
- grep { $check_exclude_file -> ( $file -> {name }, $_ ) } @excluded_files
158
- ) > 0
159
- );
160
-
161
145
my ($dir ) = ( $file -> {path } =~ m / (.*)\/ [^\/ ] +$ / );
162
146
my ($remote_dir ) = ( $file -> {name } =~ m /\/ (.*)\/ [^\/ ] +$ / );
163
147
@@ -252,44 +236,53 @@ sub sync_down {
252
236
$dest = resolv_path($dest );
253
237
254
238
#
255
- # first, get all files on dest side
239
+ # first, build excludes list
256
240
#
257
- my @local_files = _get_local_files($dest );
258
241
259
- # print Dumper(\@local_files);
242
+ my $excludes = $options -> {exclude } ||= [];
243
+ $excludes = [$excludes ] unless ref ($excludes ) eq ' ARRAY' ;
244
+
245
+ my @excluded_files = @{$excludes };
246
+
247
+ my $check_exclude_file = sub {
248
+ my ($file ) = @_ ;
249
+ $file =~ s { ^/} {} ;
250
+
251
+ for my $cmp (@excluded_files ) {
252
+ return 1 if match_glob( $cmp , $file );
253
+ }
254
+
255
+ return 0;
256
+ };
260
257
261
258
#
262
- # second, get all files from source side
259
+ # second, get all files on dest side (minus excludes)
263
260
#
261
+ my @local_files = _get_local_files( $dest , $check_exclude_file );
264
262
265
- my @remote_files = _get_remote_files($source );
266
-
267
- # print Dumper(\@remote_files);
263
+ # print Dumper(\@local_files);
268
264
269
265
#
270
- # third, get the difference
266
+ # third, get all files from source side (minus excludes)
271
267
#
272
268
273
- my @diff = _diff_files( \ @remote_files , \ @local_files );
269
+ my @remote_files = _get_remote_files( $source , $check_exclude_file );
274
270
275
- # print Dumper(\@diff );
271
+ # print Dumper(\@remote_files );
276
272
277
273
#
278
- # fourth, build excludes list
274
+ # fourth, get the difference
279
275
#
280
276
281
- my $excludes = $options -> {exclude } ||= [];
282
- $excludes = [$excludes ] unless ref ($excludes ) eq ' ARRAY' ;
277
+ my @diff = _diff_files( \@remote_files , \@local_files );
283
278
284
- my @excluded_files = map { glob_to_regex( $_ ); } @{ $excludes } ;
279
+ # print Dumper(\@diff) ;
285
280
286
281
#
287
282
# fifth, download the different files
288
283
#
289
284
290
285
for my $file (@diff ) {
291
- next if grep { basename( $file -> {name } ) =~ $_ } @excluded_files ;
292
-
293
286
my ($dir ) = ( $file -> {path } =~ m / (.*)\/ [^\/ ] +$ / );
294
287
my ($remote_dir ) = ( $file -> {name } =~ m /\/ (.*)\/ [^\/ ] +$ / );
295
288
@@ -326,7 +319,7 @@ sub sync_down {
326
319
}
327
320
328
321
sub _get_local_files {
329
- my ($source ) = @_ ;
322
+ my ( $source , $exclude_sub ) = @_ ;
330
323
331
324
if ( !-d $source ) { die (" $source : no such directory." ); }
332
325
@@ -337,13 +330,15 @@ sub _get_local_files {
337
330
for my $entry ( list_files($dir ) ) {
338
331
next if ( $entry eq " ." );
339
332
next if ( $entry eq " .." );
333
+
334
+ my $name = " $dir /$entry " ;
335
+ $name =~ s / ^\Q $source\E // ;
336
+ next if $exclude_sub -> ($name );
337
+
340
338
if ( is_dir(" $dir /$entry " ) ) {
341
339
push ( @dirs , " $dir /$entry " );
342
340
next ;
343
341
}
344
-
345
- my $name = " $dir /$entry " ;
346
- $name =~ s / ^\Q $source\E // ;
347
342
push (
348
343
@local_files ,
349
344
{
@@ -361,7 +356,7 @@ sub _get_local_files {
361
356
}
362
357
363
358
sub _get_remote_files {
364
- my ($dest ) = @_ ;
359
+ my ( $dest , $exclude_sub ) = @_ ;
365
360
366
361
if ( !is_dir($dest ) ) { die (" $dest : no such directory." ); }
367
362
@@ -372,13 +367,16 @@ sub _get_remote_files {
372
367
for my $entry ( list_files($dir ) ) {
373
368
next if ( $entry eq " ." );
374
369
next if ( $entry eq " .." );
370
+
371
+ my $name = " $dir /$entry " ;
372
+ $name =~ s / ^\Q $dest\E // ;
373
+ next if $exclude_sub -> ($name );
374
+
375
375
if ( is_dir(" $dir /$entry " ) ) {
376
376
push ( @remote_dirs , " $dir /$entry " );
377
377
next ;
378
378
}
379
379
380
- my $name = " $dir /$entry " ;
381
- $name =~ s / ^\Q $dest\E // ;
382
380
push (
383
381
@remote_files ,
384
382
{
@@ -411,3 +409,4 @@ sub _diff_files {
411
409
}
412
410
413
411
1;
412
+
0 commit comments