From aceae78232e864a97c8c36e798bbb072c4901fae Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 29 May 2012 13:08:34 -0700 Subject: [PATCH] Add archive_write_fail() utility to force a write handle to abort prematurely. --- libarchive/archive.h | 4 ++++ libarchive/archive_virtual.c | 7 +++++++ libarchive/archive_write_free.3 | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/libarchive/archive.h b/libarchive/archive.h index 48b5d5462..526815f52 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -648,6 +648,10 @@ __LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, __LA_DECL int archive_write_finish_entry(struct archive *); __LA_DECL int archive_write_close(struct archive *); +/* Marks the archive as FATAL so that a subsequent free() operation + * won't try to close() cleanly. Provides a fast abort capability + * when the client discovers that things have gone wrong. */ +__LA_DECL int archive_write_fail(struct archive *); /* This can fail if the archive wasn't already closed, in which case * archive_write_free() will implicitly call archive_write_close(). */ __LA_DECL int archive_write_free(struct archive *); diff --git a/libarchive/archive_virtual.c b/libarchive/archive_virtual.c index 83089f27f..0c4155f21 100644 --- a/libarchive/archive_virtual.c +++ b/libarchive/archive_virtual.c @@ -66,6 +66,13 @@ archive_read_close(struct archive *a) return ((a->vtable->archive_close)(a)); } +int +archive_write_fail(struct archive *a) +{ + a->state = ARCHIVE_STATE_FATAL; + return a->state; +} + int archive_write_free(struct archive *a) { diff --git a/libarchive/archive_write_free.3 b/libarchive/archive_write_free.3 index ac01dd4b9..1b2d07131 100644 --- a/libarchive/archive_write_free.3 +++ b/libarchive/archive_write_free.3 @@ -28,6 +28,7 @@ .Dt ARCHIVE_WRITE_FREE 3 .Os .Sh NAME +.Nm archive_write_fail , .Nm archive_write_close , .Nm archive_write_finish , .Nm archive_write_free @@ -37,6 +38,8 @@ Streaming Archive Library (libarchive, -larchive) .Sh SYNOPSIS .In archive.h .Ft int +.Fn archive_write_fail "struct archive *" +.Ft int .Fn archive_write_close "struct archive *" .Ft int .Fn archive_write_finish "struct archive *" @@ -44,6 +47,16 @@ Streaming Archive Library (libarchive, -larchive) .Fn archive_write_free "struct archive *" .Sh DESCRIPTION .Bl -tag -width indent +.It Fn archive_write_fail +Always returns +.Cm ARCHIVE_FATAL . +This marks the archive object as being unusable; +after calling this function, the only call that can succeed is +.Fn archive_write_free +to release the resources. +This can be used to speed recovery when the archive creation +must be aborted. +Note that the created archive is likely to be malformed in this case; .It Fn archive_write_close Complete the archive and invoke the close callback. .It Fn archive_write_finish -- 2.47.2