|
From: <cas...@co...> - 2007-11-01 23:00:25
|
Author: cashmont
Date: 2007-11-01 17:00:18 -0600 (Thu, 01 Nov 2007)
New Revision: 2197
Modified:
cap4/branches/cap4.0/usr/libexec/core.pm
cap4/branches/cap4.0/usr/libexec/workorder.pm
Log:
core.pm: added function to determine if a filename could be created
workorder.pm: check if workorder to be created is possible, and if not, expire that workorder
This should close #151
-cdm
Modified: cap4/branches/cap4.0/usr/libexec/core.pm
===================================================================
--- cap4/branches/cap4.0/usr/libexec/core.pm 2007-11-01 19:03:05 UTC (rev 2196)
+++ cap4/branches/cap4.0/usr/libexec/core.pm 2007-11-01 23:00:18 UTC (rev 2197)
@@ -44,7 +44,7 @@
$Term::ANSIColor::AUTORESET = 1;
our @ISA = qw(Exporter);
-our @EXPORT = qw(noshell_exec compress getrange CheckSetCmdLineDefaults ParseCommandLine PrintCoreHelp printreftype getreftype dinfo dprint ddie dwarn uniqlist hasTimeExpired isCmdLineDefault $command $commandline $cluster $all $node $range $rack $rackposition $type $make $model $macaddress $ipaddress $network $console $power $management $mgrdelay $delay $debug $verbose $help $number_of_inputs $flat $username $password $protocol $ctrldevice $device $port $site $system $local $dryrun $force $nocache $exact $balance $managers $exclude $speconf $quiet $fanout);
+our @EXPORT = qw(IsValidFilenameLength noshell_exec compress getrange CheckSetCmdLineDefaults ParseCommandLine PrintCoreHelp printreftype getreftype dinfo dprint ddie dwarn uniqlist hasTimeExpired isCmdLineDefault $command $commandline $cluster $all $node $range $rack $rackposition $type $make $model $macaddress $ipaddress $network $console $power $management $mgrdelay $delay $debug $verbose $help $number_of_inputs $flat $username $password $protocol $ctrldevice $device $port $site $system $local $dryrun $force $nocache $exact $balance $managers $exclude $speconf $quiet $fanout);
our (@coloridlist, $command, $commandline, $all, $node, $range, $rack, $rackposition, $type, $make, $model, $macaddress, $ipaddress, $network, $console, $power, $management, $mgrdelay, $delay, $debug, $verbose, $help, $number_of_inputs, $flat, $username, $password, $protocol, $ctrldevice, $device, $port, $blade, $site, $system, $local, $cluster, $dryrun, $force, $nocache, $exact, $balance, $managers, $exclude, $speconf, $quiet, $fanout);
@@ -545,6 +545,14 @@
}
}
+#
+# given a name for a file, validate it should it exceed an allowable size
+#
+sub IsValidFilenameLength {
+ my $potential_filename = shift;
+ return length($potential_filename) < 255;
+}
+
return 1;
=head1 core.pm
Modified: cap4/branches/cap4.0/usr/libexec/workorder.pm
===================================================================
--- cap4/branches/cap4.0/usr/libexec/workorder.pm 2007-11-01 19:03:05 UTC (rev 2196)
+++ cap4/branches/cap4.0/usr/libexec/workorder.pm 2007-11-01 23:00:18 UTC (rev 2197)
@@ -185,7 +185,26 @@
# place holder for workorder id
my $wid = "$work_type" . "-$work_command" . "-$devices" . "-$work_notes.cap4_workorder";
+ # register the workorder creation time,
+ # set 0 if debugging or verbose so we get a fresh one next time.
+ my $workorder_start_time=time();
+ $workorder_start_time = 0 if $debug or $verbose;
+
#
+ # validate the filename length
+ #
+ if (!IsValidFilenameLength($wid)) {
+ $wid = "$work_type" . "-$work_command" . "-LONG_DEVICELIST" . "-$work_notes.cap4_workorder";
+ if (!IsValidFilenameLength($wid)) {
+ $wid = "CAP4WORKORDER.cap4_workorder";
+ }
+ #
+ # expire this workorder since it will never be unique
+ #
+ $workorder_start_time = 0;
+ }
+
+ #
# check if workorder id is valid: WORK_command_RACK
# always override and create a new one if we specify a protocol
#
@@ -214,7 +233,7 @@
} else {
- sysopen(WID_FILE, "$workorder_dir/$wid", O_WRONLY|O_TRUNC|O_CREAT, 0700) or ddie("workorder.pm: InitiateWorkOrder($work_type, $devices, $work_command, $work_notes): Could not open $workorder_dir/$wid: $!");
+ sysopen(WID_FILE, "$workorder_dir/$wid", O_WRONLY|O_TRUNC|O_CREAT, 0700) or ddie("workorder.pm: InitiateWorkOrder($work_type, $devices, $work_command, $work_notes): Could not open $workorder_dir/$wid: $! DAMN IT");
flock(WID_FILE, LOCK_EX) or ddie("workorder.pm: InitiateWorkOrder($work_type, $devices, $work_command, $work_notes): Could not lock $workorder_dir/$wid perhaps due to existing work order execution on $wid?");
# get deivce records, the control devices for the work to be done,
@@ -225,11 +244,6 @@
my $workorder_default_ctrl_protocol = "\"NONE\"";
$workorder_default_ctrl_protocol = $protocol if $protocol;
- # register the workorder creation time,
- # set 0 if debugging or verbose so we get a fresh one next time.
- my $workorder_start_time=time();
- $workorder_start_time = 0 if $debug or $verbose;
-
my $workorder_template_dir = ( $ENV{CAPHOME} eq "/usr" ? "/usr/include/cap" : "$ENV{CAPHOME}/include");
my $workorder_driver_directory = ( $ENV{CAPHOME} eq "/usr" ? "/usr/libexec/cap/drivers" : "$ENV{CAPHOME}/libexec/drivers");
|