Move zip owner to top

parent 9c9ed3ff
......@@ -71,8 +71,8 @@ struct zipflow_request {
VCL_STRING name;
unsigned mode;
uint32_t atime, mtime;
ZIP *zip;
VSTAILQ_ENTRY(zipflow_request) list;
struct zipflow_top *top;
};
VSTAILQ_HEAD(zipflow_head, zipflow_request);
......@@ -81,6 +81,7 @@ struct zipflow_top {
unsigned magic;
#define ZIPFLOW_TOP_MAGIC 0x5743145e
struct zipflow_head head;
ZIP *zip;
};
static struct zipflow_top *
......@@ -127,6 +128,7 @@ new_zipflow_request(VRT_CTX, struct zipflow_top *zft)
zfr->mode = 0644;
zfr->atime = ctx->now;
zfr->mtime = ctx->now;
zfr->top = zft;
return (zfr);
}
......@@ -301,6 +303,7 @@ static int
vdp_zipflow_init(VRT_CTX, struct vdp_ctx *vdc, void **priv, struct objcore *oc)
{
struct zipflow_request *zfr = get_zipflow_request(ctx);
struct zipflow_top *zft;
struct req *req;
if (zfr == NULL)
......@@ -308,15 +311,18 @@ vdp_zipflow_init(VRT_CTX, struct vdp_ctx *vdc, void **priv, struct objcore *oc)
AN(zfr->name);
AZ(zfr->zip);
zfr->zip = zip_pipe(vdc, vdp_zipflow_put, zfr->level);
if (zfr->zip == NULL) {
zft = zfr->top;
CHECK_OBJ_NOTNULL(zft, ZIPFLOW_TOP_MAGIC);
AZ(zft->zip);
zft->zip = zip_pipe(vdc, vdp_zipflow_put, zfr->level);
if (zft->zip == NULL) {
VSLb(vdc->vsl, SLT_Error, "zipflow: zip_pipe failed");
return (1);
}
AZ(zip_log(zfr->zip, vdc->vsl, vdp_zipflow_log));
AZ(zip_log(zft->zip, vdc->vsl, vdp_zipflow_log));
if (zfr->bundle) {
AZ(zip_meta(zfr->zip, zfr->name, 3, zfr->mode,
AZ(zip_meta(zft->zip, zfr->name, 3, zfr->mode,
zfr->atime, zfr->mtime));
}
......@@ -337,6 +343,7 @@ static int
vdp_zipflow_fini(struct vdp_ctx *vdc, void **priv)
{
struct zipflow_request *zfr;
struct zipflow_top *zft;
int r;
AN(priv);
......@@ -344,7 +351,9 @@ vdp_zipflow_fini(struct vdp_ctx *vdc, void **priv)
*priv = NULL;
if (zfr != NULL) {
CHECK_OBJ(zfr, ZIPFLOW_REQUEST_MAGIC);
r = zip_close(zfr->zip);
zft = zfr->top;
CHECK_OBJ_NOTNULL(zft, ZIPFLOW_TOP_MAGIC);
r = zip_close(zft->zip);
if (r)
VSLb(vdc->vsl, SLT_Error, "zip_close returned %d", r);
memset(zfr, 0, sizeof *zfr);
......@@ -357,15 +366,18 @@ vdp_zipflow_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
struct zipflow_request *zfr;
struct zipflow_top *zft;
int r;
AN(priv);
CAST_OBJ_NOTNULL(zfr, *priv, ZIPFLOW_REQUEST_MAGIC);
zft = zfr->top;
CHECK_OBJ_NOTNULL(zft, ZIPFLOW_TOP_MAGIC);
if (zfr->bundle == 0) {
(void) zip_close(zfr->zip);
(void) zip_close(zft->zip);
return (1);
}
r = zip_data(zfr->zip, ptr, len, act == VDP_END);
r = zip_data(zft->zip, ptr, len, act == VDP_END);
if (r) {
VSLb(vdc->vsl, SLT_Error, "zip_data returned %d", r);
return (-1);
......@@ -375,7 +387,7 @@ vdp_zipflow_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
return (0);
*priv = NULL;
r = zip_close(zfr->zip);
r = zip_close(zft->zip);
if (r)
VSLb(vdc->vsl, SLT_Error, "zip_close returned %d", r);
memset(zfr, 0, sizeof *zfr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment