Subversion Repositories DevTools

Rev

Rev 273 | Rev 4612 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 273 Rev 275
Line 6... Line 6...
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
# Environment(s): jats
7
# Environment(s): jats
8
#
8
#
9
#                 Utility functions to
9
#                 Utility functions to
10
#                   CopyDir                 - Copy Dir Tree
10
#                   CopyDir                 - Copy Dir Tree
11
#                   CopyFile                - Copy one file
11
#                   CopyFile                - Copy one or more files
12
#                   CreateDir               - Create one directory
12
#                   CreateDir               - Create one directory
13
#                   DeleteDir               - Delete Dir Tree
13
#                   DeleteDir               - Delete Dir Tree
14
#                   DeleteFile              - Delete a file
14
#                   DeleteFile              - Delete a file
15
#                   SetCopyDirDefaults      - Set application wide defaults
15
#                   SetCopyDirDefaults      - Set application wide defaults
16
#
16
#
Line 49... Line 49...
49
#               Notify me if an existing file is present
49
#               Notify me if an existing file is present
50
#               Do not copy files called a2 and build.pl
50
#               Do not copy files called a2 and build.pl
51
#               Do not copy the .svn subdir
51
#               Do not copy the .svn subdir
52
#               Do not copy files ending in 2
52
#               Do not copy files ending in 2
53
#
53
#
54
# Issues:
-
 
55
#               MatchDirs and MatchDirsRE don't work
-
 
56
#               Need to define what is wanted first
-
 
57
#               IgnoreDirs - appears to be useful
-
 
58
#
-
 
59
#......................................................................#
54
#......................................................................#
60
 
55
 
61
use strict;
56
use strict;
62
use warnings;
57
use warnings;
63
 
58
 
Line 121... Line 116...
121
#                       IgnoreRE        - An array of files to ignore (RE)
116
#                       IgnoreRE        - An array of files to ignore (RE)
122
#                       IgnoreDirs      - An array of subdirs to ignore
117
#                       IgnoreDirs      - An array of subdirs to ignore
123
#                       IgnoreDirsRE    - An array of subdirs to ignore (RE)
118
#                       IgnoreDirsRE    - An array of subdirs to ignore (RE)
124
#                       Match           - An array of files to match
119
#                       Match           - An array of files to match
125
#                       MatchRE         - An array of file to match (RE)
120
#                       MatchRE         - An array of file to match (RE)
126
#                       MatchDirs       - An array of dirs to match
121
#                       MatchDirs       - An array of top level dirs to match
127
#                       MatchDirsRE     - An array of dirs to match (RE)
122
#                       MatchDirsRE     - An array of top level dirs to match (RE)
-
 
123
#                       SkipTLF         - Skip Files in the specified dir -
-
 
124
#                                         only consider subdirs
128
#                     Misc
125
#                     Misc
129
#                       Stats           - A ref to a hash of stats
126
#                       Stats           - A ref to a hash of stats
130
#                       FileList        - Ref to array of target files
127
#                       FileList        - Ref to array of target files
131
#                       UserData        - Item passed through to call backs
128
#                       UserData        - Item passed through to call backs
132
#                                         for the users own purposes.
129
#                                         for the users own purposes.
Line 224... Line 221...
224
#
221
#
225
# Description     : Utility function to copy a single file
222
# Description     : Utility function to copy a single file
226
#                   Uses the same options and loging infrastructure
223
#                   Uses the same options and loging infrastructure
227
#                   as CopyDir
224
#                   as CopyDir
228
#
225
#
229
# Inputs          : $src_file               - Src directory
226
# Inputs          : $src_file               - Src file spec
-
 
227
#                                             May be a file or a reference to an
-
 
228
#                                             array of files.
230
#                   $dst_file               - Dest file (or dir)
229
#                   $dst_file               - Dest file (or dir)
231
#                   $opt                    - A Hash of options
230
#                   $opt                    - A Hash of options
232
#                                             Refer to CopyDir
231
#                                             Refer to CopyDir
233
#
232
#
234
# Returns         : Path to the target file
233
# Returns         : Path to the target file
-
 
234
#                   If multiple files are being copied then it is the
-
 
