FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
traverse.c
Go to the documentation of this file.
1 /*******************************************************************
2  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *******************************************************************/
17 
23 #include "ununpack.h"
24 #include "externs.h"
25 
34 void TraverseStart (char *Filename, char *Label, char *NewDir,
35  int Recurse)
36 {
37  dirlist *DLhead, *DLentry;
38  char Name[FILENAME_MAX];
39  char *Basename; /* the filename without the path */
40  ParentInfo PI;
41 
42  PI.Cmd = 0;
43  PI.StartTime = time(NULL);
44  PI.EndTime = PI.StartTime;
45  PI.uploadtree_pk = 0;
46  Basename = strrchr(Filename,'/');
47  if (Basename) Basename++;
48  else Basename = Filename;
49  memset(SQL,'\0',MAXSQL);
50  if (!IsDir(Filename))
51  {
52  memset(Name,'\0',sizeof(Name));
53  strcpy(Name,Filename);
54  Traverse(Filename,Basename,Label,NewDir,Recurse,&PI);
55  }
56  else /* process directory */
57  {
58  DLhead = MakeDirList(Filename);
59  for(DLentry=DLhead; DLentry; DLentry=DLentry->Next)
60  {
61  /* Now process the filename */
62  memset(Name,'\0',sizeof(Name));
63  strcpy(Name,Filename);
64  if (Last(Name) != '/') strcat(Name,"/");
65  strcat(Name,DLentry->Name);
66  TraverseStart(Name,Label,NewDir,Recurse);
67  }
68  FreeDirList(DLhead);
69  }
70 
71  /* remove anything that we needed to create */
72  if (UnlinkAll)
73  {
74  struct stat Src,Dst;
75  int i;
76  /* build the destination name */
77  SetDir(Name,sizeof(Name),NewDir,Basename);
78  for(i=strlen(Filename)-1; (i>=0) && (Filename[i] != '/'); i--)
79  ;
80  if (strcmp(Filename+i+1,".")) strcat(Name,Filename+i+1);
81  lstat(Filename,&Src);
82  lstat(Name,&Dst);
83 #if 0
84  printf("End:\n");
85  printf(" Src: %ld %s\n",(long)Src.st_ino,Filename);
86  printf(" Dst: %ld %s\n",(long)Dst.st_ino,Name);
87 #endif
88  /* only delete them if they are different! (Different inodes) */
89  if (Src.st_ino != Dst.st_ino)
90  {
91  if (IsDir(Name)) rmdir(Name);
92  else unlink(Name);
93  }
94  } /* if UnlinkAll */
95 } /* TraverseStart() */
96 
97 
107 void TraverseChild (int Index, ContainerInfo *CI, char *NewDir)
108 {
109  int rc;
110  int PlainCopy=0;
111  cmdtype Type;
112  Type = CMD[CI->PI.Cmd].Type;
113  if (CMD[CI->PI.Cmd].Status == 0) Type=CMD_DEFAULT;
114  switch(Type)
115  {
116  case CMD_PACK:
137  if (CI->TopContainer && UseRepository)
138  {
140  memcpy(CI->PartnameNew, UploadFileName, sizeof(CI->PartnameNew));
141  CI->PartnameNew[sizeof(CI->PartnameNew)-1] = 0;
142  }
143  else
156  {
159  }
160 
161  /* unpack in a sub-directory */
162  rc=RunCommand(CMD[CI->PI.Cmd].Cmd,CMD[CI->PI.Cmd].CmdPre,CI->Source,
163  CMD[CI->PI.Cmd].CmdPost,CI->PartnameNew,Queue[Index].ChildRecurse);
164  break;
165  case CMD_RPM:
166  /* unpack in the current directory */
167  rc=RunCommand(CMD[CI->PI.Cmd].Cmd,CMD[CI->PI.Cmd].CmdPre,CI->Source,
168  CMD[CI->PI.Cmd].CmdPost,CI->PartnameNew,CI->Partdir);
169  break;
170  case CMD_ARC:
171  case CMD_PARTITION:
172  /* unpack in a sub-directory */
173  rc=RunCommand(CMD[CI->PI.Cmd].Cmd,CMD[CI->PI.Cmd].CmdPre,CI->Source,
174  CMD[CI->PI.Cmd].CmdPost,CI->PartnameNew,Queue[Index].ChildRecurse);
175  if (!strcmp(CMD[CI->PI.Cmd].Magic,"application/x-zip") &&
176  ((rc==1) || (rc==2) || (rc==51)) )
177  {
178  LOG_WARNING("pfile %s Minor zip error(%d)... ignoring error.",Pfile_Pk,rc)
179  rc=0; /* lots of zip return codes */
180  }
181  break;
182  case CMD_AR:
183  /* unpack an AR: source file and destination directory */
184  rc=ExtractAR(CI->Source,Queue[Index].ChildRecurse);
185  break;
186  case CMD_ISO:
187  /* unpack an ISO: source file and destination directory */
188  rc=ExtractISO(CI->Source,Queue[Index].ChildRecurse);
189  break;
190  case CMD_DISK:
191  /* unpack a DISK: source file, FS type, and destination directory */
192  rc=ExtractDisk(CI->Source,CMD[CI->PI.Cmd].Cmd,Queue[Index].ChildRecurse);
193  break;
194  case CMD_DEB:
195  /* unpack a DEBIAN source:*/
196  rc=RunCommand(CMD[CI->PI.Cmd].Cmd,CMD[CI->PI.Cmd].CmdPre,CI->Source,
197  CMD[CI->PI.Cmd].CmdPost,CI->PartnameNew,CI->Partdir);
198  break;
199  case CMD_DEFAULT:
200  default:
201  /* use the original name */
202  PlainCopy=1;
203  if (!IsFile(Queue[Index].ChildRecurse,0))
204  {
205  CopyFile(CI->Source,Queue[Index].ChildRecurse);
206  }
207  rc=0;
208  break;
209  } /* switch type of processing */
210 
211  /* Child: Unpacks */
212  /* remove source */
213  if (UnlinkSource && (rc==0) && !NewDir && !PlainCopy)
214  {
215  /* if we're unlinking AND command worked AND it's not original... */
216  unlink(CI->Source);
217  }
218  if (rc)
219  {
220  /* if command failed but we want to continue anyway */
221  /* Note: CMD_DEFAULT will never get here because rc==0 */
222  if (strstr(CMD[CI->PI.Cmd].Cmd, "unzip") && (rc == 82))
223  {
224  LOG_ERROR("pfile %s Command %s failed on: %s, Password required.",
225  Pfile_Pk, CMD[CI->PI.Cmd].Cmd, CI->Source);
226  }
227  else
228  {
229  LOG_ERROR("pfile %s Command %s failed on: %s",
230  Pfile_Pk, CMD[CI->PI.Cmd].Cmd, CI->Source);
231  }
232  if (ForceContinue) rc=-1;
233  }
234  exit(rc);
235 } /* TraverseChild() */
236 
237 
245 int CountFilename(char *Pathname, char *Dirname)
246 {
247  char *FullDirname;
248  char *sp;
249  int FoundCount = 0;
250  int NameLen;
251 
252  FullDirname = calloc(strlen(Dirname) + 3, sizeof(char));
253  sprintf(FullDirname, "/%s/", Dirname);
254  NameLen = strlen(FullDirname);
255 
256  sp = Pathname;
257  while (((sp = strstr(sp, FullDirname)) != NULL))
258  {
259  FoundCount++;
260  sp += NameLen;
261  }
262 
263  free(FullDirname);
264  return(FoundCount);
265 }
266 
267 
282 int Traverse (char *Filename, char *Basename,
283  char *Label, char *NewDir, int Recurse, ParentInfo *PI)
284 {
285  int rc;
286  PGresult *result;
287  int i;
288  ContainerInfo CI,CImeta;
289  int IsContainer=0;
290  int RecurseOk=1; /* should it recurse? (only on unique inserts) */
291  int MaxRepeatingName = 3;
292 
293  if (!Filename || (Filename[0]=='\0')) return(IsContainer);
294  if (Verbose > 0) LOG_DEBUG("Traverse(%s) -- %s",Filename,Label)
295 
296  /* to prevent infinitely recursive test archives, count how many times the basename
297  occurs in Filename. If over MaxRepeatingName, then return 0
298  */
299  if (CountFilename(Filename, basename(Filename)) >= MaxRepeatingName)
300  {
301  LOG_NOTICE("Traverse() recursion terminating due to max directory repetition: %s", Filename);
302  return 0;
303  }
304 
305  /* clear the container */
306  memset(&CI,0,sizeof(ContainerInfo));
307 
308  /* check for top containers */
309  CI.TopContainer = (NewDir!=NULL);
310 
311  /***********************************************/
312  /* Populate CI and CI.PI structure */
313  /***********************************************/
314  CI.PI.Cmd=PI->Cmd; /* inherit */
315  CI.PI.StartTime = PI->StartTime;
316  CI.PI.EndTime = PI->EndTime;
317  CI.PI.uploadtree_pk = PI->uploadtree_pk;
319  /* the item is processed; log all children */
320  if (CI.Artifact > 0) PI->ChildRecurseArtifact=CI.Artifact-1;
321  else PI->ChildRecurseArtifact=0;
322 
323  rc = lstat(Filename,&CI.Stat);
324 
325  /* Source filename may be from another Queue element.
326  Copy the name over so it does not accidentally change. */
327  strcpy(CI.Source,Filename);
328 
329  /* split directory and filename */
330  if (Basename) SetDir(CI.Partdir,sizeof(CI.Partdir),NewDir,Basename);
331  else SetDir(CI.Partdir,sizeof(CI.Partdir),NewDir,CI.Source);
332 
333  /* count length of filename */
334  for(i=strlen(CI.Source)-1; (i>=0) && (CI.Source[i] != '/'); i--)
335  ;
336  strcpy(CI.Partname,CI.Source+i+1);
337  strcpy(CI.PartnameNew,CI.Partname);
338 
339  /***********************************************/
340  /* ignore anything that is not a directory or a file */
341  /***********************************************/
342  if (CI.Stat.st_mode & S_IFMT & ~(S_IFREG | S_IFDIR))
343  {
344  if (PI->Cmd) DisplayContainerInfo(&CI,PI->Cmd);
345  goto TraverseEnd;
346  }
347 
348  if (rc != 0)
349  {
350  /* this should never happen... */
351  LOG_ERROR("pfile %s \"%s\" DOES NOT EXIST!!!",Pfile_Pk,Filename)
352  /* goto TraverseEnd; */
353  return(0);
354  }
355 
356  /***********************************************/
357  /* handle pruning (on recursion only -- never delete originals) */
358  /***********************************************/
359  if (PruneFiles && !NewDir && Prune(Filename,CI.Stat))
360  {
361  /* pruned! */
362  if (PI->Cmd)
363  {
364  CI.Pruned=1;
365  DisplayContainerInfo(&CI,PI->Cmd);
366  }
367  goto TraverseEnd;
368  }
369 
370  /***********************************************/
371  /* check the type of file in filename: file or directory */
372  /***********************************************/
373  if (S_ISDIR(CI.Stat.st_mode))
374  {
375  /***********************************************/
376  /* if it's a directory, then recurse! */
377  /***********************************************/
378  dirlist *DLhead, *DLentry;
379  long TmpPk;
380 
381  /* record stats */
382  CI.IsDir=1;
383  CI.HasChild=1;
384  IsContainer=1;
385 
386  /* make sure it is accessible */
387  if (!NewDir && ((CI.Stat.st_mode & 0700) != 0700))
388  {
389  chmod(Filename,(CI.Stat.st_mode | 0700));
390  }
391 
392  if (CI.Source[strlen(CI.Source)-1] != '/') strcat(CI.Source,"/");
393  DLhead = MakeDirList(CI.Source);
394  /* process inode in the directory (only if unique) */
395  if (DisplayContainerInfo(&CI,PI->Cmd))
396  {
397  for(DLentry=DLhead; DLentry; DLentry=DLentry->Next)
398  {
399  SetDir(CI.Partdir,sizeof(CI.Partdir),NewDir,CI.Source);
400  strcat(CI.Partdir,DLentry->Name);
401  TmpPk = CI.PI.uploadtree_pk;
403  /* don't decrement just because it is a directory */
404  Traverse(CI.Partdir,NULL,"Called by dir",NULL,Recurse,&(CI.PI));
405  CI.PI.uploadtree_pk = TmpPk;
406  }
407  }
408  if (PI->Cmd && ListOutFile)
409  {
410  fputs("</item>\n",ListOutFile);
411  }
412  FreeDirList(DLhead);
413  } /* if S_ISDIR() */
414 
415 #if 0
416  else if (S_ISLNK(CI.Stat.st_mode) || S_ISCHR(CI.Stat.st_mode) ||
417  S_ISBLK(CI.Stat.st_mode) || S_ISFIFO(CI.Stat.st_mode) ||
418  S_ISSOCK(CI.Stat.st_mode))
419  {
420  /* skip symbolic links, blocks, and special devices */
423  }
424 #endif
425 
426  /***********************************************/
427  else if (S_ISREG(CI.Stat.st_mode))
428  {
429  if(IsInflatedFile(CI.Source, 1000)) return 0; // if the file is one compression bombs, do not unpack this file
430 
431  /***********************************************/
432  /* if it's a regular file, then process it! */
433  /***********************************************/
434  int Pid;
435  int Index; /* child index into queue table */
436 
437  CI.PI.Cmd = FindCmd(CI.Source);
438  if (CI.PI.Cmd < 0) goto TraverseEnd;
439 
440  /* make sure it is accessible */
441  if (!NewDir && ((CI.Stat.st_mode & 0600) != 0600))
442  {
443  chmod(Filename,(CI.Stat.st_mode | 0600));
444  }
445 
446  /* if it made it this far, then it's spawning time! */
447  /* Determine where to put the output */
448  Index=0;
449  while((Index < MAXCHILD) && (Queue[Index].ChildPid != 0))
450  Index++;
451 
452  /* determine output location */
453  memset(Queue+Index,0,sizeof(unpackqueue)); /* clear memory */
454  strcpy(Queue[Index].ChildRecurse,CI.Partdir);
455  strcat(Queue[Index].ChildRecurse,CI.Partname);
456  Queue[Index].PI.StartTime = CI.PI.StartTime;
457  Queue[Index].ChildEnd=0;
458  Queue[Index].PI.Cmd = CI.PI.Cmd;
459  Queue[Index].PI.uploadtree_pk = CI.PI.uploadtree_pk;
460  Queue[Index].ChildStat = CI.Stat;
461  switch(CMD[CI.PI.Cmd].Type)
462  {
463  case CMD_ARC:
464  case CMD_AR:
465  case CMD_ISO:
466  case CMD_DISK:
467  case CMD_PARTITION:
468  case CMD_PACK:
469  CI.HasChild=1;
470  IsContainer=1;
471  strcat(Queue[Index].ChildRecurse,".dir");
472  strcat(CI.PartnameNew,".dir");
473  Queue[Index].PI.ChildRecurseArtifact=1;
474  /* make the directory */
475  if (MkDir(Queue[Index].ChildRecurse))
476  {
477  LOG_FATAL("Unable to mkdir(%s) in Traverse", Queue[Index].ChildRecurse)
478  if (!ForceContinue)
479  {
480  SafeExit(30);
481  }
482  }
483  if (CMD[CI.PI.Cmd].Type == CMD_PARTITION)
484  Queue[Index].PI.ChildRecurseArtifact=2;
485 
486  /* get the upload file name */
487  /* if the type of the upload file is CMD_PACK, and is top container,
488  * and using repository, then get the upload file name from DB
489  */
490  if (CMD_PACK == CMD[CI.PI.Cmd].Type && CI.TopContainer && UseRepository)
491  {
492  char *UFileName;
493  char SQL[MAXSQL];
494  snprintf(SQL, MAXSQL,"SELECT upload_filename FROM upload WHERE upload_pk = %s;",Upload_Pk);
495  result = PQexec(pgConn, SQL); // get name of the upload file
496  if (fo_checkPQresult(pgConn, result, SQL, __FILE__, __LINE__))
497  {
498  SafeExit(31);
499  }
500  UFileName = PQgetvalue(result,0,0);
501  PQclear(result);
502  if (strchr(UFileName, '/')) UFileName = strrchr(UFileName, '/') + 1;
503  memset(UploadFileName, '\0', FILENAME_MAX);
504  strncpy(UploadFileName, UFileName, FILENAME_MAX - 1);
505  }
506 
507  break;
508  case CMD_DEB:
509  case CMD_RPM:
510  CI.HasChild=1;
511  IsContainer=1;
512  strcat(Queue[Index].ChildRecurse,".unpacked");
513  strcat(CI.PartnameNew,".unpacked");
514  Queue[Index].PI.ChildRecurseArtifact=1;
515  if (CMD[CI.PI.Cmd].Type == CMD_PACK)
516  {
517  CI.IsCompressed = 1;
518  }
519  break;
520  case CMD_DEFAULT:
521  default:
522  /* use the original name */
523  CI.HasChild=0;
524  Queue[Index].ChildEnd=1;
525  break;
526  }
527  Queue[Index].ChildHasChild = CI.HasChild;
528 
529  /* save the file's data */
530  RecurseOk = DisplayContainerInfo(&CI,PI->Cmd);
531 
532  /* extract meta info if we added it */
533  if (RecurseOk && CMD[CI.PI.Cmd].MetaCmd && CMD[CI.PI.Cmd].MetaCmd[0])
534  {
535  /* extract meta info */
536  /* This needs to call AddToRepository() or DisplayContainerInfo() */
537  char Cmd[2*FILENAME_MAX];
538  char Fname[FILENAME_MAX];
539  memcpy(&CImeta,&CI,sizeof(CI));
540  CImeta.Artifact=1;
541  CImeta.HasChild=0;
542  CImeta.TopContainer = 0;
543  CImeta.PI.uploadtree_pk = CI.uploadtree_pk;
544  CImeta.PI.Cmd = 0; /* no meta type */
545  memset(Cmd,0,sizeof(Cmd));
546  memset(Fname,0,sizeof(Fname));
547  strcpy(Fname,CImeta.Source);
548  strcat(CImeta.Source,".meta");
549  strcat(CImeta.Partname,".meta");
550 
551  /* remove the destination file if it exists */
552  /* this gets past any permission problems with read-only files */
553  unlink(CImeta.Source);
554 
555  /* build the command and run it */
556  sprintf(Cmd,CMD[CI.PI.Cmd].MetaCmd,Fname,CImeta.Source);
557  rc = system(Cmd);
558  if (WIFSIGNALED(rc))
559  {
560  LOG_ERROR("Process killed by signal (%d): %s",WTERMSIG(rc),Cmd)
561  SafeExit(32);
562  }
563  if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
564  else rc=-1;
565  if (rc != 0) LOG_ERROR("Unable to run command '%s'",Cmd)
566  /* add it to the list of files */
567  RecurseOk = DisplayContainerInfo(&CImeta,PI->Cmd);
568  if (UnlinkAll) unlink(CImeta.Source);
569  }
570 
571  /* see if I need to spawn (if not, then save time by not!) */
572  if ((Queue[Index].ChildEnd == 1) && IsFile(Queue[Index].ChildRecurse,0))
573  {
574  goto TraverseEnd;
575  }
576 
577  /* spawn unpacker */
578  fflush(stdout); /* if no flush, then child may duplicate output! */
579  if (ListOutFile) fflush(ListOutFile);
580  if (RecurseOk)
581  {
582  Pid = fork();
583  if (Pid == 0) TraverseChild(Index,&CI,NewDir);
584  else
585  {
586  /* Parent: Save child info */
587  if (Pid == -1)
588  {
589  LOG_FATAL("Unable to fork child.")
590  SafeExit(33);
591  }
592  Queue[Index].ChildPid = Pid;
593 
594  // add by larry, start
595  Queue[Index].PI.uploadtree_pk = CI.uploadtree_pk;
596  // add by larry, end
597 
598  Thread++;
599  /* Parent: Continue testing files */
600  if (Thread >= MaxThread)
601  {
602  /* Too many children. Wait for one to end */
603  Index=ParentWait();
604  if (Index < 0) goto TraverseEnd; /* no more children (shouldn't happen here!) */
605  Thread--;
606  /* the value for ChildRecurse can/will be overwitten quickly, but
607  it will be overwritten AFTER it is used */
608  /* Only recurse if the name is different */
609  if (strcmp(Queue[Index].ChildRecurse,CI.Source) && !Queue[Index].ChildEnd)
610  {
611  /* copy over data */
612  CI.Corrupt = Queue[Index].ChildCorrupt;
613  CI.PI.StartTime = Queue[Index].PI.StartTime;
614  CI.PI.EndTime = Queue[Index].PI.EndTime;
615  CI.PI.uploadtree_pk = Queue[Index].PI.uploadtree_pk;
616  CI.HasChild = Queue[Index].ChildHasChild;
617  CI.Stat = Queue[Index].ChildStat;
618 #if 0
619  Queue[Index].PI.uploadtree_pk = CI.uploadtree_pk;
620 #endif
621  if (Recurse > 0)
622  Traverse(Queue[Index].ChildRecurse,NULL,"Called by dir/wait",NULL,Recurse-1,&Queue[Index].PI);
623  else if (Recurse < 0)
624  Traverse(Queue[Index].ChildRecurse,NULL,"Called by dir/wait",NULL,Recurse,&Queue[Index].PI);
625  if (ListOutFile)
626  {
627  fputs("</item>\n",ListOutFile);
628  TotalContainers++;
629  }
630  }
631  } /* if waiting for a child */
632  } /* if parent */
633  } /* if RecurseOk */
634  } /* if S_ISREG() */
635 
636  /***********************************************/
637  else
638  {
639  /* Not a file and not a directory */
640  if (PI->Cmd)
641  {
642  CI.HasChild = 0;
643  DisplayContainerInfo(&CI,PI->Cmd);
644  }
645  LOG_DEBUG("Skipping (not a file or directory): %s",CI.Source)
646  }
647 
648  TraverseEnd:
649  if (UnlinkAll && MaxThread <=1)
650  {
651 #if 0
652  printf("===\n");
653  printf("Source: '%s'\n",CI.Source);
654  printf("NewDir: '%s'\n",NewDir ? NewDir : "");
655  printf("Name: '%s' '%s'\n",CI.Partdir,CI.Partname);
656 #endif
657  if (!NewDir)
658  {
659  if (IsDir(CI.Source)) RemoveDir(CI.Source);
660  // else unlink(CI.Source);
661  }
662  else RemoveDir(NewDir);
663  }
664  return(IsContainer);
665 } /* Traverse() */
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:181
char ChildRecurse[FILENAME_MAX+1]
Definition: ununpack.h:96
int ParentWait()
Wait for a child. Sets child status.
Definition: utils.c:520
Queue for files to be unpacked.
Definition: ununpack.h:93
Structure for storing information about a particular file.
Definition: ununpack.h:120
unpackqueue Queue[MAXCHILD+1]
Manage children.
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:52
char Partname[FILENAME_MAX]
Definition: ununpack.h:124
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
Definition: utils.c:1651
int IsFile(long mode)
Check if the pfile_id is a file.
Definition: wc_agent.c:67
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
Definition: utils.c:1467
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
int Thread
Number of threads in execution.
int IsDir(char *Fname)
Given a filename, is it a directory?
Definition: utils.c:330
int Verbose
Verbose level.
Definition: util.c:28
FILE * ListOutFile
File to store unpack list.
int ExtractISO(char *Source, char *Destination)
Given an ISO image and a directory, extract the image to the directory.
Definition: ununpack-iso.c:79
char * Pfile_Pk
Pfile pk in DB.
ParentInfo PI
Definition: ununpack.h:131
int ExtractAR(char *Source, char *Destination)
Given an AR file, extract the contents to the directory. This uses the command ar.
Definition: ununpack-ar.c:37
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
Definition: utils.c:51
long uploadtree_pk
Definition: ununpack.h:135
char * CmdPost
Definition: ununpack.h:152
int Traverse(char *Filename, char *Basename, char *Label, char *NewDir, int Recurse, ParentInfo *PI)
Find all files, traverse all directories. This is a depth-first search, in inode order! ...
Definition: traverse.c:282
int CountFilename(char *Pathname, char *Dirname)
Count the number of times Dirname appears in Pathname This is used to limit recursion in test archive...
Definition: traverse.c:245
char UploadFileName[FILENAME_MAX]
Upload file name.
int MkDir(char *Fname)
Smart mkdir.
Definition: utils.c:314
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
Definition: utils.c:860
int Status
Definition: ununpack.h:155
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
Definition: utils.c:1057
cmdlist CMD[]
Global command table.
int ChildCorrupt
Definition: ununpack.h:98
ParentInfo PI
Definition: ununpack.h:102
void RemovePostfix(char *Name)
get rid of the postfix
Definition: utils.c:101
char * Cmd
Definition: ununpack.h:150
int IsCompressed
Definition: ununpack.h:134
time_t EndTime
Definition: ununpack.h:84
char Partdir[FILENAME_MAX]
Definition: ununpack.h:123
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
Definition: utils.c:980
int ChildRecurseArtifact
Definition: ununpack.h:85
long uploadtree_pk
Definition: ununpack.h:86
int ChildHasChild
Definition: ununpack.h:100
char SQL[256]
SQL query to execute.
Definition: adj2nest.c:90
char * MetaCmd
Definition: ununpack.h:153
int UseRepository
Using files from the repository?
int PruneFiles
Remove links? >1 hard links, zero files, etc.
struct stat Stat
Definition: ununpack.h:130
int TotalContainers
Number of containers.
char * CmdPre
Definition: ununpack.h:151
char * NewDir
Test result directory.
Definition: run_tests.c:29
struct stat ChildStat
Definition: ununpack.h:101
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Definition: utils.c:228
int UnlinkSource
Remove recursive sources after unpacking?
Stores all extern variables used by the agent.
char * Upload_Pk
Upload pk in DB.
int TopContainer
Definition: ununpack.h:126
time_t StartTime
Definition: ununpack.h:83
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
Definition: utils.c:961
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec&#39;d child to process.
Definition: traverse.c:107
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
Definition: utils.c:631
int MaxThread
Value between 1 and MAXCHILD.
int ChildEnd
Definition: ununpack.h:99
char * Filename
Filename.
Definition: run_tests.c:28
cmdtype Type
Definition: ununpack.h:154
struct dirlist * Next
Definition: ununpack.h:112
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
Definition: traverse.c:34
Directory linked list.
Definition: ununpack.h:109
int UnlinkAll
Remove ALL unpacked files when done (clean up)?
void SafeExit(int rc)
Close scheduler and database connections, then exit.
Definition: utils.c:88
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:30
int ForceContinue
Force continue when unpack tool fails?
char PartnameNew[FILENAME_MAX]
Definition: ununpack.h:125