From: Chris W. <la...@us...> - 2005-09-24 19:20:20
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18040 Modified Files: Readonly.pm Log Message: OIN-180: fix bug where we returned wrong info when readonly file not found Index: Readonly.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Config/Readonly.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Readonly.pm 17 Mar 2005 14:58:00 -0000 1.12 --- Readonly.pm 24 Sep 2005 19:20:11 -0000 1.13 *************** *** 37,40 **** --- 37,44 ---- } + sub is_readonly { + my ( $self, $filename ) = @_; + return ! $self->is_writeable( $filename ); + } sub is_writeable { *************** *** 57,67 **** # This means everything is writeable... ! return [] unless ( -f $overwrite_check_file ); ! my ( @readonly ); eval { open( NOWRITE, '<', $overwrite_check_file ) || die $! }; if ( $@ ) { $log->error( "Cannot read readonly file '$overwrite_check_file': $@" ); ! return []; } while ( <NOWRITE> ) { --- 61,71 ---- # This means everything is writeable... ! return {} unless ( -f $overwrite_check_file ); ! my %readonly = (); eval { open( NOWRITE, '<', $overwrite_check_file ) || die $! }; if ( $@ ) { $log->error( "Cannot read readonly file '$overwrite_check_file': $@" ); ! return {}; } while ( <NOWRITE> ) { *************** *** 71,78 **** s/^\s+//; s/\s+$//; ! push @readonly, $_; } close( NOWRITE ); ! return { map { $_ => 1 } @readonly }; } --- 75,82 ---- s/^\s+//; s/\s+$//; ! $readonly{ $_ } = 1; } close( NOWRITE ); ! return \%readonly; } *************** *** 176,180 **** my $original_path = '/path/to/distribution/foo.html'; my $can_write = OpenInteract2::Config::Readonly ! ->new( $dir ) ->is_writeable( $original_path ); if ( $can_write ) { --- 180,184 ---- my $original_path = '/path/to/distribution/foo.html'; my $can_write = OpenInteract2::Config::Readonly ! ->new( dirname( $original_path ) ) ->is_writeable( $original_path ); if ( $can_write ) { *************** *** 221,224 **** --- 225,233 ---- false if not. + B<is_readonly( $file )> + + Returns: true if C<$file> is not writeable in the configured + directory, false if it is. + B<get_all_writeable_files()> *************** *** 233,313 **** Returns: full path to file written. - B<is_writeable_file( \@readonly_filenames | $directory, $filename )> - - Returns true if file C<$filename> is writeable in C<$directory> or if - it is not found among C<\@readonly_filenames>. We do a C<basename()> - against C<$filename> before doing the check. - - Examples: - - # These all return true - OpenInteract2::Config::Readonly->is_writeable_file( - [ 'index.html' ], 'foo.html' ); - OpenInteract2::Config::Readonly->is_writeable_file( - [ 'index.html' ], 'INDEX.HTML' ); - OpenInteract2::Config::Readonly->is_writeable_file( - [ 'index.html' ], '/path/to/index.htm' ); - - # These all return false - OpenInteract2::Config::Readonly->is_writeable_file( - [ 'index.html' ], 'index.html' ); - OpenInteract2::Config::Readonly->is_writeable_file( - [ 'index.html' ], '/path/to/my/index.html' ); - - - B<get_writeable_files( \@readonly_filenames | $directory, \@filenames )> - - Returns an arrayref of all writeable files from C<\@filenames> as - compared against the config in C<$directory> or the readonly filenames - in C<\@readonly_filenames>. The filenames returned are whatever was - stored in C<\@filenames> rather than the basename. - - Examples: - - my $files = OpenInteract2::Config::Readonly->get_writeable_files( - [ 'index.html' ], [ '/path/to/foo.html' ] ); - # $files = [ '/path/to/foo.html' ] - - my $files = OpenInteract2::Config::Readonly->get_writeable_files( - [ 'index.html' ], [ 'INDEX.HTML', '/path/to/README.txt' ] ); - # $files = [ 'INDEX.HTML', '/path/to/README.txt' ] - - my $files = OpenInteract2::Config::Readonly->get_writeable_files( - [ 'index.html' ], [ '/path/to/index.htm', '/path/to/index.html' ] ); - # $files = [ '/path/to/index.htm' ] - - B<read_config( $dir )> - - Reads the file in C<$dir> for files not to overwrite. This method - should never C<die> or throw an exception -- if there is an error - reading the file or if the file does not exist, it simply returns an - empty arrayref. - - Returns: arrayref of filenames relative to C<$dir>. - - B<write_config( $dir, \@files_to_write | \%write_info )> - - Writes filenames to a file in C<$dir>. The C<\%write_info> parameters - can be either an arrayref of filenames to write or a hashref with the - following keys: - - =over 4 - - =item * - - B<file>: Arrayref of filenames to write - - =item * - - B<comment>: Message to write as a comment. - - =back - - No path information is written to the file, only the base filename. - - Returns: full path to file written. If the file cannot be written, it - will throw an exception. If there are no files passed in to write, it - returns nothing. - =head1 BUGS --- 242,245 ---- |