Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libpkg: add a packing_append_iovec()
Kyle Evans committed 2 years ago
commit 2eb688d607097353c4bfaeee1119706296d432cd
parent a7bb1d1
2 files changed +30 -6
modified libpkg/packing.c
@@ -25,6 +25,7 @@
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

+
#include <sys/uio.h>

#include <archive.h>
#include <archive_entry.h>
@@ -133,12 +134,15 @@ packing_init(struct packing **pack, const char *path, pkg_formats format, int cl
}

int
-
packing_append_buffer(struct packing *pack, const char *buffer,
-
    const char *path, int size)
+
packing_append_iovec(struct packing *pack, const char *path, struct iovec *iov,
+
    int niov)
{
	struct archive_entry *entry;
-
	int ret = EPKG_OK;
+
	int ret = EPKG_OK, size = 0;

+
	for (int idx = 0; idx < niov; idx++) {
+
		size += iov[idx].iov_len;
+
	}
	entry = archive_entry_new();
	archive_entry_clear(entry);
	archive_entry_set_filetype(entry, AE_IFREG);
@@ -153,9 +157,15 @@ packing_append_buffer(struct packing *pack, const char *buffer,
		goto cleanup;
	}

-
	if (archive_write_data(pack->awrite, buffer, size) == -1) {
-
		pkg_emit_errno("archive_write_data", path);
-
		ret = EPKG_FATAL;
+
	for (int idx = 0; idx < niov; idx++) {
+
		const char *buffer;
+

+
		buffer = iov[idx].iov_base;
+
		size = iov[idx].iov_len;
+
		if (archive_write_data(pack->awrite, buffer, size) == -1) {
+
			pkg_emit_errno("archive_write_data", path);
+
			ret = EPKG_FATAL;
+
		}
	}

cleanup:
@@ -165,6 +175,17 @@ cleanup:
}

int
+
packing_append_buffer(struct packing *pack, const char *buffer,
+
    const char *path, int size)
+
{
+
	struct iovec iov;
+

+
	iov.iov_base = __DECONST(char *, buffer);
+
	iov.iov_len = size;
+
	return (packing_append_iovec(pack, path, &iov, 1));
+
}
+

+
int
packing_append_file_attr(struct packing *pack, const char *filepath,
    const char *newpath, const char *uname, const char *gname, mode_t perm,
    u_long fflags)
modified libpkg/private/pkg.h
@@ -703,12 +703,15 @@ void pkg_option_free(struct pkg_option *);
void pkg_conflict_free(struct pkg_conflict *);
void pkg_config_file_free(struct pkg_config_file *);

+
struct iovec;
struct packing;

int packing_init(struct packing **pack, const char *path, pkg_formats format, int clevel, time_t timestamp, bool overwrite, bool archive_symlink);
int packing_append_file_attr(struct packing *pack, const char *filepath,
     const char *newpath, const char *uname, const char *gname, mode_t perm,
     u_long fflags);
+
int packing_append_iovec(struct packing *pack, const char *buffer,
+
			  struct iovec *iov, int niov);
int packing_append_buffer(struct packing *pack, const char *buffer,
			  const char *path, int size);
void packing_get_filename(struct packing *pack, const char *filename);