|
1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # This module implements the MD5 version of the Evalid's comapre |
|
15 # |
|
16 # |
|
17 |
|
18 package BxCopy; |
|
19 |
|
20 use strict; |
|
21 use File::Copy; |
|
22 use File::Find; |
|
23 use File::Path; |
|
24 |
|
25 # FilterDir |
|
26 # |
|
27 # Inputs |
|
28 # $iDir - Directory to process |
|
29 # $iExclude - Reference to array of regular expression patterns to exclude |
|
30 # $iInclude - Reference to array of regular expression patterns to include |
|
31 # |
|
32 # Outputs |
|
33 # @iFinalFileList - Filtered list relative filenames |
|
34 # |
|
35 # Description |
|
36 # This function produces a filtered list of filenames in the specified directory |
|
37 |
|
38 sub FilterDir |
|
39 { |
|
40 my ($iDir,$iExclude,$iInclude) = @_; |
|
41 |
|
42 my (@iFileList, @iFinalFileList); |
|
43 my ($iExcludeCount, $iIncludeCount); |
|
44 |
|
45 # Produce full filelist listing without directory names |
|
46 # Remove the specified directory path from the front of the filename |
|
47 find sub { |
|
48 if (!-d) |
|
49 { |
|
50 my $filepath = $File::Find::name; |
|
51 $filepath=~ s#^$iDir/##i; |
|
52 push @iFileList, $filepath; |
|
53 } |
|
54 }, $iDir; |
|
55 |
|
56 #Calculate the number of regex includes and excludes to optimise the filtering |
|
57 if (defined $iExclude){ |
|
58 $iExcludeCount = scalar(@$iExclude); |
|
59 } else { |
|
60 $iExcludeCount = 0; |
|
61 } |
|
62 |
|
63 if (defined $iInclude){ |
|
64 $iIncludeCount = scalar(@$iInclude); |
|
65 } else { |
|
66 $iIncludeCount = 0; |
|
67 } |
|
68 |
|
69 # return unmodified list of files if there are no regexs to fitler it by |
|
70 return \@iFileList if (($iExcludeCount == 0) && ($iIncludeCount == 0)); |
|
71 |
|
72 foreach my $iFile ( @iFileList) |
|
73 { |
|
74 my $iExcludeFile = 0; |
|
75 |
|
76 # Process all Exclude RegEx to see if this file matches |
|
77 foreach my $iExcludeRegEx (@$iExclude) |
|
78 { |
|
79 if ($iFile =~ /$iExcludeRegEx/i) |
|
80 { |
|
81 # Mark this file to be excluded from the final list |
|
82 $iExcludeFile = 1; |
|
83 } |
|
84 } |
|
85 |
|
86 # Process all Include RegEx to see if this file matches |
|
87 foreach my $iIncludeRegEx (@$iInclude) |
|
88 { |
|
89 if ($iFile =~ /$iIncludeRegEx/i) |
|
90 { |
|
91 # Mark this file to be Included in the final list |
|
92 $iExcludeFile = 0; |
|
93 } |
|
94 } |
|
95 |
|
96 # Added the file to the final list based on the flag |
|
97 push @iFinalFileList, $iFile unless $iExcludeFile; |
|
98 } |
|
99 |
|
100 return \@iFinalFileList; |
|
101 |
|
102 } |
|
103 |
|
104 # CopyFiles |
|
105 # |
|
106 # Inputs |
|
107 # $iSource - Directory to copy from |
|
108 # $iTarget - Directory to copy to |
|
109 # $iCopyFiles - Reference to an array of relative filenames to copy |
|
110 # |
|
111 # Outputs |
|
112 # |
|
113 # Description |
|
114 # This function copies files from one dir to another |
|
115 |
|
116 sub CopyFiles |
|
117 { |
|
118 my ($iSource, $iTarget, $iCopyFiles, $iVerbose, $iNoAction) = @_; |
|
119 |
|
120 print "No Copy specified, would have performed:-\n" if (defined $iNoAction); |
|
121 |
|
122 #Loop through the list of files |
|
123 my ($j); |
|
124 for($j = 0; $j < scalar(@$iCopyFiles); $j++) |
|
125 { |
|
126 my ($iFile) = $$iCopyFiles[$j]; |
|
127 #Check if the to final directory exists, if not create it |
|
128 my ($iDir) = $iFile =~ m#(.*)/.*#; |
|
129 |
|
130 if (defined $iVerbose) |
|
131 { |
|
132 print $iSource."/".$iFile." => ".$iTarget."/".$iFile."\n"; |
|
133 } |
|
134 |
|
135 if (!defined $iNoAction) |
|
136 { |
|
137 if (!-d $iTarget."/".$iDir) |
|
138 { |
|
139 mkpath ($iTarget."/".$iDir) || die "ERROR: Cannot create ".$iTarget."/".$iDir; |
|
140 } |
|
141 copy($iSource."/".$iFile,$iTarget."/".$iFile) || die "ERROR: Failed to copy ".$iSource."/".$iFile." to ".$iTarget."/".$iFile." $!"; |
|
142 } |
|
143 } |
|
144 |
|
145 print "$j files processed\n"; |
|
146 } |
|
147 |
|
148 1; |