FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-pkg.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2012 Hewlett-Packard Development Company, L.P.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this library; if not, write to the Free Software Foundation, Inc.0
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  ***********************************************************/
18 
33 function GetPkgMimetypes()
34 {
35  global $PG_CONN;
36 
37  $pkArray = array();
38 
39  /* Find lft and rgt bounds for this $uploadtree_pk */
40  $sql = "select * from mimetype where
41  mimetype_name='application/x-rpm'
42  or mimetype_name='application/x-debian-package'
43  or mimetype_name='application/x-debian-source'";
44  $result = pg_query($PG_CONN, $sql);
45  DBCheckResult($result, $sql, __FILE__, __LINE__);
46  while ($row = pg_fetch_assoc($result)) {
47  if ($row['mimetype_name'] == 'application/x-rpm') {
48  $pkArray[0] = $row['mimetype_pk'];
49  } else if ($row['mimetype_name'] == 'application/x-debian-package') {
50  $pkArray[1] = $row['mimetype_pk'];
51  } else if ($row['mimetype_name'] == 'application/x-debian-source') {
52  $pkArray[2] = $row['mimetype_pk'];
53  }
54  }
55  pg_free_result($result);
56  return $pkArray;
57 }
58 
71 function IncrSrcBinCounts($uploadtree_row, $MimetypeArray,
72 &$NumSrcPkgs, &$NumBinPkgs, &$NumBinNoSrcPkgs)
73 {
74  global $PG_CONN;
75 
76  list($rpm_mtpk, $deb_mtsrcpk, $deb_mtbinpk) = $MimetypeArray;
77 
78  /* Debian source pkg? */
79  if ($uploadtree_row['pfile_mimetypefk'] == $deb_mtsrcpk) {
80  $NumSrcPkgs ++;
81  return;
82  }
83 
84  /* Debian binary pkg? */
85  if ($uploadtree_row['pfile_mimetypefk'] == $deb_mtbinpk) {
86  $NumBinPkgs ++;
87  $srcpkgmt = $deb_mtsrcpk;
88 
89  /* Is the source package present in this upload? */
90  /* First, find the source pkg name, there should only be 1 row */
91  $sql = "select source from pkg_deb where pfile_fk=$uploadtree_row[pfile_fk] limit 1";
92  $result = pg_query($PG_CONN, $sql);
93  DBCheckResult($result, $sql, __FILE__, __LINE__);
94  $row = pg_fetch_assoc($result);
95  $source = $row['source'];
96  pg_free_result($result);
97  }
98 
99  /* RPM pkg? */
100  /* RPM mimetypes don't distinguish between source and binary. So we have
101  * to look at the package data (source_rpm). If source_rpm is not empty
102  * then we are looking at a binary rpm. If source_rpm is empty, then
103  * we are looking at a source rpm.
104  */
105  if ($uploadtree_row['pfile_mimetypefk'] == $rpm_mtpk) {
106  $srcpkgmt = $rpm_mtpk;
107  /* Is this a source or binary rpm? */
108  $sql = "select source_rpm from pkg_rpm where pfile_fk=$uploadtree_row[pfile_fk] limit 1";
109  $result = pg_query($PG_CONN, $sql);
110  DBCheckResult($result, $sql, __FILE__, __LINE__);
111  $row = pg_fetch_assoc($result);
112  $source = $row['source_rpm'];
113  pg_free_result($result);
114  if ((substr($source, 0, 6) == "(none)") || empty($source)) {
115  $NumSrcPkgs ++;
116  return;
117  } else {
118  $NumBinPkgs ++;
119  }
120  }
121 
122  /* If $source is empty, then this isn't even a package */
123  if (empty($source)) {
124  return;
125  }
126 
127  /* To get here we must be looking at a binary package */
128  /* Find the source pkg in this upload */
129  $source = trim($source);
130  $sql = "select uploadtree_pk from uploadtree, pfile where
131  upload_fk=$uploadtree_row[upload_fk] and ufile_name='$source'
132  and pfile_fk=pfile_pk and pfile_mimetypefk=$srcpkgmt limit 1";
133  $result = pg_query($PG_CONN, $sql);
134  DBCheckResult($result, $sql, __FILE__, __LINE__);
135  if (pg_num_rows($result) == 0) {
136  $NumBinNoSrcPkgs ++;
137  }
138  pg_free_result($result);
139  return;
140 }
GetPkgMimetypes()
Get package mimetype.
Definition: common-pkg.php:33
IncrSrcBinCounts($uploadtree_row, $MimetypeArray, &$NumSrcPkgs, &$NumBinPkgs, &$NumBinNoSrcPkgs)
Increment counts of source package, binary package, and binary with no source.
Definition: common-pkg.php:71
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:321
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:198
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695