100 #include "ununpack.h"
105 char BuildVersion[]=
"ununpack build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
111 int main(
int argc,
char *argv[])
115 int rvExist1=0, rvExist2=0;
118 char *AgentName =
"ununpack";
119 char *AgentARSName =
"ununpack_ars";
120 char *agent_desc =
"Unpacks archives (iso, tar, etc)";
125 char *ListOutName=NULL;
127 char *FnameCheck = NULL;
130 char agent_rev[PATH_MAX];
136 while((c = getopt(argc,argv,
"ACc:d:FfHhL:m:PQiIqRr:T:t:U:VvXx")) != -1)
149 case 'L': ListOutName=optarg;
break;
156 case 'r':
Recurse=atoi(optarg);
break;
159 LOG_WARNING(
"dpkg-source is not available on this system. This means that debian source packages will NOT be unpacked.");
171 case 'q':
Quiet=1;
break;
196 gcry_check_version(NULL);
197 gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
198 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
206 LOG_ERROR(
"You have no update permissions on upload %s",
Upload_Pk);
212 sprintf(agent_rev,
"%s.%s", VERSION, COMMIT_HASH);
227 "SELECT ars_pk from %s where upload_fk='%s' and ars_success=TRUE",
232 if (PQntuples(result) > 0)
235 LOG_WARNING(
"Upload_pk %s, has already been unpacked. No further action required",
246 "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'",
251 if (PQntuples(result) > 0)
253 Pfile = strdup(PQgetvalue(result,0,0));
254 Pfile_Pk = strdup(PQgetvalue(result,0,1));
255 Pfile_size = atol(PQgetvalue(result, 0, 2));
259 LOG_WARNING(
"Uploaded file (Upload_pk %s), is zero length. There is nothing to unpack.",
271 if (Pfile_size > 500000000)
276 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",
281 if (PQresultStatus(result) != PGRES_NONFATAL_ERROR)
292 if (
Verbose) { fclose(stderr) ; stderr=stdout; }
293 if (ListOutName != NULL)
295 if ((ListOutName[0]==
'-') && (ListOutName[1]==
'\0'))
300 LOG_ERROR(
"pfile %s Unable to write to %s\n",
Pfile_Pk,ListOutName)
325 snprintf(
SQL,MAXSQL,
"SELECT uploadtree_pk FROM uploadtree WHERE upload_fk=%s limit 1;",
Upload_Pk);
333 for( ; optind<argc; optind++)
338 if (Fname) { free(Fname); Fname=NULL; }
339 if (ListOutName != NULL)
341 fprintf(
ListOutFile,
"<source source=\"%s\" ",argv[optind]);
347 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",argv[optind],argv[optind])
364 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",Fname,argv[optind])
376 LOG_ERROR(
"NO file unpacked. File %s does not exist either in GOLD or FILES",
Pfile);
383 FnameCheck = argv[optind];
388 if (stat(FnameCheck,&Stat))
390 LOG_ERROR(
"File to unpack is unavailable: %s, error: %s", Fname, strerror(errno));
394 if (Stat.st_size < 1)
396 LOG_WARNING(
"File to unpack is empty: %s", Fname);
423 Fin = fopen(argv[optind],
"rb");
447 if (ListOutName != NULL) fprintf(
ListOutFile,
"</source>\n");
451 if (Fname) { free(Fname); Fname=NULL; }
465 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",Fname,
Pfile)
477 LOG_ERROR(
"NO file unpacked!");
481 LOG_ERROR(
"Error is %s for %s", strerror(rvExist1), Fname);
486 LOG_ERROR(
"Error is %s for %s", strerror(rvExist2), Fname);
499 if (!
Queue[Pid].ChildEnd)
513 fprintf(
ListOutFile,
"<summary files_regular=\"%d\" files_compressed=\"%d\" artifacts=\"%d\" directories=\"%d\" containers=\"%d\" />\n",
523 snprintf(
SQL,MAXSQL,
"UPDATE upload SET upload_mode = (upload_mode | (1<<5)), uploadtree_tablename='%s' WHERE upload_pk = '%s';",
uploadtree_tablename,
Upload_Pk);
char SQL[256]
SQL query to execute.
PGconn * pgConn
Database connection.
char * uploadtree_tablename
upload.uploadtree_tablename
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
int Verbose
Verbose level.
int SetContainerArtifact
Should initial container be an artifact?
char * Pfile_Pk
Pfile pk in DB.
int ReunpackSwitch
Set if the uploadtree records are missing from db.
int UseRepository
Using files from the repository?
int MaxThread
Value between 1 and MAXCHILD.
int UnlinkSource
Remove recursive sources after unpacking?
char * Pfile
Pfile name (SHA1.MD5.Size)
int TotalDirectories
Number of directories.
unpackqueue Queue[MAXCHILD+1]
Manage children.
int Quiet
Run in quiet mode?
int Thread
Number of threads in execution.
int TotalFiles
Number of regular files.
int TotalArtifacts
Number of artifacts.
int PruneFiles
Remove links? >1 hard links, zero files, etc.
int TotalContainers
Number of containers.
char * Upload_Pk
Upload pk in DB.
int UnlinkAll
Remove ALL unpacked files when done (clean up)?
char REP_FILES[16]
Files repository name.
FILE * ListOutFile
File to store unpack list.
char REP_GOLD[16]
Gold repository name.
int IgnoreSCMData
1: Ignore SCM data, 0: dont ignore it.
int TotalCompressedFiles
Number of compressed files.
int ForceDuplicate
When using db, should it process duplicates?
int ForceContinue
Force continue when unpack tool fails?
magic_t MagicCookie
for Magic
Usage()
Print Usage statement.
FUNCTION int GetUploadPerm(PGconn *pgConn, long UploadPk, int user_pk)
Get users permission to this upload.
FUNCTION int fo_CreateARSTable(PGconn *pgConn, const char *tableName)
Create ars table if it doesn't already exist.
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.
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.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int fo_tableExists(PGconn *pgConn, const char *tableName)
Check if table exists. Note, this assumes the database name is 'fossology'.
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...
#define PERM_WRITE
Read-Write permission.
char * fo_RepMkPath(const char *Type, char *Filename)
Given a filename, construct the full path to the file.
int fo_RepExist2(char *Type, char *Filename)
Determine if a file exists.
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
Store file handler and mmap of a file.
Store check sum of a file.
uint8_t SHA1digest[20]
SHA1 digest of the file.
uint64_t DataLen
Size of the file.
uint8_t MD5digest[16]
MD5 digest of the file.
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
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 RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
void CheckCommands(int Show)
Make sure all commands are usable.
int MkDir(char *Fname)
Smart mkdir.
int ParentWait()
Wait for a child. Sets child status.
void InitCmd()
Initialize the metahandler CMD table.
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
void SafeExit(int rc)
Close scheduler and database connections, then exit.
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
int Recurse
Level of unpack recursion. Default to infinite.
char * NewDir
Test result directory.
Contains global declaration of variables.