aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/archive_write_set_format_xar.c
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/archive_write_set_format_xar.c')
-rw-r--r--libarchive/archive_write_set_format_xar.c65
1 files changed, 47 insertions, 18 deletions
diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c
index 5e4b90e06b3f..d456cf8f8aa9 100644
--- a/libarchive/archive_write_set_format_xar.c
+++ b/libarchive/archive_write_set_format_xar.c
@@ -212,8 +212,8 @@ struct file {
struct heap_data data;
struct archive_string script;
- int virtual:1;
- int dir:1;
+ signed int virtual:1;
+ signed int dir:1;
};
struct hardlink {
@@ -411,6 +411,8 @@ xar_options(struct archive_write *a, const char *key, const char *value)
if (strcmp(key, "checksum") == 0) {
if (value == NULL)
xar->opt_sumalg = CKSUM_NONE;
+ else if (strcmp(value, "none") == 0)
+ xar->opt_sumalg = CKSUM_NONE;
else if (strcmp(value, "sha1") == 0)
xar->opt_sumalg = CKSUM_SHA1;
else if (strcmp(value, "md5") == 0)
@@ -429,6 +431,8 @@ xar_options(struct archive_write *a, const char *key, const char *value)
if (value == NULL)
xar->opt_compression = NONE;
+ else if (strcmp(value, "none") == 0)
+ xar->opt_compression = NONE;
else if (strcmp(value, "gzip") == 0)
xar->opt_compression = GZIP;
else if (strcmp(value, "bzip2") == 0)
@@ -482,6 +486,8 @@ xar_options(struct archive_write *a, const char *key, const char *value)
if (strcmp(key, "toc-checksum") == 0) {
if (value == NULL)
xar->opt_toc_sumalg = CKSUM_NONE;
+ else if (strcmp(value, "none") == 0)
+ xar->opt_toc_sumalg = CKSUM_NONE;
else if (strcmp(value, "sha1") == 0)
xar->opt_toc_sumalg = CKSUM_SHA1;
else if (strcmp(value, "md5") == 0)
@@ -696,13 +702,37 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s)
else
run = ARCHIVE_Z_FINISH;
/* Compress file data. */
- r = compression_code(&(a->archive), &(xar->stream), run);
- if (r != ARCHIVE_OK && r != ARCHIVE_EOF)
- return (ARCHIVE_FATAL);
+ for (;;) {
+ r = compression_code(&(a->archive), &(xar->stream),
+ run);
+ if (r != ARCHIVE_OK && r != ARCHIVE_EOF)
+ return (ARCHIVE_FATAL);
+ if (xar->stream.avail_out == 0 ||
+ run == ARCHIVE_Z_FINISH) {
+ size = sizeof(xar->wbuff) -
+ xar->stream.avail_out;
+ checksum_update(&(xar->a_sumwrk), xar->wbuff,
+ size);
+ xar->cur_file->data.length += size;
+ if (write_to_temp(a, xar->wbuff,
+ size) != ARCHIVE_OK)
+ return (ARCHIVE_FATAL);
+ if (r == ARCHIVE_OK) {
+ /* Output buffer was full */
+ xar->stream.next_out = xar->wbuff;
+ xar->stream.avail_out =
+ sizeof(xar->wbuff);
+ } else {
+ /* ARCHIVE_EOF - We are done */
+ break;
+ }
+ } else {
+ /* Compressor wants more input */
+ break;
+ }
+ }
rsize = s - xar->stream.avail_in;
checksum_update(&(xar->e_sumwrk), buff, rsize);
- size = sizeof(xar->wbuff) - xar->stream.avail_out;
- checksum_update(&(xar->a_sumwrk), xar->wbuff, size);
}
#if !defined(_WIN32) || defined(__CYGWIN__)
if (xar->bytes_remaining ==
@@ -739,12 +769,9 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s)
if (xar->cur_file->data.compression == NONE) {
if (write_to_temp(a, buff, size) != ARCHIVE_OK)
return (ARCHIVE_FATAL);
- } else {
- if (write_to_temp(a, xar->wbuff, size) != ARCHIVE_OK)
- return (ARCHIVE_FATAL);
+ xar->cur_file->data.length += size;
}
xar->bytes_remaining -= rsize;
- xar->cur_file->data.length += size;
return (rsize);
}
@@ -878,11 +905,15 @@ xmlwrite_time(struct archive_write *a, xmlTextWriterPtr writer,
{
char timestr[100];
struct tm tm;
+#if defined(HAVE__GMTIME64_S)
+ __time64_t tmptime;
+#endif
#if defined(HAVE_GMTIME_R)
gmtime_r(&t, &tm);
#elif defined(HAVE__GMTIME64_S)
- _gmtime64_s(&tm, &t);
+ tmptime = t;
+ _gmtime64_s(&tm, &tmptime);
#else
memcpy(&tm, gmtime(&t), sizeof(tm));
#endif
@@ -2103,7 +2134,7 @@ file_gen_utility_names(struct archive_write *a, struct file *file)
while (len > 0) {
size_t ll = len;
- if (len > 0 && p[len-1] == '/') {
+ if (p[len-1] == '/') {
p[len-1] = '\0';
len--;
}
@@ -2532,13 +2563,11 @@ file_init_hardlinks(struct xar *xar)
static void
file_free_hardlinks(struct xar *xar)
{
- struct archive_rb_node *n, *next;
+ struct archive_rb_node *n, *tmp;
- for (n = ARCHIVE_RB_TREE_MIN(&(xar->hardlink_rbtree)); n;) {
- next = __archive_rb_tree_iterate(&(xar->hardlink_rbtree),
- n, ARCHIVE_RB_DIR_RIGHT);
+ ARCHIVE_RB_TREE_FOREACH_SAFE(n, &(xar->hardlink_rbtree), tmp) {
+ __archive_rb_tree_remove_node(&(xar->hardlink_rbtree), n);
free(n);
- n = next;
}
}