Changeset - e1171561f32f
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 16 years ago 2010-03-13 23:56:05
ohnobinki@ohnopublishing.net
attempt to fix up libarchive usage in unpackJob()
4 files changed with 59 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/server/simpleslave.c
Show inline comments
 
@@ -155,13 +155,13 @@ int main(int argc, char *argv[])
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar, &pathtoJobfile, &urltoOutput, &pathtoOutput);
 
        free(outputExt);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
 
          return 1;
 

	
 
        unpackJob(pathtoTar, jobnum);
 
        unpackJob(datadir, pathtoTar);
 

	
 
        /* Execute blender */
 
        if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
          {
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
            return 1;
src/server/slave.c
Show inline comments
 
@@ -147,13 +147,13 @@ int main(int argc, char *argv[])
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar, &pathtoJobfile, &urltoOutput, &pathtoOutput);
 
        free(outputExt);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
 
          return 1;
 

	
 
        unpackJob(pathtoTar, jobnum);
 
        unpackJob(datadir, pathtoTar);
 

	
 
        /* Execute blender */
 
        if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
          {
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
            return 1;
src/server/slavefuncs.c
Show inline comments
 
@@ -402,65 +402,78 @@ int uploadOutput(char *pathtoOutput, cha
 
        }
 
      return 1; // Upload failed after multiple tries
 
      // @FUTURE: Keep track of files that we were unable to upload, and upload them later
 
    }
 
}
 

	
 

	
 
int unpackJob(char *pathtoTar, int jobnum){
 
/**
 
   Extracts archive to the specified directory, creating this directory
 
   if necessary (but this directory will not be recursively created).
 
   @param outdir output directory
 
   @param pathtoTar filename of the archive to extract
 
 */
 
int unpackJob(char *outdir, char *pathtoTar)
 
{
 
  int ret;
 
  int buffsize = 8192;
 
  char *buff = "";
 
  size_t size;
 
  struct archive_entry *ae = archive_entry_new();
 
  struct archive *a = archive_read_new();
 

	
 
  struct archive *a;
 
  struct archive_entry *ae;
 
  int astatus;
 

	
 
  /* ignore return because directory may exist already */
 
  mkdir(outdir, 0700);
 
  ret = chdir(outdir);
 
  if(ret == -1)
 
    {
 
      perror("chdir");
 
      return 1;
 
    }
 

	
 
  a = archive_read_new();
 
  ae = archive_entry_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) {
 
  astatus = archive_read_open_filename(a, pathtoTar, 8192);
 
  if (astatus != ARCHIVE_OK)
 
    {
 
      fprintf(stderr, "error opening archive\n");
 
      return 1;
 
    }
 
    if (size == 0)
 
      break;
 
    write(1, buff, size);
 
  }
 

	
 
  for(astatus = ARCHIVE_OK;
 
      astatus == ARCHIVE_OK
 
	|| astatus == ARCHIVE_WARN;
 
      )
 
    {
 
      astatus = archive_read_next_header2(a, ae);
 
      if(astatus == ARCHIVE_WARN)
 
	fprintf(stderr, "Encountered nonfatal read error somehow\n");
 

	
 
      if(astatus == ARCHIVE_OK
 
	 || astatus == ARCHIVE_WARN)
 
	astatus = archive_read_extract(a, ae,
 
				       ARCHIVE_EXTRACT_NO_OVERWRITE
 
				       | ARCHIVE_EXTRACT_SECURE_SYMLINKS
 
				       | ARCHIVE_EXTRACT_SECURE_NODOTDOT);
 
    }
 
  archive_entry_free(ae);
 
  archive_read_finish(a);
 
  archive_entry_free(ae);
 
  
 
  if(astatus != ARCHIVE_EOF)
 
    {
 
      fprintf(stderr, "Error reading archive\n");
 
      return 1;
 
    }
 

	
 
  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(outdir, 0750);
 

	
 
  _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, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoOutput){
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoOutput)
 
{
 
  // Variable Preparation
 
  char *jobdatapath;
 
   _distren_asprintf(&jobdatapath, "job%d", jobnum);
 
   _distren_asprintf(urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum); // Prepares URL to download from
 
   _distren_asprintf(pathtoTar, "%s/stor/jobdata/job%d.tar.gz", datadir, jobnum); // Prepares destination to save to
 
   _distren_asprintf(pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
 
@@ -494,13 +507,14 @@ int checkUsername(char *username)
 
       {
 
         fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n");
 
         return 1;
 
       }
 
}
 

	
 
void slaveTest(){
 
void slaveTest(char *datadir)
 
{
 
  int command;
 
  int test = 1;
 
  int jobnum = 0;
 
  int framenum = 0;
 
  int slavekey = 0;
 
  fprintf(stderr,"Hello!\n");
 
@@ -547,13 +561,13 @@ void slaveTest(){
 
       break;
 
     case 4:
 
       fprintf(stderr,"Jobnum to decompress: ");
 
       scanf("%d", &jobnum);
 
       fprintf(stderr,"Path to compressed data: ");
 
       scanf("%s", tmpString2);
 
       unpackJob(tmpString1, jobnum);
 
       unpackJob(datadir, tmpString1);
 
       break;
 
     case 5:
 
       test = 0;
 
       break;
 
     default:
 
       fprintf(stderr, "Invalid input, please try again.\n");
src/server/slavefuncs.h
Show inline comments
 
@@ -45,13 +45,13 @@ int exec_blender(char *input, char *outp
 
void xmlinit();
 
void xmlcleanup();
 
int distren_mkdir_recurse(char *dirname);
 
int job_build_path(char *filename, unsigned int jobnum);
 
int downloadTar(char *url, char *destinationPath);
 
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey);
 
int unpackJob(char *pathtoTar, int jobnum);
 
int unpackJob(char *outdir, char *pathtoTar);
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoJobfile,char **urltoOutput,char **pathtoOutput);
 
int checkUsername(char *username);
 
void slaveTest();
 

	
 
/* Simple slave */
 
struct _web_memorystruct;
0 comments (0 inline, 0 general)