This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=3f2c70454f0d3a225d36b80be55cd6cb917d76d8

commit 3f2c70454f0d3a225d36b80be55cd6cb917d76d8
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Oct 26 19:56:36 2022 +0200

    scripts: Switch to use file_dump() instead of open coding it
    
    Changelog: internal
---
 dselect/methods/Dselect/Ftp.pm  |  5 +----
 dselect/methods/ftp/install.pl  |  5 +----
 lib/dpkg/t/t-trigdeferred.t     | 11 ++---------
 scripts/Dpkg/Source/Quilt.pm    | 13 ++++---------
 scripts/t/Dpkg_IPC.t            |  6 +-----
 scripts/t/Dpkg_Source_Archive.t | 15 ++++++++-------
 scripts/t/dpkg_buildpackage.t   |  5 ++---
 scripts/t/dpkg_source.t         |  5 ++---
 8 files changed, 21 insertions(+), 44 deletions(-)

diff --git a/dselect/methods/Dselect/Ftp.pm b/dselect/methods/Dselect/Ftp.pm
index fdf903949..fb17076c2 100644
--- a/dselect/methods/Dselect/Ftp.pm
+++ b/dselect/methods/Dselect/Ftp.pm
@@ -91,10 +91,7 @@ sub store_config {
   # Check that config is completed
   return if not $CONFIG{done};
 
-  open(my $vars_fh, '>', $vars)
-    or die "couldn't open $vars in write mode: $!\n";
-  print { $vars_fh } Dumper(\%CONFIG);
-  close $vars_fh;
+  file_dump($vars, Dumper(\%CONFIG));
 }
 
 sub view_mirrors {
diff --git a/dselect/methods/ftp/install.pl b/dselect/methods/ftp/install.pl
index 6ffdb300e..aa6cecaa7 100755
--- a/dselect/methods/ftp/install.pl
+++ b/dselect/methods/ftp/install.pl
@@ -621,9 +621,6 @@ foreach my $file (keys %md5sums) {
   next if -f $file;
   delete $md5sums{$file};
 }
-open(my $md5sums_fh, '>', "$methdir/md5sums")
-  or die "can't open $methdir/md5sums in write mode: $!\n";
-print { $md5sums_fh } Dumper(\%md5sums);
-close $md5sums_fh;
+file_dump("$methdir/md5sums", Dumper(\%md5sums));
 
 exit $exit;
diff --git a/lib/dpkg/t/t-trigdeferred.t b/lib/dpkg/t/t-trigdeferred.t
index 8893a429f..bf7354139 100755
--- a/lib/dpkg/t/t-trigdeferred.t
+++ b/lib/dpkg/t/t-trigdeferred.t
@@ -26,6 +26,7 @@ use File::Temp qw(tempdir);
 use File::Basename;
 use File::Find;
 
+use Dpkg::File;
 use Dpkg::IPC;
 
 my $srcdir = $ENV{srcdir} || '.';
@@ -86,14 +87,6 @@ plan tests => scalar(@deferred) * 3;
 # Set a known umask.
 umask 0022;
 
-sub make_file {
-    my ($pathname, $text) = @_;
-
-    open my $fh, '>', $pathname or die "cannot touch $pathname: $!";
-    print { $fh } $text;
-    close $fh;
-}
-
 sub test_trigdeferred {
     my $stdout;
     my $stderr;
@@ -103,7 +96,7 @@ sub test_trigdeferred {
     make_path("$admindir/triggers");
 
     foreach my $test (@deferred) {
-        make_file("$admindir/triggers/Unincorp", $test->{original});
+        file_dump("$admindir/triggers/Unincorp", $test->{original});
 
         spawn(exec => [ "$builddir/t/c-trigdeferred", $admindir ],
               nocheck => 1, to_string => \$stdout, error_to_string => 
\$stderr);
diff --git a/scripts/Dpkg/Source/Quilt.pm b/scripts/Dpkg/Source/Quilt.pm
index fef709093..3e655fae9 100644
--- a/scripts/Dpkg/Source/Quilt.pm
+++ b/scripts/Dpkg/Source/Quilt.pm
@@ -29,6 +29,7 @@ use File::Basename;
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
+use Dpkg::File;
 use Dpkg::Source::Patch;
 use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time);
 use Dpkg::Vendor qw(get_current_vendor);
@@ -56,26 +57,20 @@ sub setup_db {
     }
     my $file = $self->get_db_file('.version');
     if (not -e $file) {
-        open(my $version_fh, '>', $file) or syserr(g_('cannot write %s'), 
$file);
-        print { $version_fh } "2\n";
-        close($version_fh);
+        file_dump($file, "2\n");
     }
     # The files below are used by quilt to know where patches are stored
     # and what file contains the patch list (supported by quilt >= 0.48-5
     # in Debian).
     $file = $self->get_db_file('.quilt_patches');
     if (not -e $file) {
-        open(my $qpatch_fh, '>', $file) or syserr(g_('cannot write %s'), 
$file);
-        print { $qpatch_fh } "debian/patches\n";
-        close($qpatch_fh);
+        file_dump($file, "debian/patches\n");
     }
     $file = $self->get_db_file('.quilt_series');
     if (not -e $file) {
-        open(my $qseries_fh, '>', $file) or syserr(g_('cannot write %s'), 
$file);
         my $series = $self->get_series_file();
         $series = (File::Spec->splitpath($series))[2];
-        print { $qseries_fh } "$series\n";
-        close($qseries_fh);
+        file_dump($file, "$series\n");
     }
 }
 
diff --git a/scripts/t/Dpkg_IPC.t b/scripts/t/Dpkg_IPC.t
index 6e2723b8c..450d98d07 100644
--- a/scripts/t/Dpkg_IPC.t
+++ b/scripts/t/Dpkg_IPC.t
@@ -26,15 +26,11 @@ use_ok('Dpkg::IPC');
 
 my ($tmp1_fh, $tmp1_name) = tempfile(UNLINK => 1);
 my ($tmp2_fh, $tmp2_name) = tempfile(UNLINK => 1);
-my $tmp_fh;
 
 my $string1 = "foo\nbar\n";
 my $string2;
 
-open $tmp_fh, '>', $tmp1_name
-    or die "cannot open $tmp1_name: $!";
-print { $tmp_fh } $string1;
-close $tmp_fh;
+file_dump($tmp1_name, $string1);
 
 my $pid = spawn(exec => 'cat',
                from_string => \$string1,
diff --git a/scripts/t/Dpkg_Source_Archive.t b/scripts/t/Dpkg_Source_Archive.t
index f6fe82fd8..dd887197a 100644
--- a/scripts/t/Dpkg_Source_Archive.t
+++ b/scripts/t/Dpkg_Source_Archive.t
@@ -27,6 +27,7 @@ BEGIN {
 }
 
 use Dpkg;
+use Dpkg::File;
 
 my $tmpdir = test_get_temp_path();
 
@@ -66,17 +67,17 @@ sub test_path_escape
     # base directory.
     make_path($overdir);
     make_path("$overdir/subdir-a/aa");
-    test_touch("$overdir/subdir-a/aa/file-aa", 'aa');
-    test_touch("$overdir/subdir-a/file-a", 'a');
+    file_dump("$overdir/subdir-a/aa/file-aa", 'aa');
+    file_dump("$overdir/subdir-a/file-a", 'a');
     make_path("$overdir/subdir-b/bb");
-    test_touch("$overdir/subdir-b/bb/file-bb", 'bb');
-    test_touch("$overdir/subdir-b/file-b", 'b');
+    file_dump("$overdir/subdir-b/bb/file-bb", 'bb');
+    file_dump("$overdir/subdir-b/file-b", 'b');
     make_path("$overdir/symlink-escape");
-    test_touch("$overdir/symlink-escape/escaped-file", 'escaped');
-    test_touch("$overdir/symlink-nonexistent", 'nonexistent');
+    file_dump("$overdir/symlink-escape/escaped-file", 'escaped');
+    file_dump("$overdir/symlink-nonexistent", 'nonexistent');
     make_path("$overdir/symlink-within");
     make_path("$overdir/supposed-dir");
-    test_touch("$overdir/supposed-dir/supposed-file", 'something');
+    file_dump("$overdir/supposed-dir/supposed-file", 'something');
 
     # Generate overlay tar.
     system($Dpkg::PROGTAR, '-cf', "$overdir.tar", '-C', $overdir, qw(
diff --git a/scripts/t/dpkg_buildpackage.t b/scripts/t/dpkg_buildpackage.t
index 47c6e184b..2b7244550 100644
--- a/scripts/t/dpkg_buildpackage.t
+++ b/scripts/t/dpkg_buildpackage.t
@@ -24,6 +24,7 @@ use File::Compare;
 use File::Path qw(make_path);
 use File::Copy;
 
+use Dpkg::File;
 use Dpkg::IPC;
 use Dpkg::Build::Types;
 use Dpkg::Substvars;
@@ -127,9 +128,7 @@ sub gen_from_tmpl
 {
     my ($pathname, $tmpl, $substvars) = @_;
 
-    open my $fh, '>', $pathname or die;
-    print { $fh } $substvars->substvars($tmpl);
-    close $fh or die;
+    file_dump($pathname, $substvars->substvars($tmpl));
 }
 
 sub gen_source
diff --git a/scripts/t/dpkg_source.t b/scripts/t/dpkg_source.t
index b766b374a..d251c1d2e 100644
--- a/scripts/t/dpkg_source.t
+++ b/scripts/t/dpkg_source.t
@@ -23,6 +23,7 @@ use File::Spec::Functions qw(rel2abs);
 use File::Compare;
 use File::Path qw(make_path);
 
+use Dpkg::File;
 use Dpkg::IPC;
 use Dpkg::Substvars;
 
@@ -91,9 +92,7 @@ sub gen_from_tmpl
 {
     my ($pathname, $tmpl, $substvars) = @_;
 
-    open my $fh, '>', $pathname or die;
-    print { $fh } $substvars->substvars($tmpl);
-    close $fh or die;
+    file_dump($pathname, $substvars->substvars($tmpl));
 }
 
 sub gen_source

-- 
Dpkg.Org's dpkg

Reply via email to