Hi Josch, Here's an updated patch.
Now .changes.new is written to $build_dir, then renamed to .changes, and copied from the chroot to sys_build_dir. I removed the call to unlink() since we want to keep the .changes file in $build_dir so it can be used by lintian. Also, I saw in HACKING that the emacs perl-mode style is used. I don't use emacs, and unfortunately a web search didn't turn up the specifics of what that styling entails. So I tried to match the style the best I could. Apologies if it's off slightly. Let me know if you see any issues with the patch. Thanks, Bill
diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm index f5660148..5e60436f 100644 --- a/lib/Sbuild/Build.pm +++ b/lib/Sbuild/Build.pm @@ -2601,8 +2601,9 @@ sub build { } my $sys_build_dir = $self->get_conf('BUILD_DIR'); - if (!open( F2, ">$sys_build_dir/$changes.new" )) { - $self->log("Cannot create $sys_build_dir/$changes.new: $!\n"); + my $F2 = $session->get_write_file_handle("$build_dir/$changes.new"); + if (!$F2) { + $self->log("Cannot create $build_dir/$changes.new\n"); $self->log("Distribution field may be wrong!!!\n"); if ($build_dir) { if(!$session->copy_from_chroot("$build_dir/$changes", ".")) { @@ -2611,14 +2612,21 @@ sub build { } } else { $pchanges->output(\*STDOUT); - $pchanges->output(\*F2); - - close( F2 ); - rename("$sys_build_dir/$changes.new", "$sys_build_dir/$changes") - or $self->log("$sys_build_dir/$changes.new could not be " . - "renamed to $sys_build_dir/$changes: $!\n"); - unlink("$build_dir/$changes") - if $build_dir; + $pchanges->output(\*$F2); + + close( $F2 ); + + $session->rename("$build_dir/$changes.new", "$build_dir/$changes"); + if ($? == 0) { + $self->log("$build_dir/$changes.new could not be " . + "renamed to $build_dir/$changes: $!\n"); + $self->log("Distribution field may be wrong!!!"); + } + if ($build_dir) { + if (!$session->copy_from_chroot("$build_dir/$changes", "$sys_build_dir")) { + $self->log("Could not copy $build_dir/$changes to $sys_build_dir"); + } + } } return $pchanges;