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=5715e867b386c80ac4273da5cb96c0638d849e1d

commit 5715e867b386c80ac4273da5cb96c0638d849e1d
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Oct 26 20:19:56 2022 +0200

    scripts: Switch to use file_touch() instead of open coding it
    
    Changelog: internal
---
 lib/dpkg/t/t-tarextract.t               | 12 ++-----
 lib/dpkg/t/t-treewalk.t                 | 60 +++++++++++++++------------------
 scripts/Dpkg/Source/Functions.pm        |  4 +--
 scripts/Dpkg/Source/Package/V3/Quilt.pm |  5 ++-
 scripts/t/Dpkg_Path.t                   | 14 +++-----
 scripts/t/Dpkg_Source_Archive.t         | 20 +++--------
 6 files changed, 43 insertions(+), 72 deletions(-)

diff --git a/lib/dpkg/t/t-tarextract.t b/lib/dpkg/t/t-tarextract.t
index a691c9601..5499cdc1c 100755
--- a/lib/dpkg/t/t-tarextract.t
+++ b/lib/dpkg/t/t-tarextract.t
@@ -24,6 +24,7 @@ use File::Find;
 use POSIX qw(mkfifo);
 
 use Dpkg ();
+use Dpkg::File;
 use Dpkg::IPC;
 
 use strict;
