[dpkg] 110/192: Dselect::Ftp: Avoid many function arguments in do_connect()

Ximin Luo infinity0 at debian.org
Tue Oct 17 11:04:06 UTC 2017


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

infinity0 pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 417c80f6fbc6673aac6c42bb1fdc3e0280b01cd1
Author: Guillem Jover <guillem at debian.org>
Date:   Thu Aug 31 03:29:53 2017 +0200

    Dselect::Ftp: Avoid many function arguments in do_connect()
    
    Addresses: Subroutines::ProhibitManyArgs
    Warned-by: perlcritic
---
 debian/changelog               |  1 +
 dselect/methods/Dselect/Ftp.pm | 38 ++++++++++++++++++++------------------
 dselect/methods/ftp/install.pl | 18 +++++++++---------
 dselect/methods/ftp/setup.pl   | 18 +++++++++---------
 dselect/methods/ftp/update.pl  | 36 ++++++++++++++++++------------------
 5 files changed, 57 insertions(+), 54 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6dc7ee2..cbfa61f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -35,6 +35,7 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
     - Move color setup into report_pretty in Dpkg::ErrorHandling.
     - Move printforhelp initialization into usageerr() in Dpkg::ErrorHandling.
     - Avoid many function arguments in Dpkg::Shlibs::SymbolFile parse().
+    - Avoid many function arguments in Dselect::Ftp do_connect().
   * Documentation:
     - Document currently accepted syntax for changelogs in deb-changelog(5).
       Closes: #858579
