]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add archive_write_fail() utility to force a write
authorTim Kientzle <kientzle@acm.org>
Tue, 29 May 2012 20:08:34 +0000 (13:08 -0700)
committerTim Kientzle <kientzle@acm.org>
Tue, 29 May 2012 20:08:34 +0000 (13:08 -0700)
handle to abort prematurely.

libarchive/archive.h
libarchive/archive_virtual.c
libarchive/archive_write_free.3

index 48b5d54620c7600b253ce573afa42398dc7cec4d..526815f52f435eea2aeddbd5b4c55edf4fd4215b 100644 (file)
@@ -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 *);
index 83089f27f942faaf75d9a79312cd93d8af832adc..0c4155f21e3b1f6e62ac2c45cc4033585cdba40b 100644 (file)
@@ -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)
 {
index ac01dd4b96ddaf446a417849a6fbc0af0b69d34f..1b2d07131d8efdfac3e7155ec59e985eace66975 100644 (file)
@@ -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