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

[lintian] 01/04: L::Path: Omit owner, group, uid and gid when they are root



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

nthykier pushed a commit to branch master
in repository lintian.

commit f627ef8a384e35d79753fbde2325caacdee5e4bb
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Jul 19 23:14:37 2015 +0200

    L::Path: Omit owner, group, uid and gid when they are root
    
    The average ownership value: "root/root" (or 0/0).  Instead of paying
    an vast overhead from perl for having 2x fields saying "root" (and,
    sometimes, additionally 2x fields saying 0), simply omit the fields
    entirely in these cases.
    
    This saves ~5% over total cache memory for processing lintian itself.
    
    Side-effect, uid+gid will now default to 0 rather than undef.  Though,
    that is probably not a huge loss given that:
    
     * control files tend to be root/root (and, when not, we warn about it)
     * lintian normalises ownership for source packages to root/root anyway.
    
    For "everything else" (that one last case), we collect the ownership
    and it is therefore still accurate.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 debian/changelog               |  2 ++
 lib/Lintian/Collect/Package.pm | 32 ++++++++++++++++++++------------
 lib/Lintian/Path.pm            | 39 +++++++++++++++++++++++++++++++++++----
 3 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ca1d431..03b76d4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -33,6 +33,8 @@ lintian (2.5.34) UNRELEASED; urgency=medium
     + [NT] The undocumented "type" method has been removed from
       the API.  It was an implementation detail that has now
       changed.
+    + [NT] The "uid" and "gid" methods now return 0 rather than
+      undef when numeric ownership is not collected.
 
   * reporting/templates:
     + [NT] Remove (uses of) the "invisible-anchor" css class as
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index 3df2f0c..0910965 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -57,8 +57,6 @@ my %FILE_CODE2LPATH_TYPE = (
 my %INDEX_FAUX_DIR_TEMPLATE = (
     'name'       => '',
     '_path_info' => $FILE_CODE2LPATH_TYPE{'d'} | 0755,
-    'owner'      => 'root',
-    'group'      => 'root',
     'size'       => 0,
     # Pick a "random" (but fixed) date
     # - hint, it's a good read.  :)
@@ -437,8 +435,8 @@ sub _fetch_index_data {
     while (my $line = <$idx>) {
         chomp($line);
 
-        my (%file, $perm, $operm, $owner, $name, $raw_type);
-        ($perm,$owner,$file{size},$file{date},$file{time},$name)
+        my (%file, $perm, $operm, $ownership, $name, $raw_type);
+        ($perm,$ownership,$file{size},$file{date},$file{time},$name)
           =split(' ', $line, 6);
         # This may appear to be obscene, but the call overhead of
         # perm2oct is measurable on (e.g.) chromium-browser.  With
@@ -462,13 +460,27 @@ sub _fetch_index_data {
             my ($owner_id, $name_chk) = (split(' ', $numeric, 6))[1, 5];
             croak "mismatching contents of index files: $name $name_chk"
               if $name ne $name_chk;
-            ($file{uid}, $file{gid}) = split '/', $owner_id, 2;
+            my ($uid, $gid) = split('/', $owner_id, 2);
+            # Memory-optimise for 0/0.  Perl has an insane overhead
+            # for each field, so this is sadly worth it!
+            if ($uid) {
+                $file{'uid'} = $uid;
+            }
+            if ($gid) {
+                $file{'gid'} = $gid;
+            }
         }
 
-        ($file{owner}, $file{group}) = split '/', $owner, 2;
+        my ($owner, $group) = split('/', $ownership, 2);
 
-        $file{owner} = 'root' if $file{owner} eq '0';
-        $file{group} = 'root' if $file{group} eq '0';
+        # Memory-optimise for root/root.  Perl has an insane overhead
+        # for each field, so this is sadly worth it!
+        if ($owner ne 'root' and $owner ne '0') {
+            $file{'owner'} = $owner;
+        }
+        if ($group ne 'root' and $group ne '0') {
+            $file{'group'} = $group;
+        }
 
         if ($name =~ s/ link to (.*)//) {
             my $target = dequote_name($1);
@@ -512,10 +524,6 @@ sub _fetch_index_data {
             my ($parent) = ($name =~ m,^(.+/)?(?:[^/]+/?)$,);
             $parent //= '';
             $cpy{'name'} = $name;
-            if ($num_idx) {
-                $cpy{'uid'} = 0;
-                $cpy{'gid'} = 0;
-            }
             $idxh{$name} = \%cpy;
             $children{$parent} = [] unless exists $children{$parent};
             push @{ $children{$parent} }, $name unless $parent eq $name;
diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 6ad0389..940bf51 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -126,6 +126,14 @@ NB: If only numerical owner information is available in the package,
 this may return a numerical owner (except uid 0 is always mapped to
 "root")
 
+=cut
+
+sub owner {
+    my ($self) = @_;
+    return 'root' if not exists($self->{'owner'});
+    return $self->{'owner'};
+}
+
 =item group
 
 Returns the group of the path entry as a username.
@@ -134,22 +142,46 @@ NB: If only numerical owner information is available in the package,
 this may return a numerical group (except gid 0 is always mapped to
 "root")
 
+=cut
+
+sub group {
+    my ($self) = @_;
+    return 'root' if not exists($self->{'group'});
+    return $self->{'group'};
+}
+
 =item uid
 
 Returns the uid of the owner of the path entry.
 
-NB: If the uid is not available, undef will be returned.
+NB: If the uid is not available, 0 will be returned.
 This usually happens if the numerical data is not collected (e.g. in
 source packages)
 
+=cut
+
+sub uid {
+    my ($self) = @_;
+    return 0 if not exists($self->{'uid'});
+    return $self->{'uid'};
+}
+
 =item gid
 
 Returns the gid of the owner of the path entry.
 
-NB: If the gid is not available, undef will be returned.
+NB: If the gid is not available, 0 will be returned.
 This usually happens if the numerical data is not collected (e.g. in
 source packages)
 
+=cut
+
+sub gid {
+    my ($self) = @_;
+    return 0 if not exists($self->{'gid'});
+    return $self->{'gid'};
+}
+
 =item link
 
 If this is a link (i.e. is_symlink or is_hardlink returns a truth
@@ -230,8 +262,7 @@ happen if a package does not include all intermediate directories.
 =cut
 
 Lintian::Path->mk_ro_accessors(
-    qw(name owner group link uid gid
-      size date time parent_dir faux
+    qw(name link size date time parent_dir faux
       ));
 
 =item operm

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


Reply to: