[interchange-cvs] interchange - racke modified 2 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Mon May 5 18:30:01 2003


User:      racke
Date:      2003-05-05 22:29:27 GMT
Modified:  lib/Vend File.pm Interpolate.pm
Log:
new function Vend::File::log_file_violation to avoid code duplication

Revision  Changes    Path
2.9       +22 -6     interchange/lib/Vend/File.pm


rev 2.9, prev_rev 2.8
Index: File.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/File.pm,v
retrieving revision 2.8
retrieving revision 2.9
diff -u -r2.8 -r2.9
--- File.pm	10 Apr 2003 14:16:02 -0000	2.8
+++ File.pm	5 May 2003 22:29:27 -0000	2.9
@@ -1,6 +1,6 @@
 # Vend::File - Interchange file functions
 #
-# $Id: File.pm,v 2.8 2003/04/10 14:16:02 mheins Exp $
+# $Id: File.pm,v 2.9 2003/05/05 22:29:27 racke Exp $
 # 
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -38,6 +38,7 @@
 	file_name_is_absolute
 	get_filename
 	lockfile
+	log_file_violation
 	readfile
 	readfile_db
 	set_lock_type
@@ -52,7 +53,7 @@
 use Vend::Util;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK $errstr);
-$VERSION = substr(q$Revision: 2.8 $, 10);
+$VERSION = substr(q$Revision: 2.9 $, 10);
 
 sub writefile {
     my($file, $data, $opt) = @_;
@@ -172,10 +173,7 @@
     local($/);
 
 	unless(allowed_file($ifile)) {
-		my $msg = $Vend::File::errstr
-				|| ::errmsg("Can't read file '%s' with NoAbsolute set" , $ifile);
-		::logError($msg);
-		::logGlobal({ level => 'auth'}, $msg);
+		log_file_violation($ifile);
 		return undef;
 	}
 
@@ -693,6 +691,24 @@
 	
 #::logDebug("allowed_file check for $fn: $status");
 	return $status;
+}
+
+sub log_file_violation {
+	my ($file, $action) = @_;
+	my $msg;
+
+	unless ($msg = $Vend::File::errstr) {
+		if ($action) {
+			$msg = ::errmsg ("%s: Can't use file '%s' with NoAbsolute set",
+							 $action, $file);
+		} else {
+			$msg = ::errmsg ("Can't use file '%s' with NoAbsolute set",
+							 $file);
+		}
+	}
+
+	::logError($msg);
+	::logGlobal({ level => 'auth'}, $msg);
 }
 
 1;



2.161     +6 -32     interchange/lib/Vend/Interpolate.pm


rev 2.161, prev_rev 2.160
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.160
retrieving revision 2.161
diff -u -r2.160 -r2.161
--- Interpolate.pm	29 Apr 2003 18:13:47 -0000	2.160
+++ Interpolate.pm	5 May 2003 22:29:27 -0000	2.161
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 # 
-# $Id: Interpolate.pm,v 2.160 2003/04/29 18:13:47 mheins Exp $
+# $Id: Interpolate.pm,v 2.161 2003/05/05 22:29:27 racke Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.160 $, 10);
+$VERSION = substr(q$Revision: 2.161 $, 10);
 
 @EXPORT = qw (
 
@@ -2177,14 +2177,7 @@
 
 	$file = Vend::Util::escape_chars($file);
 	unless(Vend::File::allowed_file($file)) {
-		my $msg = $Vend::File::errstr
-				|| errmsg(
-								"%s: Can't use file '%s' with NoAbsolute set",
-								'log',
-								$file,
-							);
-		::logError($msg);
-		::logGlobal({ level => 'auth'}, $msg);
+		Vend::File::log_file_violation($file, 'log');
 		return undef;
 	}
 
@@ -2411,14 +2404,7 @@
 	}
 
 	unless (allowed_file($file)) {
-		my $msg = $Vend::File::errstr
-				|| errmsg(
-								"%s: Can't use file '%s' with NoAbsolute set",
-								'counter',
-								$file,
-							);
-		::logError($msg);
-		::logGlobal({ level => 'auth'}, $msg);
+		log_file_violation ($file, 'counter');
 		return undef;
 	}
 	
@@ -5079,13 +5065,7 @@
 
 	unless (defined $page) {
 		unless( allowed_file($selector) ) {
-			my $msg = errmsg(
-							"%s: Can't use file '%s' with NoAbsolute set",
-							'fly_page',
-							$selector,
-						);
-			::logError($msg);
-			::logGlobal({ level => 'auth'}, $msg);
+			log_file_violation($selector, 'fly_page');
 			return undef;
 		}
 		$page = readin($selector);
@@ -5616,13 +5596,7 @@
 
     $file = Vend::Util::escape_chars($file);
     if(! $opt->{auto} and ! allowed_file($file)) {
-		my $msg = errmsg(
-						"%s: Can't use file '%s' with NoAbsolute set",
-						'timed_build',
-						$file,
-					);
-		::logError($msg);
-		::logGlobal({ level => 'auth'}, $msg);
+		log_file_violation($file, 'timed_build');
 		return undef;
     }