FOSSology  4.4.0
Open Source License Compliance by Open Source Software
traverse.c File Reference

Traverse directories. More...

#include "ununpack.h"
#include "externs.h"
Include dependency graph for traverse.c:

Go to the source code of this file.

Functions

void TraverseStart (char *Filename, char *Label, char *NewDir, int Recurse)
 Find all files (assuming a directory) and process (unpack) all of them. More...
 
void TraverseChild (int Index, ContainerInfo *CI, char *NewDir)
 Called by exec'd child to process. More...
 
int CountFilename (char *Pathname, char *Dirname)
 Count the number of times Dirname appears in Pathname This is used to limit recursion in test archives that infinitely recurse. More...
 
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! More...
 

Detailed Description

Traverse directories.

Definition in file traverse.c.

Function Documentation

◆ CountFilename()

int CountFilename ( char *  Pathname,
char *  Dirname 
)

Count the number of times Dirname appears in Pathname This is used to limit recursion in test archives that infinitely recurse.

Parameters
PathnamePathname of file to process
DirnameDirectory name to search for
Returns
number of occurances of Dirname in Pathname

Full Dirname (includes forward and trailing slashes and null terminator)

Definition at line 238 of file traverse.c.

◆ Traverse()

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!

Parameters
FilenamePathname of file to process
BasenameOptional basename() of Filename
Labelis used for debugging.
NewDirOptional, specifies an alternate directory to extract to. Default (NewDir==NULL) is to extract to the same directory as Filename.
Recurse>0 to recurse
PIParentInfo
Returns
1 if Filename was a container, 0 if not a container. (The return value is really only used by TraverseStart().)

Definition at line 275 of file traverse.c.

◆ TraverseChild()

void TraverseChild ( int  Index,
ContainerInfo CI,
char *  NewDir 
)

Called by exec'd child to process.

The child never leaves here! It calls EXIT! Exit is 0 on success, non-zero on failure.

Parameters
IndexChild index into the queue table
CIThe ContainerInfo
NewDirOptional, specifies an alternate directory to extract to.

If the file processed is one original uploaded file and it is an archive, also using repository, need to reset the file name in the archive, if do not reset, for the gz Z bz2 archives, the file name in the archive is sha1.md5.size file name, that is:

For example:

argmatch.c.gz ---> CI->Source --->
657db64230b9d647362bfe0ebb82f7bd1d879400.a0f2e4d071ba2e68910132a8da5784a6.292
CI->PartnameNew --->
657db64230b9d647362bfe0ebb82f7bd1d879400.a0f2e4d071ba2e68910132a8da5784a6

so in order to get the original file name(CI->PartnameNew): we need get the upload archive name first, then get rid of the postfix.

For example: for test.gz, get rid of .gz, get the original file name 'test', replace sha1.md5.size file name with 'test'.

If the file processed is a sub-archive, in the other words, it is part of other archive, or not using repository, need get rid of the postfix two time, for example:

  1. for test.tar.gz, it is in test.rpm, when test.tar.gz is unpacked, the name of unpacked file should be test.tar under test.tar.gz.dir, but it is test.tar.gz.dir, so do as below: test.tar.gz.dir-->test.tar.gz-->test.tar,
  2. for metahandle.tab.bz2, it is one top archive, when metahandle.tab.bz2 is unpacked, the name of unpacked file should be metahandle.tab, so do as below: metahandle.tab.bz2.dir-->metahandle.tab.bz2-->metahandle.tab,

Definition at line 96 of file traverse.c.

◆ TraverseStart()

void TraverseStart ( char *  Filename,
char *  Label,
char *  NewDir,
int  Recurse 
)

Find all files (assuming a directory) and process (unpack) all of them.

Parameters
FilenamePathname of file to process
LabelString displayed by debug messages
NewDirOptional, specifies an alternate directory to extract to.
Recurse>0 to recurse

Definition at line 23 of file traverse.c.