1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#!/usr/bin/perl -w
########################################################################
# Copyright 2004 by Malcolm Nooning
# This program does not impose any
# licensing restrictions on files generated by their execution, in
# accordance with the 8th article of the Artistic License:
#
# "Aggregation of this Package with a commercial distribution is
# always permitted provided that the use of this Package is embedded;
# that is, when no overt attempt is made to make this Package's
# interfaces visible to the end user of the commercial distribution.
# Such use shall not be construed as a distribution of this Package."
#
# Therefore, you are absolutely free to place any license on the resulting
# executable(s), as long as the packed 3rd-party libraries are also available
# under the Artistic License.
#
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# See L<http://www.perl.com/perl/misc/Artistic.html>
#
#
#
########################################################################
# Usage:
# $error = remove_file_and_try_executable_again
# (
# $file_to_remove,
# $test_number,
# $sub_test_number,
# $test_name_string,
# $test_dir,
# $pipe_command_string,
# $executable_name",
# $expected_results,
# $os,
# $verbose,
# \$message,
# $print_cannot_locate_message,
# );
#
########################################################################
########################################################################
our $VERSION = '0.07';
package remove_file_and_try_executable_again;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = ("remove_file_and_try_executable_again");
use POSIX qw(EXIT_SUCCESS EXIT_FAILURE);
use Cwd qw(chdir);
use pipe_a_command;
use strict;
#########################################################################
sub remove_file {
my ($file, $message_ref, $verbose) = @_;
if (-e($file)) {
if (!(unlink($file))) {
# Try a desparation chmod
chmod(0775, $file);
if (!(unlink($file))) {
$$message_ref = $$message_ref .
"\[620\]Cannot delete file $file \n";
return(EXIT_FAILURE);
}
}
if ($verbose) {
print ("\[625\]Removed file $file\n");
}
} else {
if ($verbose) {
print ("You wanted me to remove file $file\n");
print ("but it does not exist. Skipping \.\.\. \n");
}
}
return (EXIT_SUCCESS);
}
#########################################################################
sub remove_file_and_try_executable_again {
my (
$file_to_remove,
$test_number,
$sub_test,
$test_name_string,
$test_dir,
$command_string,
$executable_name,
$expected_result,
$os,
$verbose,
$message_ref,
$print_cannot_locate_message,
) = @_;
my $results = "";
my $error = EXIT_FAILURE;
$error = remove_file($file_to_remove, $message_ref, $verbose);
if ($error == EXIT_FAILURE) {
$$message_ref = "Test ${test_number}_${sub_test} : " . $$message_ref;
return ($error);
}
#.................................................................
$error = pipe_a_command(
$test_number,
$sub_test,
$test_name_string,
$test_dir,
$command_string,
$executable_name,
$expected_result,
$os,
$verbose,
$message_ref,
$print_cannot_locate_message,
);
return ($error);
}
#########################################################################
1;
|