Changeset - e166f7bf8ca0
[Not reviewed]
default
0 1 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-02-20 20:47:37
e@ethanzonca.com
Initial libarchive implementation of unpackJob
1 file changed with 42 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -29,6 +29,9 @@
 
#include <curl/easy.h>
 
#include <curl/types.h>
 

	
 
#include <archive.h>
 
#include <archive_entry.h>
 

	
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
@@ -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;
0 comments (0 inline, 0 general)