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=c7bb4e157d0776fed7160d770b667ddf6b83cd58

commit c7bb4e157d0776fed7160d770b667ddf6b83cd58
Author: Guillem Jover <[email protected]>
AuthorDate: Mon Aug 25 12:26:58 2025 +0200

    perl: Switch from tempfile()/tempdir() to OOP File::Temp interfaces
    
    But do not switch yet to use its UNLINK and CLEANUP support, as we are
    currently handling that through our exit handlers, which take care of
    removing the temporary objects also after signal interruption.
    
    This also gets rid of the unused filehandle variables.
---
 scripts/Dpkg/Source/Archive.pm           |  8 +++++---
 scripts/Dpkg/Source/Package/V1.pm        | 16 +++++++++++-----
 scripts/Dpkg/Source/Package/V2.pm        | 15 +++++++++++----
 scripts/Dpkg/Source/Package/V3/Bzr.pm    |  8 ++++++--
 scripts/Dpkg/Source/Package/V3/Git.pm    |  8 ++++++--
 scripts/Dpkg/Source/Package/V3/Native.pm |  9 ++++++---
 scripts/t/Dpkg_IPC.t                     | 20 ++++++++++----------
 7 files changed, 55 insertions(+), 29 deletions(-)

diff --git a/scripts/Dpkg/Source/Archive.pm b/scripts/Dpkg/Source/Archive.pm
index d39d8874e..9ff968086 100644
--- a/scripts/Dpkg/Source/Archive.pm
+++ b/scripts/Dpkg/Source/Archive.pm
@@ -34,7 +34,7 @@ use v5.36;
 
 use Carp;
 use Errno qw(ENOENT);
-use File::Temp qw(tempdir);
+use File::Temp;
 use File::Basename qw(basename);
 use File::Spec;
 use File::Find;
