Subversion Repositories DevTools

Rev

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

Rev 6776 Rev 7387
Line 67... Line 67...
67
#                   $pdata      - Ref to hash of controlling data
67
#                   $pdata      - Ref to hash of controlling data
68
#                                 hashed by config item and '.ignore'
68
#                                 hashed by config item and '.ignore'
69
#                                 Values are:
69
#                                 Values are:
70
#                                   default     - Default value
70
#                                   default     - Default value
71
#                                   mandatory   - Must be present
71
#                                   mandatory   - Must be present
-
 
72
#                                   requires    - Items must also be defined (accept comma sep list)
72
#                                   fmt         - Format
73
#                                   fmt         - Format
73
#                                                   'size'      - convert to block
74
#                                                   'size'      - convert to block
74
#                                                   'period'    - convert to time
75
#                                                   'period'    - convert to time
75
#                                                   'dir'       - Directory
76
#                                                   'dir'       - Directory
76
#                                                   'file'      - File
77
#                                                   'file'      - File
Line 78... Line 79...
78
#                                                   'int'       - integer
79
#                                                   'int'       - integer
79
#                                                   'int_list'  - A list of integers
80
#                                                   'int_list'  - A list of integers
80
#                                                   'text'      - Random Text
81
#                                                   'text'      - Random Text
81
#                                                   'bool'      - y/n 1/0
82
#                                                   'bool'      - y/n 1/0
82
#                               .ignore       - Regexp of items to ignore
83
#                               .ignore       - Regexp of items to ignore
-
 
84
#                               .oneOf        - Array of Array of config items. One item in each array must be defined
83
#
85
#
84
#
86
#
85
#
87
#
86
# Returns         : $conf       - Ref to config data
88
# Returns         : $conf       - Ref to config data
87
#                   $errors     - Ref to an array of error messages
89
#                   $errors     - Ref to an array of error messages
Line 120... Line 122...
120
        close $fh;
122
        close $fh;
121
 
123
 
122
        #
124
        #
123
        #   Validate mandatory entries
125
        #   Validate mandatory entries
124
        #   Insert defaults that are not present
126
        #   Insert defaults that are not present
-
 
127
        #   Check conflicts
-
 
128
        #   Check required entries
125
        #
129
        #
126
        while ( (my ($key, $entry)) = each %{$pdata} )
130
        while ( (my ($key, $entry)) = each %{$pdata} )
127
        {
131
        {
-
 
132
            next if $key =~ m~^\.~;
128
            if ( exists ($entry->{mandatory}) && $entry->{mandatory}  )
133
            if ( exists ($entry->{mandatory}) && $entry->{mandatory}  )
129
            {
134
            {
130
                if ( !exists $conf->{$key} )
135
                if ( !exists $conf->{$key} )
131
                {
136
                {
132
                    push @errors, "Mandatory config not found: $key";
137
                    push @errors, "Mandatory config not found: $key";
133
                }
138
                }
134
            }
139
            }
135
 
140
 
-
 
141
            if ( exists $entry->{requires} && exists $conf->{$key} ) {
-
 
142
                foreach my $rkey (split (',',  $entry->{requires}))
-
 
143
                {
-
 
144
                    if ( !exists $conf->{$rkey} )
-
 
145
                    {
-
 
146
                        push @errors, "$key requires that $rkey also be specified";
-
 
147
                    }
-
 
148
                }
-
 
149
            }
-
 
150
 
136
            if ( exists $entry->{default} )
151
            if ( exists $entry->{default} )
137
            {
152
            {
138
                if ( !exists $conf->{$key} )
153
                if ( !exists $conf->{$key} )
139
                {
154
                {
140
                    $conf->{$key} = $entry->{default};
155
                    $conf->{$key} = $entry->{default};
141
                }
156
                }
142
            }
157
            }
143
        }
158
        }
144
 
159
 
145
        #
160
        #
-
 
161
        #   oneOf processing
-
 
162
        #   
-
 
