Exemple #1
0
static int32_t pkg_xar_err_callback(int32_t sev, int32_t err, xar_errctx_t ctx, void *usrctx) {
   xar_file_t  f;
   xar_t       x;
   const char *str;
   int         e;

   x = xar_err_get_archive(ctx);
   f = xar_err_get_file(ctx);
   str = xar_err_get_string(ctx);
   e = xar_err_get_errno(ctx);

   switch (sev) {
      case XAR_SEVERITY_DEBUG:
      case XAR_SEVERITY_INFO:
         break;
      case XAR_SEVERITY_WARNING:
         printf("%s\n", str);
         break;
      case XAR_SEVERITY_NORMAL:
         break;
      case XAR_SEVERITY_NONFATAL:
      case XAR_SEVERITY_FATAL:
         if (f) {
            const char *file = xar_get_path(f);
            if (file)
               printf(":(%s)", file);

            free((char *)file);
         }

         if (str)
            printf(": %s", str);

         if (err)
            printf(" (%s)", strerror(e));
         if (sev == XAR_SEVERITY_NONFATAL) {
            printf(" - ignored");
            printf("\n");
         } else {
            printf("-- aborting\n");
            raise(SIGTERM);
         }

         break;
   }
   return 0;
}
Exemple #2
0
static int32_t err_callback(int32_t sev, int32_t err, xar_errctx_t ctx, void *usrctx) {
	xar_file_t f;
	xar_t x;
	const char *str;
	int e;

	x = xar_err_get_archive(ctx);
	f = xar_err_get_file(ctx);
	str = xar_err_get_string(ctx);
	e = xar_err_get_errno(ctx);

	switch(sev) {
	case XAR_SEVERITY_DEBUG:
	case XAR_SEVERITY_INFO:
		break;
	case XAR_SEVERITY_WARNING:
		printf("%s\n", str);
		break;
	case XAR_SEVERITY_NORMAL:
		if( (err = XAR_ERR_ARCHIVE_CREATION) && f )
    			print_file(x, f);
		break;
	case XAR_SEVERITY_NONFATAL:
	case XAR_SEVERITY_FATAL:
		Err = 2;
		printf("Error while ");
		if( err == XAR_ERR_ARCHIVE_CREATION ) printf("creating");
		if( err == XAR_ERR_ARCHIVE_EXTRACTION ) printf("extracting");
		printf(" archive");
		if( f ) {
			const char *file = xar_get_path(f);
			if( file ) printf(":(%s)", file);
			free((char *)file);
		}
		if( str ) printf(": %s", str);
		if( err ) printf(" (%s)", strerror(e));
		if( sev == XAR_SEVERITY_NONFATAL ) {
			printf(" - ignored");
			printf("\n");
		} else {
			printf("\n");
			exit(1);
		}
		break;
	}
	return 0;
}