27 char Name[FILENAME_MAX];
36 if (Basename) Basename++;
38 memset(
SQL,
'\0',MAXSQL);
41 memset(Name,
'\0',
sizeof(Name));
48 for(DLentry=DLhead; DLentry; DLentry=DLentry->
Next)
51 memset(Name,
'\0',
sizeof(Name));
53 if (Last(Name) !=
'/') strcat(Name,
"/");
54 strcat(Name,DLentry->Name);
75 printf(
" Dst: %ld %s\n",(
long)
Dst.st_ino,Name);
78 if (
Src.st_ino !=
Dst.st_ino)
80 if (
IsDir(Name)) rmdir(Name);
164 if (!strcmp(
CMD[CI->
PI.Cmd].Magic,
"application/x-zip") &&
165 ((rc==1) || (rc==2) || (rc==51)) )
167 LOG_WARNING(
"pfile %s Minor zip error(%d)... ignoring error.",
Pfile_Pk,rc)
215 if (strstr(
CMD[CI->
PI.Cmd].
Cmd,
"unzip") && (rc == 82))
217 LOG_ERROR(
"pfile %s Command %s failed on: %s, Password required.",
222 LOG_ERROR(
"pfile %s Command %s failed on: %s",
245 FullDirname = calloc(strlen(Dirname) + 3,
sizeof(
char));
246 sprintf(FullDirname,
"/%s/", Dirname);
247 NameLen = strlen(FullDirname);
250 while (((sp = strstr(sp, FullDirname)) != NULL))
284 int MaxRepeatingName = 3;
294 LOG_NOTICE(
"Traverse() recursion terminating due to max directory repetition: %s",
Filename);
327 for(i=strlen(CI.Source)-1; (i>=0) && (CI.Source[i] !=
'/'); i--)
335 if (CI.
Stat.st_mode & S_IFMT & ~(S_IFREG | S_IFDIR))
366 if (S_ISDIR(CI.
Stat.st_mode))
380 if (!
NewDir && ((CI.
Stat.st_mode & 0700) != 0700))
385 if (CI.Source[strlen(CI.Source)-1] !=
'/') strcat(CI.Source,
"/");
390 for(DLentry=DLhead; DLentry; DLentry=DLentry->
Next)
393 strcat(CI.
Partdir,DLentry->Name);
409 else if (S_ISLNK(CI.
Stat.st_mode) || S_ISCHR(CI.
Stat.st_mode) ||
410 S_ISBLK(CI.
Stat.st_mode) || S_ISFIFO(CI.
Stat.st_mode) ||
411 S_ISSOCK(CI.
Stat.st_mode))
420 else if (S_ISREG(CI.
Stat.st_mode))
431 if (CI.
PI.Cmd < 0)
goto TraverseEnd;
434 if (!
NewDir && ((CI.
Stat.st_mode & 0600) != 0600))
442 while((Index < MAXCHILD) && (
Queue[Index].ChildPid != 0))
465 strcat(
Queue[Index].ChildRecurse,
".dir");
471 LOG_FATAL(
"Unable to mkdir(%s) in Traverse",
Queue[Index].ChildRecurse)
477 if (
CMD[CI.
PI.Cmd].
Type == CMD_PARTITION)
488 snprintf(
SQL, MAXSQL,
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
494 UFileName = PQgetvalue(result,0,0);
496 if (strchr(UFileName,
'/')) UFileName = strrchr(UFileName,
'/') + 1;
506 strcat(
Queue[Index].ChildRecurse,
".unpacked");
531 char Cmd[2*FILENAME_MAX];
532 char Fname[FILENAME_MAX];
533 memcpy(&CImeta,&CI,
sizeof(CI));
539 memset(Cmd,0,
sizeof(Cmd));
540 memset(Fname,0,
sizeof(Fname));
541 strcpy(Fname,CImeta.Source);
542 strcat(CImeta.Source,
".meta");
547 unlink(CImeta.Source);
550 sprintf(Cmd,
CMD[CI.
PI.Cmd].
MetaCmd,Fname,CImeta.Source);
554 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd)
557 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
559 if (rc != 0) LOG_ERROR(
"Unable to run command '%s'",Cmd)
583 LOG_FATAL(
"Unable to fork child.")
586 Queue[Index].ChildPid = Pid;
598 if (Index < 0)
goto TraverseEnd;
639 LOG_DEBUG(
"Skipping (not a file or directory): %s",CI.Source)
647 printf(
"Source: '%s'\n",CI.Source);
char SQL[256]
SQL query to execute.
PGconn * pgConn
Database connection.
int Verbose
Verbose level.
Stores all extern variables used by the agent.
char * Pfile_Pk
Pfile pk in DB.
int UseRepository
Using files from the repository?
int MaxThread
Value between 1 and MAXCHILD.
int UnlinkSource
Remove recursive sources after unpacking?
unpackqueue Queue[MAXCHILD+1]
Manage children.
int Thread
Number of threads in execution.
cmdlist CMD[]
Global command table.
int PruneFiles
Remove links? >1 hard links, zero files, etc.
int TotalContainers
Number of containers.
char UploadFileName[FILENAME_MAX]
Upload file name.
char * Upload_Pk
Upload pk in DB.
int UnlinkAll
Remove ALL unpacked files when done (clean up)?
FILE * ListOutFile
File to store unpack list.
int ForceContinue
Force continue when unpack tool fails?
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
void CopyFile(char *Source, char *Type, char *Name)
Structure for storing information about a particular file.
char Partname[FILENAME_MAX]
char PartnameNew[FILENAME_MAX]
char Partdir[FILENAME_MAX]
Queue for files to be unpacked.
char ChildRecurse[FILENAME_MAX+1]
static char * Dst
Destination location.
static char * Src
Souce location.
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
int CountFilename(char *Pathname, char *Dirname)
Count the number of times Dirname appears in Pathname This is used to limit recursion in test archive...
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec'd child to process.
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!
int ExtractAR(char *Source, char *Destination)
Given an AR file, extract the contents to the directory. This uses the command ar.
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
int ExtractISO(char *Source, char *Destination)
Given an ISO image and a directory, extract the image to the directory.
int ExtractZstd(char *Source, const char *OrigName, char *Destination)
Given a ZSTd file, extract the contents to the directory.
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
int MkDir(char *Fname)
Smart mkdir.
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
int ParentWait()
Wait for a child. Sets child status.
void RemovePostfix(char *Name)
get rid of the postfix
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
int IsDir(char *Fname)
Given a filename, is it a directory?
int Recurse
Level of unpack recursion. Default to infinite.
char * NewDir
Test result directory.
int IsFile(long mode)
Check if the pfile_id is a file.