163
        if ($pdata->{'.oneOf'}) {
-
 
164
            foreach my $set ( @{$pdata->{'.oneOf'}} ) {
-
 
165
                my $found = 0;
-
 
166
                foreach my $key ( @{$set}) {
-
 
167
                    if (exists $conf->{$key} && defined $conf->{$key}) {
-
 
168
                        $found++;
-
 
169
                    }
-
 
170
                }
-
 
171
                if ($found ne 1) {
-
 
172
                    push @errors, "Require exactly one of " . join(',',  @{$set});
-
 
173
                }
-
 
174
            }
-
 
175
            
-
 
176
        }
-
 
177
 
-
 
178
        #
146
        #   Scan all user items
179
        #   Scan all user items
147
        #
180
        #
148
        my $ignore_re = $pdata->{'.ignore'} ;
181
        my $ignore_re = $pdata->{'.ignore'} ;
149
        while ( (my ($key, $data)) = each %{$conf} )
182
        while ( (my ($key, $data)) = each %{$conf} )
150
        {
183
        {
Line 303... Line 336...
303
    }
336
    }
304
    return $result;
337
    return $result;
305
}
338
}
306
 
339
 
307
#-------------------------------------------------------------------------------
340
#-------------------------------------------------------------------------------
-
 
341
# Function        : TouchFile 
-
 
342
#
-
 
343
# Description     : touch a file
-
 
344
#                   Real use is to touch a marker file
-
 
345
#
-
 
346
# Inputs          : path        - path to the file
-
 
347
#
-
 
348
# Returns         : TRUE if an error occured in creating the file
-
 
349
#
-
 
350
sub TouchFile($$)
-
 
351
{
-
 
352
 
-
 
353
    my ($conf, $path) = @_;
-
 
354
    my $logger = $conf->{logger};
-
 
355
    my $result = 0;
-
 
356
    my $tfh;
-
 
357
 
-
 
358
    $logger->verbose( "Touching: $path" );
-
 
359
    if ( ! -f $path )
-
 
360
    {
-
 
361
        open ($tfh, ">>", $path) || ($result = 1);
-
 
362
        close $tfh;
-
 
363
    }
-
 
364
    else
-
 
365
    {
-
 
366
 
-
 
367
        #
-
 
368
        #   Modify the file
-
 
369
        #
-
 
370
        #   Need to physically modify the file
-
 
371
        #   Need to change the 'change time' on the file. Simply setting the
-
 
372
        #   last-mod and last-access is not enough to get past WIN32
-
 
373
        #   OR 'utime()' does not work as expected
-
 
374
        #
-
 
375
        #   Read in the first character of the file, rewind and write it
-
 
376
        #   out again.
-
 
377
        #
-
 
378
        my $data;
-
 
379
        open ($tfh , "+<", $path ) || return 1;
-
 
380
        if ( read ( $tfh, $data, 1 ) )
-
 
381
        {
-
 
382
            seek  ( $tfh, 0, 0 );
-
 
383
            print $tfh $data;
-
 
384
        }
-
 
385
        else
-
 
386
        {
-
 
387
            #
-
 
388
            #   File must have been of zero length
-
 
389
            #   Delete the file and create it
-
 
390
            #
-
 
391
            close ($tfh);
-
 
392
            unlink ( $path );
-
 
393
            open ($tfh, ">>", $path) || ($result = 1);
-
 
394
        }
-
 
395
        close ($tfh);
-
 
396
    }
-
 
397
 
-
 
398
    #
-
 
399
    #   Ensure all can remove the file
-
 
400
    #   May be created by root and need to be deleted by the blatDaemon
-
 
401
    #
-
 
402
    chmod 0666, $path;
-
 
403
    return $result;
-
 
404
}
-
 
405
 
-
 
406
#-------------------------------------------------------------------------------
308
# Function        : toBytes
407
# Function        : toBytes
309
#
408
#
310
# Description     : Process a string and convert it to a byte count
409
# Description     : Process a string and convert it to a byte count
311
#                   Handle:
410
#                   Handle:
312
#                       100     -> 100 bytes
411
#                       100     -> 100 bytes