@@ -129,12 +129,14 @@ sub extract {
     my %spawn_opts = (wait_child => 1);
 
     # Prepare destination
-    my $template = basename($self->get_filename()) .  '.tmp-extract.XXXXX';
     unless (-e $dest) {
         # Kludge so that realpath works
         mkdir($dest) or syserr(g_('cannot create directory %s'), $dest);
     }
-    my $tmpdir = tempdir($template, DIR => Cwd::realpath("$dest/.."), CLEANUP 
=> 1);
+    my $tmpdir = File::Temp->newdir(
+        TEMPLATE => basename($self->get_filename()) . '.tmp-extract.XXXXX',
+        DIR => Cwd::realpath("$dest/.."),
+    );
     $spawn_opts{chdir} = $tmpdir;
 
     # Prepare stuff that handles the input of tar
diff --git a/scripts/Dpkg/Source/Package/V1.pm 
b/scripts/Dpkg/Source/Package/V1.pm
index a2defe48d..3f823c3cc 100644
--- a/scripts/Dpkg/Source/Package/V1.pm
+++ b/scripts/Dpkg/Source/Package/V1.pm
@@ -35,7 +35,7 @@ use v5.36;
 use Errno qw(ENOENT);
 use Cwd;
 use File::Basename;
-use File::Temp qw(tempfile);
+use File::Temp;
 use File::Spec;
 
 use Dpkg ();
@@ -432,8 +432,11 @@ sub do_build {
        info(g_('building %s in %s'),
             $sourcepackage, $tarname);
 
-       my ($ntfh, $newtar) = tempfile("$tarname.new.XXXXXX",
-                                      DIR => getcwd(), UNLINK => 0);
+        my $newtar = File::Temp->new(
+            TEMPLATE => "$tarname.new.XXXXXX",
+            DIR => getcwd(),
+            UNLINK => 0,
+        );
        my $tar = Dpkg::Source::Archive->new(filename => $newtar,
                    compression => compression_guess_from_filename($tarname),
                    compression_level => $self->{options}{comp_level});
@@ -490,8 +493,11 @@ sub do_build {
        my $diffname = "$basenamerev.diff.gz";
        info(g_('building %s in %s'),
             $sourcepackage, $diffname);
-       my ($ndfh, $newdiffgz) = tempfile("$diffname.new.XXXXXX",
-                                       DIR => getcwd(), UNLINK => 0);
+        my $newdiffgz = File::Temp->new(
+            TEMPLATE => "$diffname.new.XXXXXX",
+            DIR => getcwd(),
+            UNLINK => 0,
+        );
         push_exit_handler(sub { unlink($newdiffgz) });
         my $diff = Dpkg::Source::Patch->new(filename => $newdiffgz,
                                             compression => 'gzip',
diff --git a/scripts/Dpkg/Source/Package/V2.pm 
b/scripts/Dpkg/Source/Package/V2.pm
index f36b75507..059c33b6c 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -35,7 +35,7 @@ use v5.36;
 use List::Util qw(first);
 use Cwd;
 use File::Basename;
-use File::Temp qw(tempfile tempdir);
+use File::Temp;
 use File::Path qw(make_path);
 use File::Spec;
 use File::Find;
@@ -470,7 +470,11 @@ sub _generate_patch {
     }
 
     # Unpack a second copy for comparison
-    my $tmpdir = tempdir("$dirname.orig.XXXXXX", DIR => $updir);
+    my $tmpdir = File::Temp->newdir(
+        TEMPLATE => "$dirname.orig.XXXXXX",
+        DIR => $updir,
+        CLEANUP => 0,
+    );
     push_exit_handler(sub { erasedir($tmpdir) });
 
     # Extract main tarball
@@ -494,8 +498,11 @@ sub _generate_patch {
     $self->apply_patches($tmpdir, skip_auto => $opts{skip_auto}, usage => 
'build');
 
     # Create a patch
-    my ($difffh, $tmpdiff) = tempfile($self->get_basename(1) . '.diff.XXXXXX',
-                                      TMPDIR => 1, UNLINK => 0);
+    my $tmpdiff = File::Temp->new(
+        TEMPLATE => $self->get_basename(1) . '.diff.XXXXXX',
+        TMPDIR => 1,
+        UNLINK => 0,
+    );
     push_exit_handler(sub { unlink($tmpdiff) });
     my $diff = Dpkg::Source::Patch->new(filename => $tmpdiff,
                                         compression => 'none');
diff --git a/scripts/Dpkg/Source/Package/V3/Bzr.pm 
b/scripts/Dpkg/Source/Package/V3/Bzr.pm
index d5e33e7d8..db8774980 100644
--- a/scripts/Dpkg/Source/Package/V3/Bzr.pm
+++ b/scripts/Dpkg/Source/Package/V3/Bzr.pm
@@ -38,7 +38,7 @@ use Cwd;
 use File::Basename;
 use File::Spec;
 use File::Find;
-use File::Temp qw(tempdir);
+use File::Temp;
 
 use Dpkg::Gettext;
 use Dpkg::Compression;
@@ -138,7 +138,11 @@ sub do_build {
 
     chdir $old_cwd or syserr(g_("unable to chdir to '%s'"), $old_cwd);
 
-    my $tmpdir = tempdir("$dirname.bzr.XXXXXX", DIR => $updir);
+    my $tmpdir = File::Temp->newdir(
+        TEMPLATE => "$dirname.bzr.XXXXXX",
+        DIR => $updir,
+        CLEANUP => 0,
+    );
     push_exit_handler(sub { erasedir($tmpdir) });
     my $tardir = "$tmpdir/$dirname";
 
diff --git a/scripts/Dpkg/Source/Package/V3/Git.pm 
b/scripts/Dpkg/Source/Package/V3/Git.pm
index 0a9fd661d..445d2fdac 100644
--- a/scripts/Dpkg/Source/Package/V3/Git.pm
+++ b/scripts/Dpkg/Source/Package/V3/Git.pm
@@ -35,7 +35,7 @@ use v5.36;
 use Cwd qw(abs_path getcwd);
 use File::Basename;
 use File::Spec;
-use File::Temp qw(tempdir);
+use File::Temp;
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
@@ -191,7 +191,11 @@ sub do_build {
     my $shallowfile;
     if ($self->{options}{git_depth}) {
         chdir $old_cwd or syserr(g_("unable to chdir to '%s'"), $old_cwd);
-        $tmpdir = tempdir("$dirname.git.XXXXXX", DIR => $updir);
+        $tmpdir = File::Temp->newdir(
+            TEMPLATE => "$dirname.git.XXXXXX",
+            DIR => $updir,
+            CLEANUP => 0,
+        );
         push_exit_handler(sub { erasedir($tmpdir) });
         my $clone_dir = "$tmpdir/repo.git";
         # file:// is needed to avoid local cloning, which does not
diff --git a/scripts/Dpkg/Source/Package/V3/Native.pm 
b/scripts/Dpkg/Source/Package/V3/Native.pm
index 8ca6b4c55..0d69df34c 100644
--- a/scripts/Dpkg/Source/Package/V3/Native.pm
+++ b/scripts/Dpkg/Source/Package/V3/Native.pm
@@ -34,7 +34,7 @@ use v5.36;
 use Cwd;
 use File::Basename;
 use File::Spec;
-use File::Temp qw(tempfile);
+use File::Temp;
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
@@ -119,8 +119,11 @@ sub do_build {
 
     info(g_('building %s in %s'), $sourcepackage, $tarname);
 
-    my ($ntfh, $newtar) = tempfile("$tarname.new.XXXXXX",
-                                   DIR => getcwd(), UNLINK => 0);
+    my $newtar = File::Temp->new(
+        TEMPLATE => "$tarname.new.XXXXXX",
+        DIR => getcwd(),
+        UNLINK => 0,
+    );
     push_exit_handler(sub { unlink($newtar) });
 
     my ($dirname, $dirbase) = fileparse($dir);
diff --git a/scripts/t/Dpkg_IPC.t b/scripts/t/Dpkg_IPC.t
index 3ffa753c2..2d238d7a1 100644
--- a/scripts/t/Dpkg_IPC.t
+++ b/scripts/t/Dpkg_IPC.t
@@ -17,19 +17,19 @@ use v5.36;
 
 use Test::More tests => 8;
 
-use File::Temp qw(tempfile);
+use File::Temp;
 
 use Dpkg::File;
 
 use_ok('Dpkg::IPC');
 
-my ($tmp1_fh, $tmp1_name) = tempfile(UNLINK => 1);
-my ($tmp2_fh, $tmp2_name) = tempfile(UNLINK => 1);
+my $tmpfile1 = File::Temp->new();
+my $tmpfile2 = File::Temp->new();
 
 my $string1 = "foo\nbar\n";
 my $string2;
 
-file_dump($tmp1_name, $string1);
+file_dump("$tmpfile1", $string1);
 
 my $pid = spawn(exec => 'cat',
                from_string => \$string1,
@@ -40,25 +40,25 @@ ok($pid, 'execute cat program, I/O to variables');
 is($string2, $string1, '{from,to}_string');
 
 $pid = spawn(exec => 'cat',
-            from_handle => $tmp1_fh,
-            to_handle => $tmp2_fh);
+            from_handle => $tmpfile1,
+            to_handle => $tmpfile2);
 
 ok($pid, 'execute cat program, I/O to filehandles');
 
 wait_child($pid);
 
-$string2 = file_slurp($tmp2_name);
+$string2 = file_slurp("$tmpfile2");
 
 is($string2, $string1, '{from,to}_handle');
 
 $pid = spawn(exec => 'cat',
-            from_file => $tmp1_name,
-            to_file => $tmp2_name,
+            from_file => $tmpfile1,
+            to_file => $tmpfile2,
             wait_child => 1);
 
 ok($pid, 'execute cat program, I/O to filenames and wait');
 
-$string2 = file_slurp($tmp2_name);
+$string2 = file_slurp("$tmpfile2");
 
 is($string2, $string1, '{from,to}_file');
 

-- 
Dpkg.Org's dpkg

Reply via email to