[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH/dpkg-cross] make use of standard perl ways of creating temporary files and directories



This patch uses safer and faster method of creating temporary things.

--- dpkg-cross/dpkg-cross.pl.orig       2006-06-02 16:18:23.000000000 +0200
+++ dpkg-cross/dpkg-cross.pl    2006-06-12 18:45:29.000000000 +0200
@@ -19,6 +19,8 @@
#
#  $Id: dpkg-cross.pl,v 1.39 2006/04/18 07:14:35 yoush-guest Exp $

+use File::Temp qw/tempfile tempdir/;
+
# Determine if the system wide or user defined cross-compile configuration
# have to be read.
$conffile = "/etc/dpkg-cross/cross-compile";
@@ -372,11 +378,11 @@
                               my $obj_ = `ar t "$file_" 2>/dev/null
| head -n1`;
                               chomp($obj_);   # remove newline
                               if ($obj_) {
-                                       my $tmp_ = `tempfile`;
-                                       chomp($tmp_);   # remove newline
+                                       my ($fh_, $tmp_) =
tempfile(DIR => $ENV{'TMPDIR'} || '/tmp');
                                       if (system("ar p \"$file_\"
\"$obj_\" > $tmp_ 2>/dev/null") =
= 0) {
                                               $arch_ = detect_arch($tmp_);
                                       }
+                                       close $fh_;
                                       unlink($tmp_);
                               }
                       }
@@ -635,17 +646,17 @@
# $1: Directory basename (random suffix will be added)
# return: Full directory pathname, undef if failed
sub create_tmpdir ($) {
-       my ($pd, $d, $b, $try);
-       $b = $_[0];
-       $pd = $ENV{'TMPDIR'};
-       $pd = '/tmp' if ((!$pd) || (! -d $pd));
-       $try = 0;
-       while ($try < 100) {
-               $d = $pd . '/' . $b . '.' . sprintf("%08x",
int(rand(0xFFFFFFFF)));
-               return $d if mkdir($d, 0700);
-               $try++;
-       }
-       return undef;
+       my $name = shift;
+       my $pd = $ENV{'TMPDIR'} && -d $ENV{'TMPDIR'}
+               ? $ENV{'TMPDIR'}
+               : '/tmp';
+       return undef unless -d $pd;
+       my $dir;
+
+       eval { $dir = tempdir("$name.XXXXXXXX", DIR => $pd) };
+       print("$@"), return undef if $@;
+
+       return $dir;
}

1;



Reply to: