###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::TouchFile - touch file action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::TouchFile;
use strict;
use PSGConf::Action::File;
our @ISA = qw(PSGConf::Action::File);
###############################################################################
### check method
###############################################################################
sub check
{
my ($self, $psgconf) = @_;
local *FP;
$self->_set_tmpfile($psgconf);
if ( ! -e $self->{name} ) {
open (FP, ">>" . $self->{tmpfile}) || die "Cannot write " . $self->{tmpfile} . ":$!";
close FP;
}
$self->{changed} = 1;
### check for permission differences
$self->PSGConf::Action::ChMod::check($psgconf);
### check for ownership differences
$self->PSGConf::Action::ChOwn::check($psgconf);
### check for group differences
$self->PSGConf::Action::ChGrp::check($psgconf);
return $self->{changed};
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self, $psgconf) = @_;
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "+ touch $self->{name}\n\n";
### check for permission differences
$self->PSGConf::Action::ChMod::diff($psgconf);
### check for ownership differences
$self->PSGConf::Action::ChOwn::diff($psgconf);
### check for group differences
$self->PSGConf::Action::ChGrp::diff($psgconf);
}
###############################################################################
### do method
###############################################################################
sub do
{
my ($self, $psgconf) = @_;
my ($t) = time;
$self->SUPER::do($psgconf);
$t = $self->{timestamp}
if ( exists $self->{timestamp} );
if (!utime($t, $t, $self->{name}))
{
warn "\n\t!!! can't update timestamp (" . $self->{name} . ")\n";
return -1;
}
return 1;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::TouchFile - touch file action type for psgconf
=head1 SYNOPSIS
use PSGConf::Action::TouchFile;
$psgconf->register_actions(
PSGConf::Action::TouchFile->new(
'name' => '/path/to/file',
...
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::TouchFile> module provides a B<PSGConf> action
class for updating the timestamp a file.
The B<PSGConf::Action::TouchFile> class is derived from the
B<PSGConf::Action::File> class, but it defines/overrides the
following methods:
=over 4
=item check()
If the file already exists, returns 0. Otherwise, creates an empty
tmpfile and returns 1.
=item diff()
Displays a message indicating that the file needs to be touched.
=back
=head1 SEE ALSO
L<perl>
C<CE<lt>touch(1)E<gt>>
L<PSGConf>
L<PSGConf::Action::File>
L<ExtUtils::Command>
=cut
syntax highlighted by Code2HTML, v. 0.9.1