diff --git a/dselect/methods/Dselect/Ftp.pm b/dselect/methods/Dselect/Ftp.pm
index 1c326c4..acd32d1 100644
--- a/dselect/methods/Dselect/Ftp.pm
+++ b/dselect/methods/Dselect/Ftp.pm
@@ -228,8 +228,7 @@ sub yesno($$) {
 ##############################
 
 sub do_connect {
-    my($ftpsite,$username,$pass,$ftpdir,$passive,
-       $useproxy,$proxyhost,$proxylogname,$proxypassword) = @_;
+    my (%opts) = @_;
 
     my($rpass,$remotehost,$remoteuser,$ftp);
 
@@ -237,28 +236,28 @@ sub do_connect {
     while(1) {
 	my $exit = 0;
 
-	if ($useproxy) {
-	    $remotehost = $proxyhost;
-	    $remoteuser = $username . '@' . $ftpsite;
+	if ($opts{useproxy}) {
+	    $remotehost = $opts{proxyhost};
+	    $remoteuser = $opts{username} . '@' . $opts{ftpsite};
 	} else {
-	    $remotehost = $ftpsite;
-	    $remoteuser = $username;
+	    $remotehost = $opts{ftpsite};
+	    $remoteuser = $opts{username};
 	}
-	print "Connecting to $ftpsite...\n";
-	$ftp = Net::FTP->new($remotehost, Passive => $passive);
+	print "Connecting to $opts{ftpsite}...\n";
+	$ftp = Net::FTP->new($remotehost, Passive => $opts{passive});
 	if(!$ftp || !$ftp->ok) {
 	  print "Failed to connect\n";
 	  $exit=1;
 	}
 	if (!$exit) {
 #    $ftp->debug(1);
-	    if ($useproxy) {
-		print "Login on $proxyhost...\n";
-		$ftp->_USER($proxylogname);
-		$ftp->_PASS($proxypassword);
+	    if ($opts{useproxy}) {
+		print "Login on $opts{proxyhost}...\n";
+		$ftp->_USER($opts{proxylogname});
+		$ftp->_PASS($opts{proxypassword});
 	    }
-	    print "Login as $username...\n";
-	    if ($pass eq '?') {
+	    print "Login as $opts{username}...\n";
+	    if ($opts{password} eq '?') {
 		    print 'Enter password for ftp: ';
 		    system('stty', '-echo');
 		    $rpass = <STDIN>;
@@ -266,7 +265,7 @@ sub do_connect {
 		    print "\n";
 		    system('stty', 'echo');
 	    } else {
-		    $rpass = $pass;
+		    $rpass = $opts{password};
 	    }
 	    if(!$ftp->login($remoteuser, $rpass))
 	    { print $ftp->message() . "\n"; $exit=1; }
@@ -276,8 +275,11 @@ sub do_connect {
 	    if(!$ftp->binary()) { print $ftp->message . "\n"; $exit=1; }
 	}
 	if (!$exit) {
-	    print "Cd to '$ftpdir'...\n";
-	    if(!$ftp->cwd($ftpdir)) { print $ftp->message . "\n"; $exit=1; }
+	    print "Cd to '$opts{ftpdir}'...\n";
+	    if (!$ftp->cwd($opts{ftpdir})) {
+		print $ftp->message . "\n";
+		$exit = 1;
+	    }
 	}
 
 	if ($exit) {
diff --git a/dselect/methods/ftp/install.pl b/dselect/methods/ftp/install.pl
index 2eb9f16..9966e7a 100755
--- a/dselect/methods/ftp/install.pl
+++ b/dselect/methods/ftp/install.pl
@@ -338,15 +338,15 @@ sub download() {
 
     if (! @getfiles) { $i++; next; }
 
-    $ftp = do_connect ($site->[0], #$::ftpsite,
-                       $site->[4], #$::username,
-		       $site->[5], #$::password,
-		       $site->[1], #$::ftpdir,
-		       $site->[3], #$::passive,
-		       $CONFIG{use_auth_proxy},
-		       $CONFIG{proxyhost},
-		       $CONFIG{proxylogname},
-		       $CONFIG{proxypassword});
+    $ftp = do_connect(ftpsite => $site->[0],
+                      ftpdir => $site->[1],
+                      passive => $site->[3],
+                      username =>  $site->[4],
+                      password => $site->[5],
+                      useproxy => $CONFIG{use_auth_proxy},
+                      proxyhost => $CONFIG{proxyhost},
+                      proxylogname => $CONFIG{proxylogname},
+                      proxypassword => $CONFIG{proxypassword});
 
     local $SIG{INT} = sub { die "Interrupted !\n"; };
 
diff --git a/dselect/methods/ftp/setup.pl b/dselect/methods/ftp/setup.pl
index 18a5832..67a86fe 100755
--- a/dselect/methods/ftp/setup.pl
+++ b/dselect/methods/ftp/setup.pl
@@ -114,15 +114,15 @@ my $ftp;
 sub download() {
  foreach (@{$CONFIG{site}}) {
 
-    $ftp = do_connect ($_->[0], # Ftp server
-                       $_->[4], # username
-		       $_->[5], # password
-		       $_->[1], # ftp dir
-		       $_->[3], # passive
-		       $CONFIG{use_auth_proxy},
-		       $CONFIG{proxyhost},
-		       $CONFIG{proxylogname},
-		       $CONFIG{proxypassword});
+    $ftp = do_connect(ftpsite => $_->[0],
+                      ftpdir => $_->[1],
+                      passive => $_->[3],
+                      username => $_->[4],
+                      password => $_->[5],
+                      useproxy => $CONFIG{use_auth_proxy},
+                      proxyhost => $CONFIG{proxyhost},
+                      proxylogname => $CONFIG{proxylogname},
+                      proxypassword => $CONFIG{proxypassword});
 
     my @dists = @{$_->[2]};
 
diff --git a/dselect/methods/ftp/update.pl b/dselect/methods/ftp/update.pl
index 68f7a67..a40f6f0 100755
--- a/dselect/methods/ftp/update.pl
+++ b/dselect/methods/ftp/update.pl
@@ -76,15 +76,15 @@ foreach (@{$CONFIG{site}}) {
 
    my $site = $_;
 
-        $ftp = do_connect ($_->[0], # Ftp server
-                           $_->[4], # username
-                           $_->[5], # password
-                           $_->[1], # ftp dir
-                           $_->[3], # passive
-                           $CONFIG{use_auth_proxy},
-                           $CONFIG{proxyhost},
-                           $CONFIG{proxylogname},
-                           $CONFIG{proxypassword});
+        $ftp = do_connect(ftpsite => $_->[0],
+                          ftpdir => $_->[1],
+                          passive => $_->[3],
+                          username => $_->[4],
+                          password => $_->[5],
+                          useproxy => $CONFIG{use_auth_proxy},
+                          proxyhost => $CONFIG{proxyhost},
+                          proxylogname => $CONFIG{proxylogname},
+                          proxypassword => $CONFIG{proxypassword});
 
     my @dists = @{$_->[2]};
     PACKAGE:
@@ -166,15 +166,15 @@ foreach (@{$CONFIG{site}}) {
 		      $ftp->quit();
 		    };
 		    if (yesno ('y', "Transfer failed at $size: retry at once")) {
-                         $ftp = do_connect ($site->[0], # Ftp server
-                           $site->[4], # username
-                           $site->[5], # password
-                           $site->[1], # ftp dir
-                           $site->[3], # passive
-                           $CONFIG{use_auth_proxy},
-                           $CONFIG{proxyhost},
-                           $CONFIG{proxylogname},
-                           $CONFIG{proxypassword});
+                         $ftp = do_connect(ftpsite => $site->[0],
+                                           ftpdir => $site->[1],
+                                           passive => $site->[3],
+                                           username => $site->[4],
+                                           password => $site->[5],
+                                           useproxy => $CONFIG{use_auth_proxy},
+                                           proxyhost => $CONFIG{proxyhost},
+                                           proxylogname => $CONFIG{proxylogname},
+                                           proxypassword => $CONFIG{proxypassword});
 
 			if ($newest_pack_date != do_mdtm ($ftp, "$dir/Packages.gz")) {
 			    print ("Packages file has changed !\n");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list