int extractTar(char *path, char *destPath){
	basePath = destPath;
	FILE* a = fopen(path, "rb");
	if (!a)
		return ARCHIVE_ERROR;
	untar(a, path);
	fclose(a);
	return ARCHIVE_SUCCESS;
}
Example #2
0
Future<pair<string, string>> untarLayer(
    const string& layerPath,
    const string& directory,
    const string& layerId)
{
  // We untar the layer from source into a directory, then move the
  // layer into store. We do this instead of untarring directly to
  // store to make sure we don't end up with partially untarred layer
  // rootfs.

  const string localRootfsPath =
    paths::getImageArchiveLayerRootfsPath(directory, layerId);

  // Image layer has been untarred but is not present in the store directory.
  if (os::exists(localRootfsPath)) {
    LOG(WARNING) << "Image layer '" << layerId << "' rootfs present in staging "
                 << "directory but not in store directory '"
                 << localRootfsPath << "'. Removing staged rootfs and untarring"
                 << "layer again.";

    Try<Nothing> rmdir = os::rmdir(localRootfsPath);
    if (rmdir.isError()) {
      return Failure("Failed to remove incomplete staged rootfs for layer '" +
                     layerId + "': " + rmdir.error());
    }
  }

  Try<Nothing> mkdir = os::mkdir(localRootfsPath);
  if (mkdir.isError()) {
    return Failure("Failed to create rootfs path '" + localRootfsPath +
                   "': " + mkdir.error());
  }

  // The tar file will be removed when the staging directory is
  // removed.
  return untar(
      layerPath,
      localRootfsPath)
    .then([directory, layerId]() -> Future<pair<string, string>> {
      const string rootfsPath =
        paths::getImageArchiveLayerRootfsPath(directory, layerId);

      if (!os::exists(rootfsPath)) {
        return Failure("Failed to find the rootfs path after extracting layer"
                       " '" + layerId + "'");
      }

      return pair<string, string>(layerId, rootfsPath);
    });
}
Example #3
0
static void bcast(char * src, char * PREFIX) {
    if(NodeRank != 0) {
        MPI_Barrier(MPI_COMM_WORLD);
        return;
    }

    double t1;
    long fsize;
    char *fcontent;
    char * dest = alloca(strlen(PREFIX) + 100);
    char * filename = basename(src);

    sprintf(dest, "%s/%s-%d",  PREFIX, filename, ThisTask);

    free(filename);

    t1 = MPI_Wtime();

    if(ThisTask == 0) {
        FILE * fp = fopen(src, "r");
        if(fp == NULL) {
            fprintf(stderr, "package file %s not found\n", src);
            MPI_Abort(MPI_COMM_WORLD, 1);
        }
        fseek(fp, 0, SEEK_END);
        fsize = ftell(fp);
        fseek(fp, 0, SEEK_SET);

        fcontent = malloc(fsize + 1);
        fread(fcontent, 1, fsize, fp);
        fclose(fp);
        MPI_Bcast(&fsize, 1, MPI_LONG, 0, NODE_LEADERS);
        MPI_Bcast(fcontent, fsize, MPI_BYTE, 0, NODE_LEADERS);
        if(VERBOSE) {
            printf("Bcasting %s: %ld bytes\n", src, fsize);
            fflush(stdout);
        }
    } else {
        MPI_Bcast(&fsize, 1, MPI_LONG, 0, NODE_LEADERS);
        fcontent = malloc(fsize + 1);
        MPI_Bcast(fcontent, fsize, MPI_BYTE, 0, NODE_LEADERS);
    }
    
    MPI_Barrier(NODE_LEADERS);
    FILE * fp = fopen(dest, "w");
    if(fp == NULL) {
        fprintf(stderr, "Cannot write to %s\n", dest);
        MPI_Abort(MPI_COMM_WORLD, 1);
    }
    fwrite(fcontent, 1, fsize, fp);
    fclose(fp);
    free(fcontent);

    t_bcast += MPI_Wtime() - t1;
    
    t1 = MPI_Wtime();
    untar(dest, PREFIX);
    unlink(dest);

    MPI_Barrier(NODE_LEADERS);

    MPI_Barrier(MPI_COMM_WORLD);
    t_tar += MPI_Wtime() - t1;

    if(ThisTask == 0) {
        if(VERBOSE) {
            printf("Packages delivered. \n");
            fflush(stdout);
        }
    }
}