24 require_once
"/usr/share/fossology/php/pathinclude.php";
27 require_once (
"$WEBDIR/common/common.php");
29 function Usage($argc, $argv)
31 echo
"$argv[0] -m -f {file of pathnames} -u {original upload_pk} -t {tag_pk}\n";
32 echo
" -m means to only print out missing files. Do not update the db.\n";
41 function Strip2Path($RawFilePath)
43 if (empty($RawFilePath)) {
48 $FirstSlashPos = strpos($RawFilePath,
"/");
49 $StartStr = substr($RawFilePath, $FirstSlashPos);
51 $FParts = explode(
" ", $StartStr, 3);
54 $fPath = strtok($FParts[0],
" \t");
68 function Path2Uploadtree($upload_pk, $FilePath)
72 $FileName = basename($FilePath);
78 $FilePathArray = explode(
'/', $FilePath);
80 foreach ($FilePathArray as $name) {
84 $FilePathStr .= $name;
87 $sql =
"SELECT * from uploadtree where upload_fk='$upload_pk' and ufile_name='$FileName'";
90 if (pg_num_rows($result) == 0) {
95 while ($row = pg_fetch_assoc($result)) {
96 $sql =
"select ufile_name from uploadtree2path('$row[uploadtree_pk]')";
97 $PathResult = pg_query(
$PG_CONN, $sql);
101 $SelectedPathStr =
"";
102 while ($PathRow = pg_fetch_assoc($PathResult)) {
103 $SelectedPathStr = $PathRow[
'ufile_name'] . $SelectedPathStr;
105 pg_free_result($PathResult);
108 if ($FilePathStr == $SelectedPathStr) {
109 pg_free_result($result);
113 pg_free_result($result);
122 function TagPath($UploadtreeRow, $tag_pk)
126 if (empty($UploadtreeRow[
'pfile_fk'])) {
129 $sql =
"SELECT * from tag_uploadtree where uploadtree_fk='$UploadtreeRow[uploadtree_pk]' and tag_fk='$tag_pk'";
132 if (pg_num_rows($result) == 0) {
133 $sql =
"insert into tag_uploadtree (tag_fk, uploadtree_fk, tag_uploadtree_date, tag_uploadtree_text) values ($tag_pk, '$UploadtreeRow[uploadtree_pk]', now(), NULL)";
134 $InsResult = pg_query(
$PG_CONN, $sql);
140 $sql =
"SELECT * from tag_file where pfile_fk='$UploadtreeRow[pfile_fk]' and tag_fk='$tag_pk'";
143 if (pg_num_rows($result) == 0) {
144 $sql =
"insert into tag_file (tag_fk, pfile_fk, tag_file_date, tag_file_text) values ($tag_pk, '$UploadtreeRow[pfile_fk]', now(), NULL)";
145 $InsResult = pg_query(
$PG_CONN, $sql);
149 pg_free_result($result);
159 error_reporting(E_NOTICE & E_STRICT);
163 $dbok = $DB->db_init();
165 echo
"FATAL: NO DB connection";
170 $Options = getopt(
"mf:t:u:");
171 if (array_key_exists(
'f', $Options)
172 && array_key_exists(
't', $Options)
173 && array_key_exists(
'u', $Options)
175 $Missing = array_key_exists(
'm', $Options) ? true :
false;
176 $PathFile = $Options[
'f'];
177 $tag_pk = $Options[
't'];
178 $upload_pk = $Options[
'u'];
180 echo
"Fatal: Missing parameter\n";
186 "Missing: $Missing\n";
190 $fhandle = @fopen($PathFile,
"r");
194 while (($fpathRaw = fgets($fhandle, 4096)) !==
false) {
195 $fpath = Strip2Path($fpathRaw);
196 $UploadtreeRow = Path2Uploadtree($upload_pk, $fpath);
197 if ($UploadtreeRow ===
false) {
198 echo
"Missing $fpath\n";
201 if ($Missing ===
false) {
202 TagPath($UploadtreeRow, $tag_pk);
207 if (! feof($fhandle)) {
208 echo
"Error: unexpected fgets() fail\n";
214 echo
"$FileCount files tagged\n";
215 echo
"$MissCount file paths not found\n";
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN