|
1 # |
|
2 # CheckDistributionFiles.pl |
|
3 # Aug 3rd 2009. Written for use during the SOS production build. |
|
4 # Parameter 1 : Directory to search |
|
5 # The script will search through the directory provided. (This is \clean-src in the current SOS production build.) |
|
6 # It will produce an advisory note for any missing distribution.policy.s60 files. |
|
7 # It will produce a migration note for any unnecessary distribution.policy.s60 files. |
|
8 # |
|
9 |
|
10 use File::Find; |
|
11 |
|
12 my $dirToSearch = shift; |
|
13 |
|
14 # Iterate through all sub-directories checking the distribution.policy.s60 status. |
|
15 finddepth(sub{if ($_ !~ /^\.\.?$/ ) {$entry = Cwd::cwd."\\"."$_"; if (-d $entry) {checkDir($entry)}}}, $dirToSearch); |
|
16 |
|
17 # A directory is considered empty for this purpose if it contains no files (it may contain other directories) |
|
18 sub dirIsEmpty($) |
|
19 { |
|
20 my $currentDir = shift; |
|
21 opendir DIR, $currentDir; |
|
22 |
|
23 while(my $entry = readdir DIR) { |
|
24 next if(($entry =~ /^\.\.?$/) || (-d "$currentDir"."\\"."$entry")); # ignore all directory entries (including . and ..) |
|
25 closedir DIR; |
|
26 return 0; # first file has been found |
|
27 } |
|
28 closedir DIR; |
|
29 return 1; # no files found |
|
30 } |
|
31 |
|
32 # Checks if a directory contains files other than an S60 distribution policy file. |
|
33 sub onlyPolicyFileExists($) |
|
34 { |
|
35 my $currentDir = shift; |
|
36 my $file = "distribution.policy.s60"; |
|
37 |
|
38 opendir DIR, $currentDir; |
|
39 while(my $entry = readdir DIR) { |
|
40 |
|
41 # ignore directories (including . and ..) and S60 distribution file |
|
42 next if(($entry =~ /^\.\.?$/) || (-d "$currentDir"."\\"."$entry") || ($entry =~ /^$file$/i)); |
|
43 closedir DIR; |
|
44 return 0; # first file (except distribution.policy.s60) has been found |
|
45 } |
|
46 closedir DIR; |
|
47 return 1; # no extra files found |
|
48 } |
|
49 |
|
50 # checkDir |
|
51 # Check the distribution.policy.s60 status of the directory passed as parameter. |
|
52 # 4 cases are checked for |
|
53 # Case 1: Empty directory , no policy file - this is fine |
|
54 # Case 2: The directory is empty except for the distribution.policy.s60 file - produce migration note |
|
55 # Case 3: Non-empty directory with policy file in place - this is fine |
|
56 # Case 4: Directory is not empty and does not contain a distribution.policy.s60 file - produce an advisory note |
|
57 # |
|
58 sub checkDir($) { |
|
59 |
|
60 my $currentDir = shift; |
|
61 my $file = "distribution.policy.s60"; |
|
62 |
|
63 # An empty directory should not have a policy file. |
|
64 if (dirIsEmpty($currentDir) ) |
|
65 { # Case 1: Empty directory , no policy file - this is fine |
|
66 # print "\nok, $currentDir has no files so no distribution.policy.s60 file is necessary \n"; |
|
67 } |
|
68 |
|
69 else # Directory is not empty |
|
70 { |
|
71 # Check if a policy file exists |
|
72 if (-e "$currentDir"."\\"."$file") |
|
73 { |
|
74 # Check that it is necessary i.e. that there are other files in the directory |
|
75 if (onlyPolicyFileExists($currentDir)) |
|
76 { |
|
77 # Case 2: The directory is empty except for the distribution.policy.s60 file - produce migration note |
|
78 print "MIGRATION_NOTE: Unnecessary distribution.policy.s60 file in $currentDir\n"; |
|
79 } |
|
80 else |
|
81 { |
|
82 # Case 3: Non-empty directory with policy file in place. |
|
83 # print "\nok, distribution.policy.s60 and other files exist in $currentDir\n"; |
|
84 } |
|
85 |
|
86 } |
|
87 else # no policy file exists in a non-empty directory |
|
88 { |
|
89 # Case 4: Directory is not empty and does not contain a distribution.policy.s60 file - produce an advisory note |
|
90 print "ADVISORY NOTE: Missing distribution.policy.s60 file in $currentDir \n"; |
|
91 } |
|
92 |
|
93 } # end directory is not empty |
|
94 |
|
95 } # end checkDir; |