vcl-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arku...@apache.org
Subject svn commit: r1645086 - in /vcl/trunk/managementnode/lib/VCL/Module: OS.pm OS/Windows.pm Provisioning.pm
Date Fri, 12 Dec 2014 22:47:59 GMT
Author: arkurth
Date: Fri Dec 12 22:47:58 2014
New Revision: 1645086

URL: http://svn.apache.org/r1645086
Log:
VCL-783
The latest version of Cygwin doesn't install unix2dos by default. This causes problems. Removed
Windows.pm::run_unix2dos. Added set_text_file_line_endings to Windows.pm and OS.pm. Changed
all calls to run_unix2dos to set_text_file_line_endings.

Other
Removed unused Windows.pm::format_text_file.

Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
    vcl/trunk/managementnode/lib/VCL/Module/Provisioning.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=1645086&r1=1645085&r2=1645086&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS.pm Fri Dec 12 22:47:58 2014
@@ -1132,42 +1132,34 @@ sub set_vcld_post_load_status {
 	}
 
 	my $image_os_type = $self->data->get_image_os_type();
-	my $computer_node_name   = $self->data->get_computer_node_name();
+	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $time = localtime;
 	
+	my $file_path = 'currentimage.txt';
+	$self->remove_lines_from_file($file_path, 'vcld_post_load');
+	
 	my $post_load_line = "vcld_post_load=success ($time)";
 	
 	# Assemble the command
 	my $command;
-	
-	# Remove existing lines beginning with vcld_post_load
-	$command .= "sed -i -e \'/vcld_post_load.*/d\' currentimage.txt";
-
-	# Add a line to the end of currentimage.txt
-	$command .= " && echo >> currentimage.txt";
-	$command .= " && echo \"$post_load_line\" >> currentimage.txt";
-	
-	# Remove blank lines
-	$command .= ' && sed -i -e \'/^[\\s\\r\\n]*$/d\' currentimage.txt';
-
-	if ($image_os_type =~ /windows/i) {
-		$command .= " && unix2dos currentimage.txt";
-	}
+	$command .= " echo >> $file_path";
+	$command .= " && echo \"$post_load_line\" >> $file_path";
 	
 	my ($exit_status, $output) = $self->execute($command, 1);
 	if (defined($exit_status) && $exit_status == 0) {
-		notify($ERRORS{'DEBUG'}, 0, "added line to currentimage.txt on $computer_node_name: '$post_load_line'");
+		notify($ERRORS{'DEBUG'}, 0, "added line to $file_path on $computer_node_name: '$post_load_line'");
 	}
 	elsif ($exit_status) {
-		notify($ERRORS{'WARNING'}, 0, "failed to add line to currentimage.txt on $computer_node_name:
'$post_load_line', exit status: $exit_status, output:\n" . join("\n", @$output));
+		notify($ERRORS{'WARNING'}, 0, "failed to add line to $file_path on $computer_node_name:
'$post_load_line', exit status: $exit_status, output:\n" . join("\n", @$output));
 		return;
 	}
 	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to add line to currentimage.txt
on $computer_node_name");
+		notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to add line to $file_path on $computer_node_name");
 		return;
 	}
 	
+	$self->set_text_file_line_endings($file_path);
 	return 1;
 }
 
@@ -1912,19 +1904,6 @@ sub create_text_file {
 		$self->create_directory($parent_directory_path) if $parent_directory_path;
 	}
 	
-	# Remove Windows-style carriage returns if the image OS isn't Windows
-	if ($image_os_type =~ /windows/) {
-		$file_contents_string =~ s/\r*\n/\r\n/g;
-	}
-	else {
-		$file_contents_string =~ s/\r//g;
-	}
-	
-	# Add a newline to the end of the contents
-	if ($file_contents_string !~ /\n$/) {
-		$file_contents_string .= "\n";
-	}
-	
 	# Convert the string to a string containing the hex value of each character
 	# This is done to avoid problems with special characters in the file contents
 	
