107 #include "ununpack.h" 111 char BuildVersion[]=
"ununpack build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
117 int main(
int argc,
char *argv[])
121 int rvExist1=0, rvExist2=0;
124 char *AgentName =
"ununpack";
125 char *AgentARSName =
"ununpack_ars";
126 char *agent_desc =
"Unpacks archives (iso, tar, etc)";
131 char *ListOutName=NULL;
133 char *FnameCheck = NULL;
136 char agent_rev[PATH_MAX];
142 while((c = getopt(argc,argv,
"ACc:d:FfHhL:m:PQiIqRr:T:t:U:VvXx")) != -1)
155 case 'L': ListOutName=optarg;
break;
161 case 'R': Recurse=-1;
break;
162 case 'r': Recurse=atoi(optarg);
break;
165 LOG_WARNING(
"dpkg-source is not available on this system. This means that debian source packages will NOT be unpacked.");
177 case 'q':
Quiet=1;
break;
207 LOG_ERROR(
"You have no update permissions on upload %s",
Upload_Pk);
213 sprintf(agent_rev,
"%s.%s", VERSION, COMMIT_HASH);
228 "SELECT ars_pk from %s where upload_fk='%s' and ars_success=TRUE",
233 if (PQntuples(result) > 0)
236 LOG_WARNING(
"Upload_pk %s, has already been unpacked. No further action required",
247 "SELECT pfile.pfile_sha1 || '.' || pfile.pfile_md5 || '.' || pfile.pfile_size AS pfile, pfile_fk, pfile_size FROM upload INNER JOIN pfile ON upload.pfile_fk = pfile.pfile_pk WHERE upload.
upload_pk = '%
s'",
249 result = PQexec(pgConn, SQL);
252 if (PQntuples(result) > 0)
254 Pfile = strdup(PQgetvalue(result,0,0));
255 Pfile_Pk = strdup(PQgetvalue(result,0,1));
256 Pfile_size = atol(PQgetvalue(result, 0, 2));
260 LOG_WARNING(
"Uploaded file (Upload_pk %s), is zero length. There is nothing to unpack.",
272 if (Pfile_size > 500000000)
277 snprintf(SQL,MAXSQL,
"CREATE TABLE %s (LIKE uploadtree INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES); ALTER TABLE %s ADD CONSTRAINT %s CHECK (upload_fk=%s); ALTER TABLE %s INHERIT uploadtree",
280 result = PQexec(pgConn, SQL);
282 if (PQresultStatus(result) != PGRES_NONFATAL_ERROR)
293 if (NewDir)
MkDir(NewDir);
294 if (
Verbose) { fclose(stderr) ; stderr=stdout; }
295 if (ListOutName != NULL)
297 if ((ListOutName[0]==
'-') && (ListOutName[1]==
'\0'))
302 LOG_ERROR(
"pfile %s Unable to write to %s\n",
Pfile_Pk,ListOutName)
327 snprintf(SQL,MAXSQL,
"SELECT uploadtree_pk FROM uploadtree WHERE upload_fk=%s limit 1;",Upload_Pk);
328 result = PQexec(pgConn, SQL);
335 for( ; optind<argc; optind++)
340 if (Fname) { free(Fname); Fname=NULL; }
341 if (ListOutName != NULL)
343 fprintf(
ListOutFile,
"<source source=\"%s\" ",argv[optind]);
349 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",argv[optind],argv[optind])
366 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",Fname,argv[optind])
378 LOG_ERROR(
"NO file unpacked. File %s does not exist either in GOLD or FILES",
Pfile);
385 FnameCheck = argv[optind];
390 if (stat(FnameCheck,&Stat))
392 LOG_ERROR(
"File to unpack is unavailable: %s, error: %s", Fname, strerror(errno));
396 if (Stat.st_size < 1)
398 LOG_WARNING(
"File to unpack is empty: %s", Fname);
425 Fin = fopen(argv[optind],
"rb");
447 if (Fname)
TraverseStart(Fname,
"called by main via args",NewDir,Recurse);
448 else TraverseStart(argv[optind],
"called by main",NewDir,Recurse);
449 if (ListOutName != NULL) fprintf(
ListOutFile,
"</source>\n");
453 if (Fname) { free(Fname); Fname=NULL; }
467 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",Fname,
Pfile)
473 TraverseStart(Fname,
"called by main via env",NewDir,Recurse);
479 LOG_ERROR(
"NO file unpacked!");
483 LOG_ERROR(
"Error is %s for %s", strerror(rvExist1), Fname);
488 LOG_ERROR(
"Error is %s for %s", strerror(rvExist2), Fname);
501 if (!
Queue[Pid].ChildEnd)
505 Traverse(
Queue[Pid].ChildRecurse,NULL,
"called by wait",NULL,Recurse-1,&
Queue[Pid].PI);
506 else if (Recurse < 0)
515 fprintf(
ListOutFile,
"<summary files_regular=\"%d\" files_compressed=\"%d\" artifacts=\"%d\" directories=\"%d\" containers=\"%d\" />\n",
525 snprintf(SQL,MAXSQL,
"UPDATE upload SET upload_mode = (upload_mode | (1<<5)), uploadtree_tablename='%s' WHERE upload_pk = '%s';",
uploadtree_tablename, Upload_Pk);
526 result = PQexec(pgConn, SQL);
530 snprintf(SQL,MAXSQL,
"UPDATE %s SET realparent = getItemParent(uploadtree_pk) WHERE upload_fk = '%s'",
uploadtree_tablename, Upload_Pk);
531 result = PQexec(pgConn, SQL);
536 if (ars_pk)
fo_WriteARS(pgConn, ars_pk, atoi(Upload_Pk), agent_pk, AgentARSName, 0, 1);
546 if (strcmp(NewDir,
"."))
RemoveDir(NewDir);
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int Quiet
Run in quiet mode?
int TotalFiles
Number of regular files.
Contains global declaration of variables.
int ParentWait()
Wait for a child. Sets child status.
unpackqueue Queue[MAXCHILD+1]
Manage children.
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
if(!$Test &&$OptionQ) if($stdin_flag) if($Verbose) else
PGconn * pgConn
Database connection.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int Thread
Number of threads in execution.
int Verbose
Verbose level.
int TotalCompressedFiles
Number of compressed files.
char * Pfile
Pfile name (SHA1.MD5.Size)
FILE * ListOutFile
File to store unpack list.
int s
The socket that the CLI will use to communicate.
char * Pfile_Pk
Pfile pk in DB.
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
int TotalArtifacts
Number of artifacts.
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 IgnoreSCMData
1: Ignore SCMÂ data, 0: dont ignore it.
int MkDir(char *Fname)
Smart mkdir.
uint8_t SHA1digest[20]
SHA1 digest of the file.
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
int ReunpackSwitch
Set if the uploadtree records are missing from db.
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
uint8_t MD5digest[16]
MD5 digest of the file.
char SQL[256]
SQL query to execute.
int ForceDuplicate
When using db, should it process duplicates?
int UseRepository
Using files from the repository?
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
Usage()
Print Usage statement.
int PruneFiles
Remove links? >1 hard links, zero files, etc.
int TotalContainers
Number of containers.
void CheckCommands(int Show)
Make sure all commands are usable.
char * NewDir
Test result directory.
int UnlinkSource
Remove recursive sources after unpacking?
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
char * uploadtree_tablename
upload.uploadtree_tablename
FUNCTION int fo_CreateARSTable(PGconn *pgConn, const char *tableName)
Create ars table if it doesn't already exist.
Store check sum of a file.
int fo_tableExists(PGconn *pgConn, const char *tableName)
Check if table exists. Note, this assumes the database name is 'fossology'.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
uint64_t DataLen
Size of the file.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
FUNCTION int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk, const char *tableName, const char *ars_status, int ars_success)
Write ars record.
char * Upload_Pk
Upload pk in DB.
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
magic_t MagicCookie
for Magic
char REP_FILES[16]
Files repository name.
char REP_GOLD[16]
Gold repository name.
int TotalDirectories
Number of directories.
int MaxThread
Value between 1 and MAXCHILD.
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
void InitCmd()
Initialize the metahandler CMD table.
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
int UnlinkAll
Remove ALL unpacked files when done (clean up)?
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int Recurse
Level of unpack recursion. Default to infinite.
int ForceContinue
Force continue when unpack tool fails?
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int SetContainerArtifact
Should initial container be an artifact?
Store file handler and mmap of a file.
#define PERM_WRITE
Read-Write permission.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.