Ejemplo n.º 1
0
int Untar_FromGzChunk_Print(
  Untar_GzChunkContext *ctx,
  void *chunk,
  size_t chunk_size,
  const rtems_printer *printer
)
{
  int untar_succesful;
  int status;

  ctx->strm.next_in = (Bytef *)chunk;
  ctx->strm.avail_in = (size_t)chunk_size;

    /* Inflate until output buffer is not full */
  do {
    ctx->strm.next_out = (Bytef *) ctx->inflateBuffer;
    ctx->strm.avail_out = ctx->inflateBufferSize;

    status = inflate(&ctx->strm, Z_NO_FLUSH);
    if (status == Z_OK || status == Z_STREAM_END) {
      size_t inflated_size =
        ctx->inflateBufferSize - ctx->strm.avail_out;
      untar_succesful = Untar_FromChunk_Print(&ctx->base,
        ctx->inflateBuffer, inflated_size, NULL);
      if (untar_succesful != UNTAR_SUCCESSFUL){
        return untar_succesful;
      }
    }
  } while (ctx->strm.avail_out == 0 && ctx->strm.avail_in > 0
      && status == Z_OK);

  if (status != Z_OK) {
    if (untar_succesful != UNTAR_SUCCESSFUL){
      rtems_printf(printer, "Untar not successful\n");
    }

    if (status != Z_STREAM_END) {
      rtems_printf(printer, "Zlib inflate failed\n");
    }

    status = inflateEnd(&ctx->strm);
    if (status != Z_OK) {
      rtems_printf(printer, "Zlib inflate end failed\n");
    }
  }
  return untar_succesful;
}
Ejemplo n.º 2
0
void test_untar_chunks_from_memory(void)
{
  rtems_status_code sc;
  rtems_printer     printer;
  int rv;
  Untar_ChunkContext ctx;
  unsigned long counter = 0;
  char *buffer = (char *)TARFILE_START;
  size_t buflen = TARFILE_SIZE;

  puts( "" );

  rtems_print_printer_printf(&printer);

  /* make a directory to untar it into */
  rv = mkdir( "/dest2", 0777 );
  rtems_test_assert( rv == 0 );

  rv = chdir( "/dest2" );
  rtems_test_assert( rv == 0 );

  printf( "Untaring chunks from memory - " );
  Untar_ChunkContext_Init(&ctx);
  do {
    sc = Untar_FromChunk_Print(&ctx, &buffer[counter], (size_t)1 , &printer);
    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    counter ++;
  } while (counter < buflen);
  printf("successful\n");

  /******************/
  printf( "========= /dest2/home/test_file =========\n" );
  test_cat( "/dest2/home/test_file", 0, 0 );

  /******************/
  printf( "========= /dest2/home/test_script =========\n" );
  test_cat( "/dest2/home/test_script", 0, 0 );
  test_untar_check_mode("/dest2/home/test_script", 0755);

  /******************/
  printf( "========= /dest2/symlink =========\n" );
  test_cat( "/dest2/symlink", 0, 0 );

}