summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2003-05-12 12:40:49 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2003-05-12 12:40:49 +0000
commitbedffd0471e4bc66249947821c9f2826f091c1d0 (patch)
treef44f0df96140351ceaa4782c8983e1f9635790b5
parent5d763d892e043026facf45a91ee0c4b93568afb9 (diff)
downloadMPC-bedffd0471e4bc66249947821c9f2826f091c1d0.tar.gz
ChangeLogTag: Mon May 12 07:39:29 2003 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r--modules/ProjectCreator.pm32
1 files changed, 28 insertions, 4 deletions
diff --git a/modules/ProjectCreator.pm b/modules/ProjectCreator.pm
index 3ef0a66d..3657771c 100644
--- a/modules/ProjectCreator.pm
+++ b/modules/ProjectCreator.pm
@@ -13,6 +13,7 @@ package ProjectCreator;
use strict;
use FileHandle;
use File::Path;
+use File::Compare;
use File::Basename;
use Creator;
@@ -1743,19 +1744,42 @@ sub write_output_file {
mkpath($dir, 0, 0777);
}
- if (open($fh, ">$name")) {
+ ## First write the output to a temporary file
+ my($tmp) = "MPC$>.$$";
+ my($different) = 1;
+ if (open($fh, ">$tmp")) {
my($lines) = $tp->get_lines();
foreach my $line (@$lines) {
print $fh $line;
}
close($fh);
-
- $self->add_file_written($name);
+ if (compare($tmp, $name) == 0) {
+ $different = 0;
+ }
}
else {
- $error = "ERROR: Unable to open $name for output.";
+ $error = "ERROR: Unable to open $tmp for output.";
$status = 0;
}
+
+ if ($status) {
+ ## If they are different, then rename the temporary file
+ if ($different) {
+ unlink($name);
+ if (rename($tmp, $name)) {
+ $self->add_file_written($name);
+ }
+ else {
+ $error = "ERROR: Unable to open $name for output.";
+ $status = 0;
+ }
+ }
+ else {
+ ## We will pretend that we wrote the file
+ unlink($tmp);
+ $self->add_file_written($name);
+ }
+ }
}
}
}