]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/Common.pm
add new_bug and overwrite file
[debbugs.git] / Debbugs / Common.pm
index ae3c844936dcf26c09293d80e0a2bd3a77ac2074..915fa859a7f8bd290f6037d3c8b17ab3fa757cf7 100644 (file)
@@ -39,7 +39,7 @@ BEGIN{
 
      @EXPORT = ();
      %EXPORT_TAGS = (util   => [qw(getbugcomponent getbuglocation getlocationpath get_hashname),
-                               qw(appendfile buglog getparsedaddrs getmaintainers),
+                               qw(appendfile overwritefile buglog getparsedaddrs getmaintainers),
                                qw(bug_status),
                                qw(getmaintainers_reverse),
                                qw(getpseudodesc),
@@ -218,6 +218,28 @@ sub appendfile {
        close $fh or die "Unable to close $file: $!";
 }
 
+=head2 overwritefile
+
+     ovewritefile($file,'data','to','append');
+
+Opens file.new, writes data to it, then moves file.new to file.
+
+=cut
+
+sub overwritefile {
+       my ($file,@data) = @_;
+       my $fh = IO::File->new("${file}.new",'w') or
+            die "Unable top open ${file}.new for writing: $!";
+       print {$fh} @data or die "Unable to write to ${file}.new: $!";
+       close $fh or die "Unable to close ${file}.new: $!";
+       rename("${file}.new",$file) or
+           die "Unable to rename ${file}.new to $file: $!";
+}
+
+
+
+
+
 =head2 getparsedaddrs
 
      my $address = getparsedaddrs($address);