[dpkg] 114/192: Dpkg::File: Move file_lock() into a new Dpkg::Lock module

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 ff00042f3d77a2b8d122a7a7628d43a3e3bbf385
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Jul 14 03:09:23 2017 +0200

    Dpkg::File: Move file_lock() into a new Dpkg::Lock module
    
    This reduces the load chain for several Dpkg modules.
---
 debian/changelog                       |  2 ++
 scripts/Dpkg/File.pm                   | 33 ---------------------------------
 scripts/Dpkg/{File.pm => Lock.pm}      | 11 +----------
 scripts/Makefile.am                    |  2 ++
 scripts/dpkg-distaddfile.pl            |  2 +-
 scripts/dpkg-genbuildinfo.pl           |  2 +-
 scripts/dpkg-gencontrol.pl             |  2 +-
 scripts/po/POTFILES.in                 |  1 +
 scripts/t/{Dpkg_File.t => Dpkg_Lock.t} |  2 +-
 9 files changed, 10 insertions(+), 47 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index b70b645..2b3c753 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -39,6 +39,8 @@ dpkg (1.19.0) UNRELEASED; urgency=medium
     - Add new Dpkg::Interface::Storable option to disable compression support,
       so that we can load Dpkg::Compression::FileHandle only when enabled.
     - Disable decompression support for Dpkg::Vendor origin files.
+    - Move file_lock() function into a new Dpkg::Lock module, to reduce the
+      module load chain for several Dpkg modules.
   * Documentation:
     - Document currently accepted syntax for changelogs in deb-changelog(5).
       Closes: #858579
diff --git a/scripts/Dpkg/File.pm b/scripts/Dpkg/File.pm
index cf68d9e..8849238 100644
--- a/scripts/Dpkg/File.pm
+++ b/scripts/Dpkg/File.pm
@@ -21,43 +21,10 @@ use warnings;
 
 our $VERSION = '0.01';
 our @EXPORT = qw(
-    file_lock
     file_slurp
 );
 
 use Exporter qw(import);
-use Fcntl qw(:flock);
-
-use Dpkg::Gettext;
-use Dpkg::ErrorHandling;
-
-sub file_lock($$) {
-    my ($fh, $filename) = @_;
-
-    # A strict dependency on libfile-fcntllock-perl being it an XS module,
-    # and dpkg-dev indirectly making use of it, makes building new perl
-    # package which bump the perl ABI impossible as these packages cannot
-    # be installed alongside.
-    eval q{
-        pop @INC if $INC[-1] eq '.';
-        use File::FcntlLock;
-    };
-    if ($@) {
-        # On Linux systems the flock() locks get converted to file-range
-        # locks on NFS mounts.
-        if ($^O ne 'linux') {
-            warning(g_('File::FcntlLock not available; using flock which is not NFS-safe'));
-        }
-        flock($fh, LOCK_EX)
-            or syserr(g_('failed to get a write lock on %s'), $filename);
-    } else {
-        eval q{
-            my $fs = File::FcntlLock->new(l_type => F_WRLCK);
-            $fs->lock($fh, F_SETLKW)
-                or syserr(g_('failed to get a write lock on %s'), $filename);
-        }
-    }
-}
 
 sub file_slurp {
     my $fh = shift;
diff --git a/scripts/Dpkg/File.pm b/scripts/Dpkg/Lock.pm
similarity index 93%
copy from scripts/Dpkg/File.pm
copy to scripts/Dpkg/Lock.pm
index cf68d9e..6344779 100644
--- a/scripts/Dpkg/File.pm
+++ b/scripts/Dpkg/Lock.pm
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-package Dpkg::File;
+package Dpkg::Lock;
 
 use strict;
 use warnings;
@@ -22,7 +22,6 @@ use warnings;
 our $VERSION = '0.01';
 our @EXPORT = qw(
     file_lock
-    file_slurp
 );
 
 use Exporter qw(import);
@@ -59,12 +58,4 @@ sub file_lock($$) {
     }
 }
 
-sub file_slurp {
-    my $fh = shift;
-
-    local $/;
-    my $data = <$fh>;
-    return $data;
-}
-
 1;
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index efc970c..b66682e 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -88,6 +88,7 @@ nobase_dist_perllib_DATA = \
 	Dpkg/Index.pm \
 	Dpkg/Interface/Storable.pm \
 	Dpkg/IPC.pm \
+	Dpkg/Lock.pm \
 	Dpkg/Package.pm \
 	Dpkg/Path.pm \
 	Dpkg/Shlibs.pm \
@@ -219,6 +220,7 @@ test_scripts = \
 	t/Dpkg_ErrorHandling.t \
 	t/Dpkg_Exit.t \
 	t/Dpkg_File.t \
+	t/Dpkg_Lock.t \
 	t/Dpkg_Getopt.t \
 	t/Dpkg_Gettext.t \
 	t/Dpkg_Conf.t \
diff --git a/scripts/dpkg-distaddfile.pl b/scripts/dpkg-distaddfile.pl
index 060b3a2..929b697 100755
--- a/scripts/dpkg-distaddfile.pl
+++ b/scripts/dpkg-distaddfile.pl
@@ -26,7 +26,7 @@ use POSIX qw(:errno_h :fcntl_h);
 use Dpkg ();
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
-use Dpkg::File;
+use Dpkg::Lock;
 use Dpkg::Dist::Files;
 
 textdomain('dpkg-dev');
diff --git a/scripts/dpkg-genbuildinfo.pl b/scripts/dpkg-genbuildinfo.pl
index d1da726..3682f2f 100755
--- a/scripts/dpkg-genbuildinfo.pl
+++ b/scripts/dpkg-genbuildinfo.pl
@@ -46,7 +46,7 @@ use Dpkg::Control;
 use Dpkg::Changelog::Parse;
 use Dpkg::Deps;
 use Dpkg::Dist::Files;
-use Dpkg::File;
+use Dpkg::Lock;
 use Dpkg::Version;
 use Dpkg::Vendor qw(get_current_vendor run_vendor_hook);
 
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index cf9529a..98c304a 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -29,7 +29,7 @@ use File::Find;
 use Dpkg ();
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
-use Dpkg::File;
+use Dpkg::Lock;
 use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is debarch_list_parse);
 use Dpkg::Package;
 use Dpkg::BuildProfiles qw(get_build_profiles);
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index 460a494..7584619 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -55,6 +55,7 @@ scripts/Dpkg/Gettext.pm
 scripts/Dpkg/IPC.pm
 scripts/Dpkg/Index.pm
 scripts/Dpkg/Interface/Storable.pm
+scripts/Dpkg/Lock.pm
 scripts/Dpkg/Package.pm
 scripts/Dpkg/Path.pm
 scripts/Dpkg/Shlibs.pm
diff --git a/scripts/t/Dpkg_File.t b/scripts/t/Dpkg_Lock.t
similarity index 96%
copy from scripts/t/Dpkg_File.t
copy to scripts/t/Dpkg_Lock.t
index 1db6ee9..0b85180 100644
--- a/scripts/t/Dpkg_File.t
+++ b/scripts/t/Dpkg_Lock.t
@@ -19,7 +19,7 @@ use warnings;
 use Test::More tests => 1;
 
 BEGIN {
-    use_ok('Dpkg::File');
+    use_ok('Dpkg::Lock');
 }
 
 # TODO: Add actual test cases.

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