diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -29,6 +29,9 @@ #include #include +#include +#include + #include #include #include @@ -389,21 +392,56 @@ int uploadOutput(char *pathtoOutput, cha int unpackJob(char *pathtoTar, int jobnum){ - char *tarcmd; /* Command to run for tar. Migrate to libtar sometime */ - char *outdir; /* Output Directory for tar */ + int ret; + int buffsize = 8192; + char *buff = ""; + size_t size; + struct archive_entry *ae = archive_entry_new(); + struct archive *a = archive_read_new(); + + archive_read_support_compression_all(a); + archive_read_support_format_raw(a); + ret = archive_read_open_filename(a, pathtoTar, 16384); + if (ret != ARCHIVE_OK) { + return 1; + } + ret = archive_read_next_header(a, &ae); + if (ret != ARCHIVE_OK) { + return 1; + } + for (;;) { + size = archive_read_data(a, buff, buffsize); + if (size < 0) { + return 1; + } + if (size == 0) + break; + write(1, buff, size); + } + + archive_read_finish(a); + archive_entry_free(ae); + + return 0; + +/* + char *tarcmd; // Command to run for tar. Migrate to libtar sometime + char *outdir; // Output Directory for tar _distren_asprintf(&outdir, "/tmp/distren/job%d", jobnum); - mkdir("/tmp/distren", 0750); /* @FIXME: Change to tmpdir once it exists */ + mkdir("/tmp/distren", 0750); // @FIXME: Change to tmpdir once it exists mkdir(outdir, 0750); - _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @FIXME:Use a lib here! */ + _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); // @FIXME:Use a lib here! system(tarcmd); free(tarcmd); free(pathtoTar); free(outdir); return 0; + */ } + void prepareJobPaths(int jobnum,char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoXml){ // Variable Preparation char *jobdatapath;