35 require_once
"/usr/share/fossology/php/pathinclude.php";
38 require_once (
"$WEBDIR/common/common.php");
40 function Usage($argc, $argv)
42 echo
"$argv[0] -m -f {file of pathnames} -u {original upload_pk} -t {tag_pk}\n";
43 echo
" -m means to only print out missing files. Do not update the db.\n";
52 function Strip2Path($RawFilePath)
54 if (empty($RawFilePath)) {
59 $FirstSlashPos = strpos($RawFilePath,
"/");
60 $StartStr = substr($RawFilePath, $FirstSlashPos);
62 $FParts = explode(
" ", $StartStr, 3);
65 $fPath = strtok($FParts[0],
" \t");
78 function Path2Uploadtree($upload_pk, $FilePath)
82 $FileName = basename($FilePath);
88 $FilePathArray = explode(
'/', $FilePath);
90 foreach ($FilePathArray as $name) {
94 $FilePathStr .= $name;
97 $sql =
"SELECT * from uploadtree where upload_fk='$upload_pk' and ufile_name='$FileName'";
98 $result = pg_query($PG_CONN, $sql);
100 if (pg_num_rows($result) == 0) {
105 while ($row = pg_fetch_assoc($result)) {
106 $sql =
"select ufile_name from uploadtree2path('$row[uploadtree_pk]')";
107 $PathResult = pg_query($PG_CONN, $sql);
111 $SelectedPathStr =
"";
112 while ($PathRow = pg_fetch_assoc($PathResult)) {
113 $SelectedPathStr = $PathRow[
'ufile_name'] . $SelectedPathStr;
115 pg_free_result($PathResult);
118 if ($FilePathStr == $SelectedPathStr) {
119 pg_free_result($result);
123 pg_free_result($result);
132 function TagPath($UploadtreeRow, $tag_pk)
136 if (empty($UploadtreeRow[
'pfile_fk'])) {
139 $sql =
"SELECT * from tag_uploadtree where uploadtree_fk='$UploadtreeRow[uploadtree_pk]' and tag_fk='$tag_pk'";
140 $result = pg_query($PG_CONN, $sql);
142 if (pg_num_rows($result) == 0) {
143 $sql =
"insert into tag_uploadtree (tag_fk, uploadtree_fk, tag_uploadtree_date, tag_uploadtree_text) values ($tag_pk, '$UploadtreeRow[uploadtree_pk]', now(), NULL)";
144 $InsResult = pg_query($PG_CONN, $sql);
150 $sql =
"SELECT * from tag_file where pfile_fk='$UploadtreeRow[pfile_fk]' and tag_fk='$tag_pk'";
151 $result = pg_query($PG_CONN, $sql);
153 if (pg_num_rows($result) == 0) {
154 $sql =
"insert into tag_file (tag_fk, pfile_fk, tag_file_date, tag_file_text) values ($tag_pk, '$UploadtreeRow[pfile_fk]', now(), NULL)";
155 $InsResult = pg_query($PG_CONN, $sql);
159 pg_free_result($result);
169 error_reporting(E_NOTICE & E_STRICT);
173 $dbok = $DB->db_init();
175 echo
"FATAL: NO DB connection";
180 $Options = getopt(
"mf:t:u:");
181 if (array_key_exists(
'f', $Options)
182 && array_key_exists(
't', $Options)
183 && array_key_exists(
'u', $Options)
185 $Missing = array_key_exists(
'm', $Options) ?
true :
false;
186 $PathFile = $Options[
'f'];
187 $tag_pk = $Options[
't'];
188 $upload_pk = $Options[
'u'];
190 echo
"Fatal: Missing parameter\n";
196 "Missing: $Missing\n";
200 $fhandle = @fopen($PathFile,
"r");
204 while (($fpathRaw = fgets($fhandle, 4096)) !==
false) {
205 $fpath = Strip2Path($fpathRaw);
206 $UploadtreeRow = Path2Uploadtree($upload_pk, $fpath);
207 if ($UploadtreeRow ===
false) {
208 echo
"Missing $fpath\n";
211 if ($Missing ===
false) {
212 TagPath($UploadtreeRow, $tag_pk);
217 if (! feof($fhandle)) {
218 echo
"Error: unexpected fgets() fail\n";
224 echo
"$FileCount files tagged\n";
225 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...
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.