Пример #1
0
static PGPError
SizeAdvise (PGPPipeline *myself, unsigned long bytes)
{
	DefModContext *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == DEFMODMAGIC);

	context = (DefModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	if (bytes || context->scope_depth)
		return( kPGPError_NoErr );

	if (!context->finished) {
		/* It is a Bad Thing to call zip_finish multiple times. */
		zip_finish (context->zdcontext, context->ztcontext,
					context->zbcontext);
		context->finished = 1;
	}
	error = DoFlush (context);
	if (error)
		return error;

	return context->tail->sizeAdvise (context->tail, 0);
}
Пример #2
0
int zipfile_delete_files (const char *targ, const char **filenames,
			  ZipOption opt, GError **gerr)
{
    zfile zf;
    gchar *matches = NULL;
    int err;

    g_return_val_if_fail(targ != NULL, 1);
    g_return_val_if_fail(filenames != NULL, 1);

    trace(1, "zipfile_delete_files: targ = '%s'\n", targ);

    matches = make_match_array(filenames);

    zfile_init(&zf, 0, opt);

    if (matches == NULL) {
	err = ZE_MEM;
	if (gerr != NULL) {
	   make_gerr(err, gerr);
	}
	return err;
    }

    zf.wanted = filenames;
    zf.matches = matches;

    err = process_zipfile(&zf, targ, ZIP_DO_DELETE);

    trace(2, "zipfile_delete_files: process_zipfile returned %d\n", err);

    if (!err) {
	err = check_matches(filenames, matches);
    }

    if (!err) {
	err = real_delete_files(&zf);
    }

    free(matches);

    if (err && gerr != NULL) {
	make_gerr(err, gerr);
    } 

    zip_finish(&zf);

    return err;
}
Пример #3
0
int zlib_stream::pop_end(string* out, size_t max /* = 0 */ acl_unused)
{
	if (out == NULL)
		return (0);

	size_t n = out->length();
	if (is_compress_)
	{
		if (zip_finish(out) == false)
			return (-1);
	}
	else
	{
		if (unzip_finish(out) == false)
			return (-1);
	}

	return ((int) (out->length() - n));
}
Пример #4
0
int zipfile_extract_files (const char *targ,
			   const char **filenames,
			   const char *eprefix,
			   ZipOption opt,
			   GError **gerr)
{
    zfile zf;
    gchar *matches = NULL;
    int err;

    g_return_val_if_fail(targ != NULL, 1);

    if (filenames != NULL) {
	matches = make_match_array(filenames);
    }

    zfile_init(&zf, 0, opt);

    zf.wanted = filenames;
    zf.eprefix = eprefix;
    zf.matches = matches;

    err = process_zipfile(&zf, targ, ZIP_DO_UNZIP);

    trace(2, "zipfile_extract_files: process_zipfile returned %d\n", err);

    if (!err && matches != NULL) {
	err = check_matches(filenames, matches);
    }

    free(matches);

    if (err && gerr != NULL) {
	make_gerr(err, gerr);
    } 

    zip_finish(&zf);

    return err;
}
Пример #5
0
zipinfo *zipfile_get_info (const char *targ, ZipOption opt, GError **gerr)
{
    zipinfo *zinfo;
    zfile zf;
    int err;

    g_return_val_if_fail(targ != NULL, NULL);

    zinfo = zipinfo_new(targ);
    if (zinfo == NULL) {
	err = ZE_MEM;
	goto bailout;
    }

    zfile_init(&zf, 0, opt);

    err = process_zipfile(&zf, targ, ZIP_DO_LIST);

    trace(2, "zipfile_get_info: process_zipfile returned %d\n", err);

    if (!err) {
	err = record_zfiles(zinfo);
    }

 bailout:

    if (err) {
	if (gerr != NULL) {
	    make_gerr(err, gerr);
	}
	zipinfo_destroy(zinfo);
	zinfo = NULL;
    } 

    zip_finish(&zf);

    return zinfo;
}
Пример #6
0
static int real_archive_files (const char *targ, const char **filenames, 
			       int level, ZipOption opt, int task,
			       GError **gerr)
{
    int attr;             /* attributes of zip file */
    flist *f;             /* steps through found linked list */
    int i;                /* arg counter, root directory flag */
    int k;                /* marked counter, comment size, entry count */
    int openerr = 0;      /* true if there were any ZE_OPEN errors */
    guint32 t;            /* file time, length of central directory */
    zlist **w;            /* pointer to last link in zfiles list */
    zlist *z;             /* steps through zfiles linked list */
    FILE *fr = NULL;      /* for reading from original zipfile */
    char tempzip[FILENAME_MAX]; /* name for temporary zipfile */
    int err = 0;
    zfile zf;

    *tempzip = '\0';

    if (level < 0 || level > 9) {
	fprintf(stderr, "invalid compression level %d: setting to 6\n", level);
	level = 6;
    }

    zfile_init(&zf, level, opt);

    trace(1, "real_archive_files: targ = '%s'\n", targ);

    zf.fname = g_strdup(targ);
    if (zf.fname == NULL) {
	err = ziperr(ZE_MEM, "was processing arguments");
	goto bailout;
    }

    if (task != ZIP_DO_NEW) {
	/* if ZIP_DO_NEW, disregard any existing zipfile */
	err = read_zipfile(&zf, ZIP_DO_ZIP);
	if (err) {
	    err = ziperr(err, zf.fname);
	    goto bailout;
	}
    } 

    /* assemble list of filenames to be added/updated */
    k = 0;
    for (i=0; filenames[i] != NULL; i++) {
	if (!gretl_file_test(filenames[i], G_FILE_TEST_EXISTS)) {
	    err = ziperr(ZE_OPEN, "file '%s' was not found", filenames[i]);
	    goto bailout;
	}
	err = add_filenames(filenames[i], &zf);
	if (err) {
	    ziperr(err, filenames[i]);
	    goto bailout;
	} else {
	    k++;
	}
    }

    if (k == 0) {
	err = ziperr(ZE_NONE, NULL);
	goto bailout;
    }

    if (zf.zcount) {
	free(zf.zsort);
	zf.zsort = NULL;
    }

    /* For each marked entry, check if it exists, and, if updating,
       compare date with entry in existing zipfile.  Unmark if it
       doesn't exist or is too old, else update marked count.
    */
    k = 0; 
    for (z = zfiles; z != NULL; z = z->nxt) {
	if (z->mark == MARK_ZIP) {
	    if (dont_keep_file(z, &zf)) {
		z->mark = MARK_NONE;
	    } else {
		k++;
	    }
	}
    }

    /* Remove entries from "found" list that do not exist or are
       otherwise invalid
    */
    for (f = found; f != NULL; ) {
	t = file_mod_time(f->name, NULL, NULL, NULL, &zf);
	if (t == 0 || !fnamecmp(f->zname, zf.fname)) {
	    f = flist_expel(f, &zf.fcount);
	} else {
	    f = f->nxt;
	}
    }

    err = zipfile_write_check(&zf, task, &attr);
    if (err) {
	goto bailout;
    }

    if (zfiles != NULL || zf.zstart) {
	trace(1, "opening original zip file for reading\n");
	fr = fopen(zf.fname, "rb");
	if (fr == NULL) {
	    err = ziperr(ZE_NAME, zf.fname);
	    goto bailout;
	}
    }

    strcpy(tempzip, zf.fname);
    zf.fp = ztempfile(tempzip);
    if (zf.fp == NULL) {
	fprintf(stderr, " real_archive_files: ztempfile failed\n");
	err = ziperr(ZE_TEMP, tempzip);
	goto bailout;
    }

    if (zf.zstart > 0) {
	/* copy initial chunk of old zipfile as is */
	err = fcopy(fr, zf.fp, zf.zstart);
	if (err != Z_OK) {
	    err = ziperr(err, (err == ZE_TEMP)? tempzip : zf.fname);
	    goto bailout;
	}
    }

    zf.tempzn = zf.zstart;
    trace(2, "after initial read, tempzn = %d\n", (int) zf.tempzn);

    err = process_zfiles(&zf, fr, &w, &openerr);
    if (err) {
	fclose(zf.fp);
	if (fr != NULL) {
	    fclose(fr);
	}
	goto bailout;
    }

    /* Process the edited found list, adding them to the zip file */
    trace(2, "now zipping up new entries, fcount=%u\n", (unsigned) zf.fcount);
  
    for (f = found; f != NULL; f = flist_expel(f, &zf.fcount)) {
	/* add a new zfiles entry and set the name */
	z = zlist_entry_new(f);
	if (z == NULL) {
	    err = ziperr(ZE_MEM, "was adding files to zip file");
	    goto bailout;
	}	    

	err = zipup(&zf, z);

	if (err && err != ZE_OPEN && err != ZE_MISS) {
	    err = ziperr(err, "was zipping %s", z->zname);
	    goto bailout;
	}

	if (err == ZE_OPEN || err == ZE_MISS) {
	    openerr = 1;
	    if (err == ZE_OPEN) {
		perror("zip warning");
	    } 
	    free_zlist_entry(z);
	} else {
	    *w = z;
	    w = &z->nxt;
	    zf.zcount += 1;
	}
    }

    err = write_central_and_end(&zf, tempzip);
    fclose(zf.fp);
    zf.fp = NULL;

    if (fr != NULL) {
	fclose(fr);
    }

    /* Replace old zip file with new zip file, leaving only the new one */
    if (!err) {
	trace(1, "moving %s into position as %s\n", tempzip, zf.fname);
	err = replace_file(zf.fname, tempzip);
	if (err) {
	    ziperr(err, "was replacing %s", zf.fname);
	} else if (attr) {
	    chmod(zf.fname, attr);
	}
    }

 bailout:

    zlib_deflate_free(&zf);

    if (err && *tempzip != '\0') {
	/* clean up */
	gretl_remove(tempzip);
    }

    zip_finish(&zf);

    if (err && gerr != NULL) {
	make_gerr(err, gerr);
    }

    trace(1, "returning err = %d\n", err);

    return err;
}