Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use stack based read with a 32k buffer instead of mmap
Baptiste Daroussin committed 9 years ago
commit 2fe54b63824103a0da62946e78dbdf0ff241d78f
parent 9175c77
2 files changed +91 -34
modified libpkg/packing.c
@@ -32,7 +32,6 @@
#include <fcntl.h>
#include <fts.h>
#include <string.h>
-
#include <sys/mman.h>
#include <pwd.h>
#include <grp.h>

@@ -134,7 +133,6 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
    u_long fflags)
{
	int fd;
-
	char *map;
	int retcode = EPKG_OK;
	int ret;
	time_t source_time;
@@ -142,6 +140,8 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
	struct archive_entry *entry, *sparse_entry;
	bool unset_timestamp;
	const char *source_date_epoch;
+
	char buf[32768];
+
	int len;

	entry = archive_entry_new();
	archive_entry_copy_sourcepath(entry, filepath);
@@ -220,43 +220,22 @@ packing_append_file_attr(struct packing *pack, const char *filepath,
			retcode = EPKG_FATAL;
			goto cleanup;
		}
-
		if (st.st_size > SSIZE_MAX) {
-
			char buf[BUFSIZ];
-
			int len;
-

-
			while ((len = read(fd, buf, sizeof(buf))) > 0)
-
				if (archive_write_data(pack->awrite, buf, len) == -1) {
-
					pkg_emit_errno("archive_write_data", "archive write error");
-
					retcode = EPKG_FATAL;
-
					break;
-
				}
-

-
			if (len == -1) {
-
				pkg_emit_errno("read", "file read error");
-
				retcode = EPKG_FATAL;
-
			}
-
			close(fd);
-
		}
-
		else {
-
			if ((map = mmap(NULL, st.st_size, PROT_READ,
-
					MAP_SHARED, fd, 0)) != MAP_FAILED) {
-
				close(fd);
-
				if (archive_write_data(pack->awrite, map, st.st_size) == -1) {
-
					pkg_emit_errno("archive_write_data", "archive write error");
-
					retcode = EPKG_FATAL;
-
				}
-
				munmap(map, st.st_size);
-
			}
-
			else {
-
				close(fd);
-
				pkg_emit_errno("open", filepath);
+

+
		while ((len = read(fd, buf, sizeof(buf))) > 0)
+
			if (archive_write_data(pack->awrite, buf, len) == -1) {
+
				pkg_emit_errno("archive_write_data", "archive write error");
				retcode = EPKG_FATAL;
-
				goto cleanup;
+
				break;
			}
+

+
		if (len == -1) {
+
			pkg_emit_errno("read", "file read error");
+
			retcode = EPKG_FATAL;
		}
+
		close(fd);
	}

-
	cleanup:
+
cleanup:
	archive_entry_free(entry);
	return (retcode);
}
added tests/frontend/formula.sh
@@ -0,0 +1,78 @@
+
#! /usr/bin/env atf-sh
+

+
. $(atf_get_srcdir)/test_environment.sh
+

+
tests_init \
+
	formula
+

+
formula_body() {
+
	cat << EOF >> repo.conf
+
local1: {
+
	url: file://${TMPDIR},
+
	enabled: true
+
}
+
EOF
+

+
	cat << EOF > a.ucl
+
name: a
+
origin: a
+
version: "1.0"
+
maintainer: test
+
categories: [test]
+
comment: a test
+
www: http://test
+
prefix: /usr/local
+
desc: <<EOD
+
Yet another test
+
EOD
+
EOF
+

+
	cat << EOF > b.ucl
+
name: b
+
origin: b
+
version: "1.0"
+
maintainer: test
+
categories: [test]
+
comment: a test
+
www: http://test
+
prefix: /usr/local
+
desc: <<EOD
+
Yet another test
+
EOD
+
dep_formula: 'a >= 1',
+
EOF
+
	for p in a b; do
+
		atf_check \
+
		    -o ignore \
+
		    -e empty \
+
		    -s exit:0 \
+
		    pkg create -M ./${p}.ucl
+
	done
+

+
	atf_check \
+
	    -o ignore \
+
	    -e empty \
+
	    -s exit:0 \
+
	    pkg repo .
+

+
	OUTPUT="Updating local1 repository catalogue...
+
${JAILED}meta.txz                                 :  done
+
${JAILED}packagesite.txz                          :  done
+
Processing entries:  done
+
local1 repository update completed. 2 packages processed.
+
All repositories are up to date.
+
Checking integrity... done (0 conflicting)
+
The following 2 package(s) will be affected (of 0 checked):
+

+
New packages to be INSTALLED:
+
	b: 1.0
+
	a: 1.0
+

+
Number of packages to be installed: 2
+
"
+
	atf_check \
+
	    -o inline:"${OUTPUT}" \
+
	    -e match:".*load error: access repo file.*" \
+
	    -s exit:1 \
+
	    pkg -o REPOS_DIR="${TMPDIR}" install -n b
+
}