FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-pkg.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2012 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: LGPL-2.1-only
6 */
7 
22 function GetPkgMimetypes()
23 {
24  global $PG_CONN;
25 
26  $pkArray = array();
27 
28  /* Find lft and rgt bounds for this $uploadtree_pk */
29  $sql = "select * from mimetype where
30  mimetype_name='application/x-rpm'
31  or mimetype_name='application/x-debian-package'
32  or mimetype_name='application/x-debian-source'";
33  $result = pg_query($PG_CONN, $sql);
34  DBCheckResult($result, $sql, __FILE__, __LINE__);
35  while ($row = pg_fetch_assoc($result)) {
36  if ($row['mimetype_name'] == 'application/x-rpm') {
37  $pkArray[0] = $row['mimetype_pk'];
38  } else if ($row['mimetype_name'] == 'application/x-debian-package') {
39  $pkArray[1] = $row['mimetype_pk'];
40  } else if ($row['mimetype_name'] == 'application/x-debian-source') {
41  $pkArray[2] = $row['mimetype_pk'];
42  }
43  }
44  pg_free_result($result);
45  return $pkArray;
46 }
47 
60 function IncrSrcBinCounts($uploadtree_row, $MimetypeArray,
61 &$NumSrcPkgs, &$NumBinPkgs, &$NumBinNoSrcPkgs)
62 {
63  global $PG_CONN;
64 
65  list($rpm_mtpk, $deb_mtsrcpk, $deb_mtbinpk) = $MimetypeArray;
66 
67  /* Debian source pkg? */
68  if ($uploadtree_row['pfile_mimetypefk'] == $deb_mtsrcpk) {
69  $NumSrcPkgs ++;
70  return;
71  }
72 
73  /* Debian binary pkg? */
74  if ($uploadtree_row['pfile_mimetypefk'] == $deb_mtbinpk) {
75  $NumBinPkgs ++;
76  $srcpkgmt = $deb_mtsrcpk;
77 
78  /* Is the source package present in this upload? */
79  /* First, find the source pkg name, there should only be 1 row */
80  $sql = "select source from pkg_deb where pfile_fk=$uploadtree_row[pfile_fk] limit 1";
81  $result = pg_query($PG_CONN, $sql);
82  DBCheckResult($result, $sql, __FILE__, __LINE__);
83  $row = pg_fetch_assoc($result);
84  $source = $row['source'];
85  pg_free_result($result);
86  }
87 
88  /* RPM pkg? */
89  /* RPM mimetypes don't distinguish between source and binary. So we have
90  * to look at the package data (source_rpm). If source_rpm is not empty
91  * then we are looking at a binary rpm. If source_rpm is empty, then
92  * we are looking at a source rpm.
93  */
94  if ($uploadtree_row['pfile_mimetypefk'] == $rpm_mtpk) {
95  $srcpkgmt = $rpm_mtpk;
96  /* Is this a source or binary rpm? */
97  $sql = "select source_rpm from pkg_rpm where pfile_fk=$uploadtree_row[pfile_fk] limit 1";
98  $result = pg_query($PG_CONN, $sql);
99  DBCheckResult($result, $sql, __FILE__, __LINE__);
100  $row = pg_fetch_assoc($result);
101  $source = $row['source_rpm'];
102  pg_free_result($result);
103  if ((substr($source, 0, 6) == "(none)") || empty($source)) {
104  $NumSrcPkgs ++;
105  return;
106  } else {
107  $NumBinPkgs ++;
108  }
109  }
110 
111  /* If $source is empty, then this isn't even a package */
112  if (empty($source)) {
113  return;
114  }
115 
116  /* To get here we must be looking at a binary package */
117  /* Find the source pkg in this upload */
118  $source = trim($source);
119  $sql = "select uploadtree_pk from uploadtree, pfile where
120  upload_fk=$uploadtree_row[upload_fk] and ufile_name='$source'
121  and pfile_fk=pfile_pk and pfile_mimetypefk=$srcpkgmt limit 1";
122  $result = pg_query($PG_CONN, $sql);
123  DBCheckResult($result, $sql, __FILE__, __LINE__);
124  if (pg_num_rows($result) == 0) {
125  $NumBinNoSrcPkgs ++;
126  }
127  pg_free_result($result);
128  return;
129 }
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:187
GetPkgMimetypes()
Get package mimetype.
Definition: common-pkg.php:22
IncrSrcBinCounts($uploadtree_row, $MimetypeArray, &$NumSrcPkgs, &$NumBinPkgs, &$NumBinNoSrcPkgs)
Increment counts of source package, binary package, and binary with no source.
Definition: common-pkg.php:60
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308