netcdf-c/nczarr_test/test_nczarr_utils.h
Dennis Heimbigner e7d5f24078 Add zip file support
The primary change is to support the use of a zip file as a
storage format. Simultaneously the .nz4 support is made obsolete

Use of zip requires the libzip support library, so a number of
changes to the build files (Makefile.am, CMakeLists.txt) are
necessary to locate and incorporate libzip.  The nczarr_tests
tests are also changed to add zip testing.

Other changes:
* Make sure distcheck leaves no files around.
* Add some functions to netcdf_aux to export some functions of libnetcdf.
* Add a new error NC_EFOUND as the complement of NC_EEMPTY.
* Add tracing support to nclog and use it in libnczarr.
* Modify the zmap interface to support the writeonce semantics of zip.
* Create a new s3util.c to support a variety of S3 auxilliary functions.
* EXTERNL'ize a number of functions so they can be used in s3util.
* Add support for the S3 ListObjects CommonPrefixes mechanism
  to improve search.
* Add experimental support for running nczarr X s3 tests against
  the actual Amazon S3 cloud.
2021-01-28 20:11:01 -07:00

164 lines
3.6 KiB
C

/* This is part of the netCDF package.
Copyright 2018 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
@Author Dennis Heimbigner
*/
/*********************************************************************
* Copyright 2018, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
/* $Id: main.c,v 1.33 2010/05/26 21:43:36 dmh Exp $ */
/* $Header: /upc/share/CVS/netcdf-3/ncgen/main.c,v 1.33 2010/05/26 21:43:36 dmh Exp $ */
#ifndef TEST_NCZARR_UTILS_H
#define TEST_NCZARR_UTILS_H
#include "config.h"
#include <assert.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef _MSC_VER
#include "XGetopt.h"
#endif
#include "nc_tests.h"
#include "err_macros.h"
#include "ncbytes.h"
#include "zincludes.h"
static char* progname = NULL;
struct ITOptions {
NCZM_IMPL impl;
char* path;
char* cloud;
char* otherfragments;
} itoptions = {NCZM_UNDEF, NULL, NULL, NULL};
static void
test_usage(void)
{
fprintf(stderr,"usage: <test> [-e <zmapimpl>]\n");
exit(1);
}
/* strip off leading path; result is malloc'd */
static char *
ubasename(char *logident)
{
char* sep;
sep = strrchr(logident,'/');
#ifdef MSDOS
if(sep == NULL) sep = strrchr(logident,'\\');
#endif
if(sep == NULL) return logident;
sep++; /* skip past the separator */
return sep;
}
static void
setimpl(const char* name)
{
if(strcasecmp(name,"s3")==0) itoptions.impl = NCZM_S3;
else if(strcasecmp(name,"file")==0) itoptions.impl = NCZM_FILE;
else if(strcasecmp(name,"zip")==0) itoptions.impl = NCZM_ZIP;
else test_usage();
}
static const char*
implname(void)
{
switch (itoptions.impl) {
case NCZM_S3: return "s3";
case NCZM_FILE: return "file";
case NCZM_ZIP: return "zip";
default: test_usage();
}
return NULL;
}
static void
buildpath(const char* target,NCZM_IMPL impl)
{
NCbytes* buf = ncbytesnew();
switch(itoptions.impl) {
case NCZM_ZIP:
case NCZM_FILE:
ncbytescat(buf,"file://");
ncbytescat(buf,target);
ncbytescat(buf,".");
ncbytescat(buf,implname());
ncbytescat(buf,"#mode=nczarr");
ncbytescat(buf,",");
ncbytescat(buf,implname());
break;
case NCZM_S3:
ncbytescat(buf,itoptions.cloud);
if(itoptions.cloud[strlen(itoptions.cloud)-1] != '/')
ncbytescat(buf,"/");
ncbytescat(buf,target);
ncbytescat(buf,"#mode=nczarr");
ncbytescat(buf,",");
ncbytescat(buf,implname());
break;
default: test_usage();
}
if(itoptions.otherfragments != NULL) {
ncbytescat(buf,",");
ncbytescat(buf,itoptions.otherfragments);
}
itoptions.path = ncbytesextract(buf);
ncbytesfree(buf);
}
void
processoptions(int argc, char** argv, const char* base_file_name)
{
int c;
if(argc == 1) test_usage();
progname = nulldup(ubasename(argv[0]));
while ((c = getopt(argc, argv, "e:c:F:")) != EOF)
switch(c) {
case 'e': /* zmap choice */
setimpl(optarg);
break;
case 'c': /* cloud appliance url prefix*/
itoptions.cloud = strdup(optarg);
break;
case 'F': /* fragments */
itoptions.otherfragments = strdup(optarg);
break;
case '?':
test_usage();
break;
}
argc -= optind;
argv += optind;
if(itoptions.impl == NCZM_UNDEF) itoptions.impl = NCZM_FILE;
if(itoptions.impl == NCZM_S3 && itoptions.cloud == NULL) test_usage();
buildpath(base_file_name,itoptions.impl);
}
void
clearoptions(void)
{
nullfree(itoptions.path);
nullfree(itoptions.cloud);
nullfree(itoptions.otherfragments);
nullfree(progname);
}
#endif /*TEST_NCZARR_UTILS_H*/