@@ -1998,6 +1977,58 @@ sub append_text_file {
 }
 
 #/////////////////////////////////////////////////////////////////////////////
+
+=head2 set_text_file_line_endings
+
+ Parameters  : $file_path, $line_ending (optional)
+ Returns     : boolean
+ Description : Changes the line endings of a text file. This is equivalent to
+               running unix2dos or dos2unix. The default line ending type is
+               unix. Windows-style line endings will be applied if the
+               $line_ending argument is supplied and contains 'win' or 'r'.
+
+=cut
+
+sub set_text_file_line_endings {
+	my $self = shift;
+	if (ref($self) !~ /VCL::Module/i) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
+		return;
+	}
+	
+	my ($file_path, $line_ending) = @_;
+	if (!$file_path) {
+		notify($ERRORS{'WARNING'}, 0, "file path argument was not supplied");
+		return;
+	}
+	
+	my $command = 'sed -i -r ';
+	my $type;
+	if ($line_ending && $line_ending =~ /(r|win)/i) {
+		$type = 'windows';
+		$command .= '"s/\r*$/\r/"';
+	}
+	else {
+		$type = 'unix';
+		$command .= '"s/\r//"';
+	}
+	$command .= " $file_path";
+	my ($exit_status, $output) = $self->execute($command);
+	if (!defined($output)) {
+		notify($ERRORS{'WARNING'}, 0, "failed to execute command to set $type-style line endings
for file: $file_path");
+		return;
+	}
+	elsif ($exit_status eq 0) {
+		notify($ERRORS{'DEBUG'}, 0, "set $type-style line endings for file: $file_path");
+		return 1;
+	}
+	else {
+		notify($ERRORS{'WARNING'}, 0, "failed to set $type-style line endings for file: $file_path,
exit status: $exit_status, output:\n@{$output}");
+		return;
+	}
+}
+
+#/////////////////////////////////////////////////////////////////////////////
 
 =head2 get_file_contents
 

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1645086&r1=1645085&r2=1645086&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Fri Dec 12 22:47:58 2014
@@ -6217,8 +6217,8 @@ sub add_group_policy_script {
 		return;
 	}
 	
-	# Run unix2dos on scripts.ini
-	$self->run_unix2dos($scripts_ini);
+	# Apply Windows-style line endings to scripts.ini
+	$self->set_text_file_line_endings($scripts_ini);
 	
 	# Get the modified contents of scripts.ini
 	my $cat_modified_command = "cat $scripts_ini";
@@ -6458,8 +6458,8 @@ sub remove_group_policy_script {
 		return;
 	}
 	
-	# Run unix2dos on scripts.ini
-	$self->run_unix2dos($scripts_ini);
+	# Apply Windows-style line endings to scripts.ini
+	$self->set_text_file_line_endings($scripts_ini);
 	
 	# Get the modified contents of scripts.ini
 	my $cat_modified_command = "cat $scripts_ini";
@@ -6571,44 +6571,33 @@ sub fix_cygwin_nodosfilewarning {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 run_unix2dos
+=head2 set_text_file_line_endings
 
- Parameters  : 
- Returns     :
- Description : 
+ Parameters  : $file_path, $line_ending (optional)
+ Returns     : boolean
+ Description : Changes the line endings of a text file. This is equivalent to
+               running unix2dos or dos2unix. The default line ending type is
+               Windows. Unix-style line endings will be applied if the
+					$line_ending argument is supplied and does not contain 'win' or
+					'r'.
 
 =cut
 
-sub run_unix2dos {
+sub set_text_file_line_endings {
 	my $self = shift;
-	if (ref($self) !~ /windows/i) {
+	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
 		return;
 	}
-
-	# Get the arguments
-	my $file_path = shift;
+	
+	my ($file_path, $line_ending) = @_;
 	if (!$file_path) {
-		notify($ERRORS{'WARNING'}, 0, "file path was not specified as an argument");
-		return;
-	}
-
-	# Run unix2dos on scripts.ini
-	my $unix2dos_command = "unix2dos $file_path";
-	my ($unix2dos_status, $unix2dos_output) = $self->execute($unix2dos_command);
-	if (defined($unix2dos_status) && $unix2dos_status == 0) {
-		notify($ERRORS{'DEBUG'}, 0, "ran unix2dos on $file_path");
-	}
-	elsif (defined($unix2dos_status)) {
-		notify($ERRORS{'WARNING'}, 0, "failed to run unix2dos on $file_path, exit status: $unix2dos_status,
output:\n@{$unix2dos_output}");
-		return;
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "unable to run ssh command to run unix2dos on $file_path");
+		notify($ERRORS{'WARNING'}, 0, "file path argument was not supplied");
 		return;
 	}
+	$line_ending = 'win' unless $line_ending;
 	
-	return 1;
+	return $self->SUPER::set_text_file_line_endings($file_path, $line_ending);
 }
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -6708,9 +6697,8 @@ sub search_and_replace_in_files {
 		else {
 			notify($ERRORS{'OK'}, 0, "replaced '$search_pattern' with '$replace_string' in $matching_file");
 			
-			# sed replaces Windows newlines with \n
-			# There is a sed -b option which prevents this but it is not available on all versions
of sed
-			$self->run_unix2dos($matching_file);
+			# Apply Windows-style line endings to scripts.ini
+			$self->set_text_file_line_endings($matching_file);
 		}
 	}
 	
@@ -11316,49 +11304,6 @@ sub get_installed_updates {
 }
 
 #/////////////////////////////////////////////////////////////////////////////
-
-=head2 format_text_file
-
- Parameters  : $file_path
- Returns     : boolean
- Description : Runs unix2dos on the text file to format the line endings for
-               Windows.
-
-=cut
-
-sub format_text_file {
-	my $self = shift;
-	if (ref($self) !~ /VCL::Module/) {
-		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
-		return;
-	}
-	
-	my $file_path = shift;
-	if (!$file_path) {
-		notify($ERRORS{'WARNING'}, 0, "file path argument was not specified");
-		return;
-	}
-	
-	my $computer_node_name = $self->data->get_computer_node_name();
-	
-	# Execute the command
-	my $command = "unix2dos \"$file_path\"";
-	my ($exit_status, $output) = $self->execute($command);
-	if (!defined($output)) {
-		notify($ERRORS{'WARNING'}, 0, "failed to format text file for Windows on $computer_node_name:
command: '$command'");
-		return;
-	}
-	elsif ($exit_status == 0) {
-		notify($ERRORS{'OK'}, 0, "formatted text file for Windows on $computer_node_name: '$file_path'");
-		return 1;
-	}
-	else {
-		notify($ERRORS{'WARNING'}, 0, "failed to format text file for Windows on $computer_node_name,
command: '$command'\noutput:\n" . join("\n", @$output));
-		return;
-	}
-}
-
-#/////////////////////////////////////////////////////////////////////////////
 
 =head2 get_user_names
 

Modified: vcl/trunk/managementnode/lib/VCL/Module/Provisioning.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Provisioning.pm?rev=1645086&r1=1645085&r2=1645086&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Provisioning.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Provisioning.pm Fri Dec 12 22:47:58 2014
@@ -187,7 +187,7 @@ sub node_status {
 	$status->{currentimagerevision_id} = $current_image_revision_id;
 
 	$status->{currentimage} = $self->data->get_computer_currentimage_name();
-	my $vcld_post_load_status = $self->data->get_computer_currentimage_vcld_post_load();
+	my $vcld_post_load_status = $self->data->get_computer_currentimage_vcld_post_load(0);
 	
 	if (!$current_image_revision_id) {
 		notify($ERRORS{'OK'}, 0, "unable to retrieve currentimage.txt contents on $computer_name,
returning 'RELOAD'");



Mime
View raw message