@@ -47,13 +48,6 @@ if ($tar_version and $tar_version =~ m/^tar \(GNU tar\) 
(\d+\.\d+)/ and
 # Set a known umask.
 umask 0022;
 
-sub create {
-    my ($pathname) = @_;
-
-    open my $fh, '>>', $pathname or die "cannot touch $pathname: $!";
-    close $fh;
-}
-
 sub tar_create_tree {
     my $type = shift;
 
@@ -65,12 +59,12 @@ sub tar_create_tree {
     my $long_f = 'f' x 22;
 
     # Populate tar hierarchy
-    create('file');
+    file_touch('file');
     link 'file', 'hardlink';
 
     make_path("$long_a/$long_b/$long_c/$long_d/$long_e/");
     make_path("$long_a/$long_b/$long_c/$long_d/$long_e/$long_f/");
-    create("$long_a/$long_b/$long_c/$long_d/$long_e/$long_f/long");
+    file_touch("$long_a/$long_b/$long_c/$long_d/$long_e/$long_f/long");
 
     # POSIX specifies that symlinks have undefined permissions in their
     # mode, so their handling is system dependent. Linux does not honor
diff --git a/lib/dpkg/t/t-treewalk.t b/lib/dpkg/t/t-treewalk.t
index 7061ae7b8..573103d34 100755
--- a/lib/dpkg/t/t-treewalk.t
+++ b/lib/dpkg/t/t-treewalk.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} || '.';
@@ -35,13 +36,6 @@ my $tmpdir = 't.tmp/t-treewalk';
 # Set a known umask.
 umask 0022;
 
-sub make_file {
-    my ($pathname) = @_;
-
-    open my $fh, '>>', $pathname or die "cannot touch $pathname: $!";
-    close $fh;
-}
-
 # Populate the tree hierarchy.
 sub make_tree {
     my ($dirtree) = @_;
@@ -52,60 +46,60 @@ sub make_tree {
 
     # Deep tree.
     make_path('aaaa/aaaa/aaaa/aaaa/');
-    make_file('aaaa/aaaa/aaaa/aaaa/abcde');
-    make_file('aaaa/aaaa/aaaa/aaaa/ddddd');
-    make_file('aaaa/aaaa/aaaa/aaaa/wwwwa');
-    make_file('aaaa/aaaa/aaaa/aaaa/wwwwz');
-    make_file('aaaa/aaaa/aaaa/aaaa/zzzzz');
+    file_touch('aaaa/aaaa/aaaa/aaaa/abcde');
+    file_touch('aaaa/aaaa/aaaa/aaaa/ddddd');
+    file_touch('aaaa/aaaa/aaaa/aaaa/wwwwa');
+    file_touch('aaaa/aaaa/aaaa/aaaa/wwwwz');
+    file_touch('aaaa/aaaa/aaaa/aaaa/zzzzz');
 
     # Shallow tree.
     make_path('bbbb/');
-    make_file('bbbb/abcde');
-    make_file('bbbb/ddddd');
-    make_file('bbbb/wwwwa');
-    make_file('bbbb/wwwwz');
-    make_file('bbbb/zzzzz');
+    file_touch('bbbb/abcde');
+    file_touch('bbbb/ddddd');
+    file_touch('bbbb/wwwwa');
+    file_touch('bbbb/wwwwz');
+    file_touch('bbbb/zzzzz');
 
     # Populated tree.
     make_path('cccc/aa/aa/aa/');
     make_path('cccc/aa/aa/bb/aa/');
-    make_file('cccc/aa/aa/bb/aa/file-a');
-    make_file('cccc/aa/aa/bb/aa/file-z');
+    file_touch('cccc/aa/aa/bb/aa/file-a');
+    file_touch('cccc/aa/aa/bb/aa/file-z');
     make_path('cccc/aa/bb/');
     make_path('cccc/bb/aa/');
     make_path('cccc/bb/bb/aa/aa/');
-    make_file('cccc/bb/bb/aa/aa/file-a');
-    make_file('cccc/bb/bb/aa/aa/file-z');
+    file_touch('cccc/bb/bb/aa/aa/file-a');
+    file_touch('cccc/bb/bb/aa/aa/file-z');
     make_path('cccc/bb/bb/bb/');
-    make_file('cccc/bb/bb/bb/file-w');
+    file_touch('cccc/bb/bb/bb/file-w');
     make_path('cccc/cc/aa/');
     make_path('cccc/cc/bb/aa/');
-    make_file('cccc/cc/bb/aa/file-t');
+    file_touch('cccc/cc/bb/aa/file-t');
     make_path('cccc/cc/bb/bb/');
-    make_file('cccc/cc/bb/bb/file-x');
+    file_touch('cccc/cc/bb/bb/file-x');
     make_path('cccc/cc/cc/');
     make_path('cccc/dd/aa/aa/aa/');
-    make_file('cccc/dd/aa/aa/aa/file-y');
+    file_touch('cccc/dd/aa/aa/aa/file-y');
     make_path('cccc/dd/aa/aa/bb/');
-    make_file('cccc/dd/aa/aa/bb/file-o');
+    file_touch('cccc/dd/aa/aa/bb/file-o');
     make_path('cccc/dd/aa/bb/aa/');
-    make_file('cccc/dd/aa/bb/aa/file-k');
+    file_touch('cccc/dd/aa/bb/aa/file-k');
     make_path('cccc/dd/aa/bb/bb/');
-    make_file('cccc/dd/aa/bb/bb/file-l');
+    file_touch('cccc/dd/aa/bb/bb/file-l');
     make_path('cccc/dd/aa/cc/aa/');
-    make_file('cccc/dd/aa/cc/aa/file-s');
+    file_touch('cccc/dd/aa/cc/aa/file-s');
     make_path('cccc/dd/aa/cc/bb/');
-    make_file('cccc/dd/aa/cc/bb/file-u');
+    file_touch('cccc/dd/aa/cc/bb/file-u');
 
     # Tree with symlinks cycles.
     make_path('llll/self/');
-    make_file('llll/file');
+    file_touch('llll/file');
     symlink '..', 'llll/self/loop';
     make_path('llll/real/');
-    make_file('llll/real/file-r');
+    file_touch('llll/real/file-r');
     symlink '../virt', 'llll/real/loop';
     make_path('llll/virt/');
-    make_file('llll/virt/file-v');
+    file_touch('llll/virt/file-v');
     symlink '../real', 'llll/virt/loop';
 
     chdir $cwd;
diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm
index 3435f6c5a..0576657ea 100644
--- a/scripts/Dpkg/Source/Functions.pm
+++ b/scripts/Dpkg/Source/Functions.pm
@@ -32,6 +32,7 @@ use Errno qw(ENOENT);
 
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
+use Dpkg::File;
 use Dpkg::IPC;
 
 sub erasedir {
@@ -94,8 +95,7 @@ sub fs_time($) {
     my $file = shift;
     my $is_temp = 0;
     if (not -e $file) {
-       open(my $temp_fh, '>', $file) or syserr(g_('cannot write %s'));
-       close($temp_fh);
+        file_touch($file);
        $is_temp = 1;
     } else {
        utime(undef, undef, $file) or
diff --git a/scripts/Dpkg/Source/Package/V3/Quilt.pm 
b/scripts/Dpkg/Source/Package/V3/Quilt.pm
index 45237d26a..1359168d6 100644
--- a/scripts/Dpkg/Source/Package/V3/Quilt.pm
+++ b/scripts/Dpkg/Source/Package/V3/Quilt.pm
@@ -26,6 +26,7 @@ use File::Copy;
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
+use Dpkg::File;
 use Dpkg::Version;
 use Dpkg::Source::Patch;
 use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time);
@@ -149,9 +150,7 @@ sub apply_patches {
         # We're applying the patches in --before-build, remember to unapply
         # them afterwards in --after-build
         my $pc_unapply = $quilt->get_db_file('.dpkg-source-unapply');
-        open(my $unapply_fh, '>', $pc_unapply)
-            or syserr(g_('cannot write %s'), $pc_unapply);
-        close($unapply_fh);
+        file_touch($pc_unapply);
     }
 
     # Apply patches
diff --git a/scripts/t/Dpkg_Path.t b/scripts/t/Dpkg_Path.t
index 33d1f9267..0b0d6bdfe 100644
--- a/scripts/t/Dpkg_Path.t
+++ b/scripts/t/Dpkg_Path.t
@@ -23,6 +23,8 @@ use Cwd qw(realpath);
 use File::Path qw(make_path rmtree);
 use File::Spec::Functions qw(abs2rel);
 
+use Dpkg::File;
+
 use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
        'check_files_are_the_same',
        'check_directory_traversal',
@@ -31,14 +33,6 @@ use_ok('Dpkg::Path', 'canonpath', 'resolve_symlink',
 
 my $tmpdir = test_get_temp_path();
 
-sub gen_file
-{
-    my ($pathname) = @_;
-
-    open my $fh, '>', $pathname or BAIL_OUT("cannot create file $pathname");
-    close $fh;
-}
-
 make_path("$tmpdir/a/b/c");
 make_path("$tmpdir/a/DEBIAN");
 make_path("$tmpdir/debian/a/b/c");
@@ -62,8 +56,8 @@ sub gen_hier_travbase {
     my $basedir = shift;
 
     make_path("$basedir/subdir");
-    gen_file("$basedir/file");
-    gen_file("$basedir/subdir/subfile");
+    file_touch("$basedir/file");
+    file_touch("$basedir/subdir/subfile");
     symlink 'file', "$basedir/symlink-file";
     symlink 'subdir/subfile', "$basedir/symlink-subfile";
 }
diff --git a/scripts/t/Dpkg_Source_Archive.t b/scripts/t/Dpkg_Source_Archive.t
index dd887197a..4e77aef39 100644
--- a/scripts/t/Dpkg_Source_Archive.t
+++ b/scripts/t/Dpkg_Source_Archive.t
@@ -31,16 +31,6 @@ use Dpkg::File;
 
 my $tmpdir = test_get_temp_path();
 
-sub test_touch
-{
-    my ($name, $data) = @_;
-
-    open my $fh, '>', $name
-        or die "cannot touch file $name\n";
-    print { $fh } $data if $data;
-    close $fh;
-}
-
 sub test_path_escape
 {
     my $name = shift;
@@ -53,15 +43,15 @@ sub test_path_escape
     # This is the base directory, where we are going to be extracting stuff
     # into, which include traps.
     make_path("$treedir/subdir-a");
-    test_touch("$treedir/subdir-a/file-a");
-    test_touch("$treedir/subdir-a/file-pre-a");
+    file_touch("$treedir/subdir-a/file-a");
+    file_touch("$treedir/subdir-a/file-pre-a");
     make_path("$treedir/subdir-b");
-    test_touch("$treedir/subdir-b/file-b");
-    test_touch("$treedir/subdir-b/file-pre-b");
+    file_touch("$treedir/subdir-b/file-b");
+    file_touch("$treedir/subdir-b/file-pre-b");
     symlink File::Spec->abs2rel($outdir, $treedir), "$treedir/symlink-escape";
     symlink File::Spec->abs2rel("$outdir/nonexistent", $treedir), 
"$treedir/symlink-nonexistent";
     symlink "$treedir/file", "$treedir/symlink-within";
-    test_touch("$treedir/supposed-dir");
+    file_touch("$treedir/supposed-dir");
 
     # This is the overlay directory, which we'll pack and extract over the
     # base directory.

-- 
Dpkg.Org's dpkg

Reply via email to