235
#                   path to the last one copied.
235
#
236
#
236
sub CopyFile
237
sub CopyFile
237
{
238
{
238
    my $src_file = shift;
239
    my $src_spec = shift;
239
    my $dst_file = shift;
240
    my $dst_spec = shift;
240
    my $opt = JatsCopyInternal::DefaultOpts( 'CopyFile', @_);
241
    my $opt = JatsCopyInternal::DefaultOpts( 'CopyFile', @_);
241
 
242
 
242
    #
243
    #
243
    #   Do not Validate source dir
244
    #   Do not Validate source dir
244
    #   Do it within the copy operation and get the same error
245
    #   Do it within the copy operation and get the same error
245
    #   handling as the CopyDir processing
246
    #   handling as the CopyDir processing
246
    #
247
    #
247
 
248
 
248
    #
249
    #
249
    #   If the target is a directory, then copy by name
250
    #   Handle a scalar and and array in the same manner
250
    #
251
    #
-
 
252
    if ( ref $src_spec ne 'ARRAY' ) {
251
    my $file = StripDir ($src_file);
253
        my @slist = ($src_spec );
252
    $dst_file .= '/' . $file if ( -d $dst_file );
254
        $src_spec = \@slist;
-
 
255
    }
253
 
256
 
254
    #
-
 
255
    #   Insert additional options to provide the same interface to
-
 
256
    #   the internal functions used to do the copy
-
 
257
    #
-
 
258
    #       item            - Source Path
257
    my $rv = undef;
259
    #       tgt             - Dest subdir below dst_dir
-
 
260
    #       file            - Filename
-
 
261
    #       target          - Dest Path
258
    foreach my $src_file ( @{$src_spec} )
262
    #
259
    {
263
    $opt->{'item'}     = $src_file;
260
        next unless ( $src_file );
264
    $opt->{'file'}     = $file;
-
 
265
    $opt->{'target'}   = $dst_file;
-
 
266
    $opt->{'type'}     = 'f';
-
 
267
 
261
 
-
 
262
        #
-
 
263
        #   If the target is a directory, then copy by name
268
    #
264
        #
-
 
265
        my $file = StripDir ($src_file);
-
 
266
        my $dst_file = $dst_spec;
-
 
267
        $dst_file .= '/' . $file if ( -d $dst_file );
-
 
268
 
-
 
269
        #
-
 
270
        #   Insert additional options to provide the same interface to
-
 
271
        #   the internal functions used to do the copy
-
 
272
        #
-
 
273
        #       item            - Source Path
-
 
274
        #       tgt             - Dest subdir below dst_dir
-
 
275
        #       file            - Filename
-
 
276
        #       target          - Dest Path
-
 
277
        #
-
 
278
        $opt->{'item'}     = $src_file;
-
 
279
        $opt->{'file'}     = $file;
-
 
280
        $opt->{'target'}   = $dst_file;
-
 
281
        $opt->{'type'}     = 'f';
-
 
282
 
-
 
283
        #
269
    #   Invoke the common file copy routine
284
        #   Invoke the common file copy routine
270
    #
285
        #
271
    return JatsCopyInternal::CopyFile ( $src_file, $dst_file, $opt );
286
        $rv = JatsCopyInternal::CopyFile ( $src_file, $dst_file, $opt );
-
 
287
    }
-
 
288
 
-
 
289
    return $rv;
272
}
290
}
273
 
291
 
274
#-------------------------------------------------------------------------------
292
#-------------------------------------------------------------------------------
275
# Function        : CreateDir
293
# Function        : CreateDir
276
#
294
#
Line 549... Line 567...
549
            #
567
            #
550
            stat ( $filename );
568
            stat ( $filename );
551
            if ( -f _ )
569
            if ( -f _ )
552
            {
570
            {
553
                $opt->{'Stats'}{'examinedFiles'}++;
571
                $opt->{'Stats'}{'examinedFiles'}++;
-
 
572
                next if ( $opt->{'SkipTLF'} );
554
                next unless doMatch ( $file, $opt, 'MatchRE', 'IgnoreRE' );
573
                next unless doMatch ( $file, $opt, 'MatchRE', 'IgnoreRE' );
555
                $opt->{'type'} = 'f';
574
                $opt->{'type'} = 'f';
556
            }
575
            }
557
            elsif ( -d _ )
576
            elsif ( -d _ )
558
            {
577
            {
Line 613... Line 632...
613
            #   Always invoke the 'Expert' function
632
            #   Always invoke the 'Expert' function
614
            #   A dummy one will be provided unless the user gave one
633
            #   A dummy one will be provided unless the user gave one
615
            #
634
            #
616
            $opt->{'Expert'} ( $opt );
635
            $opt->{'Expert'} ( $opt );
617
        }
636
        }
-
 
637
 
-
 
638
        #
-
 
639
        #   Have processed the entire directory
-
 
640
        #   Kill the 'MatchDirsRE' data so that the Directory match
-
 
641
        #   only occurs on the Root directory
-
 
642
        #
-
 
643
        delete $opt->{'MatchDirsRE'};
-
 
644
        delete $opt->{'SkipTLF'};
618
    }
645
    }
619
}
646
}
620
 
647
 
621
#-------------------------------------------------------------------------------
648
#-------------------------------------------------------------------------------
622
# Function        : Body
649
# Function        : Body
Line 1085... Line 1112...
1085
    'UserData'        => 0,
1112
    'UserData'        => 0,
1086
    'SymlinkFiles'    => Scalar,
1113
    'SymlinkFiles'    => Scalar,
1087
    'ReadOnlyFiles'   => Scalar,
1114
    'ReadOnlyFiles'   => Scalar,
1088
    'KeepSrcTail'     => Scalar,
1115
    'KeepSrcTail'     => Scalar,
1089
    'FileList'        => ArrayRef,
1116
    'FileList'        => ArrayRef,
-
 
1117
    'SkipTLF'         => Scalar,
1090
);
1118
);
1091
 
1119
 
1092
 
1120
 
1093
#-------------------------------------------------------------------------------
1121
#-------------------------------------------------------------------------------
1094
# Function        : ValidateArg
1122
# Function        : ValidateArg