From: Chris W. <la...@us...> - 2005-03-24 05:11:47
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16800 Modified Files: Error.pm Log Message: OIN-159: if the error filename already exists, keep incrementing the ms until it doesn't Index: Error.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Error.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Error.pm 25 Feb 2005 00:07:19 -0000 1.1 --- Error.pm 24 Mar 2005 05:11:22 -0000 1.2 *************** *** 23,26 **** --- 23,29 ---- __PACKAGE__->mk_accessors( keys %FIELDS ); + my $TEMPLATE = Template->new(); + my $ERROR_TEMPLATE = _error_template(); + sub new { my ( $class, %params ) = @_; *************** *** 83,89 **** oi_error "Parameter 'file' must be defined to store an error."; } - if ( -f $file ) { - oi_error "Cannot overwrite existing file '$file' with error contents"; - } eval { mkpath( dirname( $file ) ) --- 86,89 ---- *************** *** 92,99 **** oi_error "Cannot create directories for '$file': $@"; } ! my $error_template = $self->_error_template(); ! my $template = Template->new(); ! $template->process( \$error_template, { e => $self }, $file ) ! || oi_error "Cannot process error template to '$file': ", $template->error(); $self->file_storage( $file ); return $file; --- 92,102 ---- oi_error "Cannot create directories for '$file': $@"; } ! ! # if the file already exists, find another... (race condition) ! while ( -f $file ) { ! $file =~ s/(\d\d\d)\.txt$/sprintf( '%003d', $1 + 1 ) . '.txt'/e; ! } ! $TEMPLATE->process( \$ERROR_TEMPLATE, { e => $self }, $file ) ! || oi_error "Cannot process error template to '$file': ", $TEMPLATE->error(); $self->file_storage( $file ); return $file; |